Skip to content

Commit a13724b

Browse files
test: Add Android BiDi events test (#2256)
1 parent f75963d commit a13724b

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.android;
18+
19+
import org.junit.jupiter.api.Test;
20+
import org.openqa.selenium.bidi.Event;
21+
import org.openqa.selenium.bidi.log.LogEntry;
22+
import org.openqa.selenium.bidi.module.LogInspector;
23+
24+
import java.util.concurrent.CopyOnWriteArrayList;
25+
26+
import static io.appium.java_client.HasBrowserCheck.NATIVE_CONTEXT;
27+
import static org.junit.jupiter.api.Assertions.assertFalse;
28+
29+
public class AndroidBiDiTest extends BaseAndroidTest {
30+
31+
@Test
32+
public void listenForAndroidLogsGeneric() {
33+
var logs = new CopyOnWriteArrayList<>();
34+
var listenerId = driver.getBiDi().addListener(
35+
NATIVE_CONTEXT,
36+
new Event<Object>("log.entryAdded", m -> m),
37+
logs::add
38+
);
39+
try {
40+
driver.getPageSource();
41+
} finally {
42+
driver.getBiDi().removeListener(listenerId);
43+
}
44+
assertFalse(logs.isEmpty());
45+
}
46+
47+
@Test
48+
public void listenForAndroidLogsSpecific() {
49+
var logs = new CopyOnWriteArrayList<LogEntry>();
50+
try (var logInspector = new LogInspector(NATIVE_CONTEXT, driver)) {
51+
logInspector.onLog(logs::add);
52+
driver.getPageSource();
53+
}
54+
assertFalse(logs.isEmpty());
55+
}
56+
57+
}

src/e2eAndroidTest/java/io/appium/java_client/android/BaseAndroidTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class BaseAndroidTest {
4444

4545
UiAutomator2Options options = new UiAutomator2Options()
4646
.setDeviceName("Android Emulator")
47+
.enableBiDi()
4748
.setApp(TestResources.API_DEMOS_APK.toString())
4849
.eventTimings();
4950
driver = new AndroidDriver(service.getUrl(), options);

0 commit comments

Comments
 (0)