Skip to content

Commit

Permalink
feat: Implement HasBiDi interface support in AppiumDriver (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Dec 16, 2024
1 parent 7fc702e commit d01161d
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 98 deletions.
1 change: 1 addition & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ concurrency:
cancel-in-progress: true

env:
CI: true
ANDROID_SDK_VERSION: "28"
ANDROID_EMU_NAME: test
ANDROID_EMU_TARGET: default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

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

Expand All @@ -31,7 +32,7 @@ public class AndroidContextTest extends BaseAndroidTest {
}

@Test public void testGetContext() {
assertEquals("NATIVE_APP", driver.getContext());
assertEquals(NATIVE_CONTEXT, driver.getContext());
}

@Test public void testGetContextHandles() {
Expand All @@ -42,8 +43,8 @@ public class AndroidContextTest extends BaseAndroidTest {
driver.getContextHandles();
driver.context("WEBVIEW_io.appium.android.apis");
assertEquals(driver.getContext(), "WEBVIEW_io.appium.android.apis");
driver.context("NATIVE_APP");
assertEquals(driver.getContext(), "NATIVE_APP");
driver.context(NATIVE_CONTEXT);
assertEquals(driver.getContext(), NATIVE_CONTEXT);
}

@Test public void testContextError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static io.appium.java_client.HasBrowserCheck.NATIVE_CONTEXT;
import static java.time.Duration.ofMillis;
import static java.time.Duration.ofSeconds;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -75,7 +76,7 @@ public static void startWebViewActivity() {
@BeforeEach
public void setUp() {

driver.context("NATIVE_APP");
driver.context(NATIVE_CONTEXT);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void beforeClass() {
.setDeviceName(DEVICE_NAME)
.setCommandTimeouts(Duration.ofSeconds(240))
.setApp(TEST_APP_ZIP)
.enableBiDi()
.setWdaLaunchTimeout(WDA_LAUNCH_TIMEOUT);
try {
driver = new IOSDriver(service.getUrl(), options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public static void beforeClass() {
.setDeviceName(DEVICE_NAME)
.setWdaLaunchTimeout(WDA_LAUNCH_TIMEOUT)
.setCommandTimeouts(Duration.ofSeconds(240))
.setShowIosLog(true)
.setApp(VODQA_ZIP);
Supplier<IOSDriver> createDriver = () -> new IOSDriver(service.getUrl(), options);
try {
Expand Down
42 changes: 42 additions & 0 deletions src/e2eIosTest/java/io/appium/java_client/ios/IOSBiDiTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.ios;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
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 IOSBiDiTest extends AppIOSTest {

@Test
@Disabled("Need to resolve compatibility issues")
public void listenForIosLogs() {
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 @@ -19,6 +19,7 @@
import io.appium.java_client.NoSuchContextException;
import org.junit.jupiter.api.Test;

import static io.appium.java_client.HasBrowserCheck.NATIVE_CONTEXT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -27,7 +28,7 @@
public class IOSContextTest extends BaseIOSWebViewTest {

@Test public void testGetContext() {
assertEquals("NATIVE_APP", driver.getContext());
assertEquals(NATIVE_CONTEXT, driver.getContext());
}

@Test public void testGetContextHandles() {
Expand All @@ -38,7 +39,7 @@ public class IOSContextTest extends BaseIOSWebViewTest {
driver.getContextHandles();
findAndSwitchToWebView();
assertThat(driver.getContext(), containsString("WEBVIEW"));
driver.context("NATIVE_APP");
driver.context(NATIVE_CONTEXT);
}

@Test public void testContextError() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.appium.java_client.ios;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.TestUtils;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
Expand All @@ -15,6 +17,9 @@ public class IOSWebViewTest extends BaseIOSWebViewTest {

@Test
public void webViewPageTestCase() throws InterruptedException {
// this test is not stable in the CI env
Assumptions.assumeFalse(TestUtils.isCiEnv());

new WebDriverWait(driver, LOOKUP_TIMEOUT)
.until(ExpectedConditions.presenceOfElementLocated(By.id("login")))
.click();
Expand Down
Loading

0 comments on commit d01161d

Please sign in to comment.