Skip to content

Commit

Permalink
test: Add Android BiDi events test (#2256)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jan 13, 2025
1 parent f75963d commit a13724b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appium.java_client.android;

import org.junit.jupiter.api.Test;
import org.openqa.selenium.bidi.Event;
import org.openqa.selenium.bidi.log.LogEntry;
import org.openqa.selenium.bidi.module.LogInspector;

import java.util.concurrent.CopyOnWriteArrayList;

import static io.appium.java_client.HasBrowserCheck.NATIVE_CONTEXT;
import static org.junit.jupiter.api.Assertions.assertFalse;

public class AndroidBiDiTest extends BaseAndroidTest {

@Test
public void listenForAndroidLogsGeneric() {
var logs = new CopyOnWriteArrayList<>();
var listenerId = driver.getBiDi().addListener(
NATIVE_CONTEXT,
new Event<Object>("log.entryAdded", m -> m),
logs::add
);
try {
driver.getPageSource();
} finally {
driver.getBiDi().removeListener(listenerId);
}
assertFalse(logs.isEmpty());
}

@Test
public void listenForAndroidLogsSpecific() {
var logs = new CopyOnWriteArrayList<LogEntry>();
try (var logInspector = new LogInspector(NATIVE_CONTEXT, driver)) {
logInspector.onLog(logs::add);
driver.getPageSource();
}
assertFalse(logs.isEmpty());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class BaseAndroidTest {

UiAutomator2Options options = new UiAutomator2Options()
.setDeviceName("Android Emulator")
.enableBiDi()
.setApp(TestResources.API_DEMOS_APK.toString())
.eventTimings();
driver = new AndroidDriver(service.getUrl(), options);
Expand Down

0 comments on commit a13724b

Please sign in to comment.