Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions src/e2eIosTest/java/io/appium/java_client/ios/AppIOSTest.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,54 @@
/*
* 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 io.appium.java_client.ios.options.XCUITestOptions;
import io.appium.java_client.utils.TestUtils;
import org.junit.jupiter.api.BeforeAll;
import org.openqa.selenium.By;
import org.openqa.selenium.SessionNotCreatedException;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;

public class AppIOSTest extends BaseIOSTest {
protected static final String BUNDLE_ID = "io.appium.TestApp";
import static io.appium.java_client.AppiumBy.accessibilityId;
import static io.appium.java_client.AppiumBy.iOSClassChain;
import static io.appium.java_client.AppiumBy.iOSNsPredicateString;
import static io.appium.java_client.utils.TestUtils.IOS_SIM_VODQA_RELEASE_URL;

private static final String TEST_APP_ZIP = TestUtils.resourcePathToAbsolutePath("TestApp.app.zip").toString();
public class AppIOSTest extends BaseIOSTest {
protected static final String BUNDLE_ID = "org.reactjs.native.example.VodQAReactNative";
protected static final By LOGIN_LINK_ID = accessibilityId("login");
protected static final By USERNAME_EDIT_PREDICATE = iOSNsPredicateString("name == \"username\"");
protected static final By PASSWORD_EDIT_PREDICATE = iOSNsPredicateString("name == \"password\"");
protected static final By SLIDER_MENU_ITEM_PREDICATE = iOSNsPredicateString("name == \"slider1\"");
protected static final By VODQA_LOGO_CLASS_CHAIN = iOSClassChain(
"**/XCUIElementTypeImage[`name CONTAINS \"vodqa\"`]"
);

@BeforeAll
public static void beforeClass() {
public static void beforeClass() throws MalformedURLException {
startAppiumServer();

XCUITestOptions options = new XCUITestOptions()
.setPlatformVersion(PLATFORM_VERSION)
.setDeviceName(DEVICE_NAME)
.setCommandTimeouts(Duration.ofSeconds(240))
.setApp(TEST_APP_ZIP)
.setApp(new URL(IOS_SIM_VODQA_RELEASE_URL))
.enableBiDi()
.setWdaLaunchTimeout(WDA_LAUNCH_TIMEOUT);
if (PREBUILT_WDA_PATH != null) {
Expand Down
11 changes: 5 additions & 6 deletions src/e2eIosTest/java/io/appium/java_client/ios/BaseIOSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@
import org.junit.jupiter.api.AfterAll;

import java.time.Duration;
import java.util.Optional;

@SuppressWarnings("checkstyle:HideUtilityClassConstructor")
public class BaseIOSTest {

protected static AppiumDriverLocalService service;
protected static IOSDriver driver;
protected static final int PORT = 4723;
public static final String DEVICE_NAME = System.getenv("IOS_DEVICE_NAME") != null
? System.getenv("IOS_DEVICE_NAME")
: "iPhone 12";
public static final String PLATFORM_VERSION = System.getenv("IOS_PLATFORM_VERSION") != null
? System.getenv("IOS_PLATFORM_VERSION")
: "14.5";
public static final String DEVICE_NAME = Optional.ofNullable(System.getenv("IOS_DEVICE_NAME"))
.orElse("iPhone 17");
public static final String PLATFORM_VERSION = Optional.ofNullable(System.getenv("IOS_PLATFORM_VERSION"))
.orElse("26.0");
public static final Duration WDA_LAUNCH_TIMEOUT = Duration.ofMinutes(4);
public static final Duration SERVER_START_TIMEOUT = Duration.ofMinutes(3);
protected static String PREBUILT_WDA_PATH = System.getenv("PREBUILT_WDA_PATH");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public class ClipboardTest extends AppIOSTest {
@Test public void verifySetAndGetClipboardText() {
final String text = "Happy testing";
driver.setClipboardText(text);
assertEquals(driver.getClipboardText(), text);
assertEquals(text, driver.getClipboardText());
}
}
47 changes: 22 additions & 25 deletions src/e2eIosTest/java/io/appium/java_client/ios/IOSAlertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.appium.java_client.ios;

import io.appium.java_client.AppiumBy;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.MethodOrderer;
Expand All @@ -35,34 +34,10 @@

@TestMethodOrder(MethodOrderer.MethodName.class)
public class IOSAlertTest extends AppIOSTest {

private static final Duration ALERT_TIMEOUT = Duration.ofSeconds(5);
private static final int CLICK_RETRIES = 2;
private static final String IOS_AUTOMATION_TEXT = "show alert";

private final WebDriverWait waiter = new WebDriverWait(driver, ALERT_TIMEOUT);

private void ensureAlertPresence() {
int retry = 0;
// CI might not be performant enough, so we need to retry
while (true) {
try {
driver.findElement(AppiumBy.accessibilityId(IOS_AUTOMATION_TEXT)).click();
} catch (WebDriverException e) {
// ignore
}
try {
waiter.until(alertIsPresent());
return;
} catch (TimeoutException e) {
retry++;
if (retry >= CLICK_RETRIES) {
throw e;
}
}
}
}

@AfterEach
public void afterEach() {
try {
Expand Down Expand Up @@ -97,4 +72,26 @@ public void getAlertTextTest() {
ensureAlertPresence();
assertFalse(StringUtils.isBlank(driver.switchTo().alert().getText()));
}

private void ensureAlertPresence() {
int retry = 0;
// CI might not be performant enough, so we need to retry
while (true) {
try {
driver.findElement(PASSWORD_EDIT_PREDICATE).sendKeys("foo");
driver.findElement(LOGIN_LINK_ID).click();
} catch (WebDriverException e) {
// ignore
}
try {
waiter.until(alertIsPresent());
return;
} catch (TimeoutException e) {
retry++;
if (retry >= CLICK_RETRIES) {
throw e;
}
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.ScreenOrientation;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebElement;
import org.openqa.selenium.remote.Response;
import org.openqa.selenium.remote.http.HttpMethod;
Expand Down Expand Up @@ -65,13 +63,12 @@ public void addCustomCommandWithSessionIdTest() {

@Test
public void addCustomCommandWithElementIdTest() {
WebElement intA = driver.findElement(By.id("IntegerA"));
intA.clear();
var usernameEdit = driver.findElement(USERNAME_EDIT_PREDICATE);
driver.addCommand(HttpMethod.POST,
String.format("/session/%s/appium/element/%s/value", driver.getSessionId(),
((RemoteWebElement) intA).getId()), "setNewValue");
((RemoteWebElement) usernameEdit).getId()), "setNewValue");
final Response setNewValue = driver.execute("setNewValue",
Map.of("id", ((RemoteWebElement) intA).getId(), "text", "8"));
Map.of("id", ((RemoteWebElement) usernameEdit).getId(), "text", "foo"));
assertNotNull(setNewValue.getSessionId());
}

Expand Down Expand Up @@ -114,25 +111,22 @@ public void getDeviceTimeTest() {
}

@Test public void pullFileTest() {
byte[] data = driver.pullFile(String.format("@%s/TestApp", BUNDLE_ID));
byte[] data = driver.pullFile(String.format("@%s/VodQAReactNative", BUNDLE_ID));
assertThat(data.length, greaterThan(0));
}

@Test public void keyboardTest() {
WebElement element = driver.findElement(By.id("IntegerA"));
element.click();
driver.findElement(USERNAME_EDIT_PREDICATE).click();
assertTrue(driver.isKeyboardShown());
}

@Disabled("The app crashes when restored from the background")
@Test
public void putAppIntoBackgroundAndRestoreTest() {
final long msStarted = System.currentTimeMillis();
driver.runAppInBackground(Duration.ofSeconds(4));
assertThat(System.currentTimeMillis() - msStarted, greaterThan(3000L));
}

@Disabled("The app crashes when restored from the background")
@Test
public void applicationsManagementTest() {
driver.runAppInBackground(Duration.ofSeconds(-1));
Expand All @@ -144,24 +138,4 @@ public void applicationsManagementTest() {
() -> driver.queryAppState(BUNDLE_ID) == ApplicationState.RUNNING_IN_FOREGROUND,
Duration.ofSeconds(10), Duration.ofSeconds(1));
}

@Disabled("The app crashes when restored from the background")
@Test
public void putAIntoBackgroundWithoutRestoreTest() {
waitUntilTrue(() -> !driver.findElements(By.id("IntegerA")).isEmpty(),
Duration.ofSeconds(10), Duration.ofSeconds(1));
driver.runAppInBackground(Duration.ofSeconds(-1));
waitUntilTrue(() -> driver.findElements(By.id("IntegerA")).isEmpty(),
Duration.ofSeconds(10), Duration.ofSeconds(1));
driver.activateApp(BUNDLE_ID);
}

@Disabled
@Test public void touchIdTest() {
driver.toggleTouchIDEnrollment(true);
driver.performTouchID(true);
driver.performTouchID(false);
//noinspection SimplifiableAssertion,EqualsWithItself
assertEquals(true, true);
}
}
51 changes: 26 additions & 25 deletions src/e2eIosTest/java/io/appium/java_client/ios/IOSElementTest.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
/*
* 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 io.appium.java_client.AppiumBy;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;
import org.openqa.selenium.By;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.openqa.selenium.By.className;

@TestMethodOrder(MethodOrderer.MethodName.class)
public class IOSElementTest extends AppIOSTest {
private static final By SLIDER_CLASS = className("XCUIElementTypeSlider");

@Test
public void findByAccessibilityIdTest() {
assertThat(driver.findElements(AppiumBy.accessibilityId("Compute Sum")).size(), not(is(0)));
}

// FIXME: Stabilize the test on CI
@Disabled
@Test
public void setValueTest() {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
driver.findElement(LOGIN_LINK_ID).click();
driver.findElement(SLIDER_MENU_ITEM_PREDICATE).click();

WebElement slider = wait.until(
driver1 -> driver1.findElement(AppiumBy.className("XCUIElementTypeSlider")));
slider.sendKeys("0%");
assertEquals("0%", slider.getAttribute("value"));
var slider = driver.findElement(SLIDER_CLASS);
var previousValue = slider.getAttribute("value");
slider.sendKeys("0.5");
assertNotEquals(slider.getAttribute("value"), previousValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,25 @@

package io.appium.java_client.ios;

import io.appium.java_client.AppiumBy;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class IOSSearchingTest extends AppIOSTest {

@Test public void findByAccessibilityIdTest() {
assertNotEquals(driver
.findElement(AppiumBy.accessibilityId("ComputeSumButton"))
.getText(), null);
assertNotEquals(driver
.findElements(AppiumBy.accessibilityId("ComputeSumButton"))
.size(), 0);
@Test
public void findByAccessibilityIdTest() {
assertNotNull(driver.findElement(LOGIN_LINK_ID).getText());
assertNotEquals(0, driver.findElements(LOGIN_LINK_ID).size());
}

@Test public void findByByIosPredicatesTest() {
assertNotEquals(driver
.findElement(AppiumBy.iOSNsPredicateString("name like 'Answer'"))
.getText(), null);
assertNotEquals(driver
.findElements(AppiumBy.iOSNsPredicateString("name like 'Answer'"))
.size(), 0);
@Test
public void findByByIosPredicatesTest() {
assertNotNull(driver.findElement(USERNAME_EDIT_PREDICATE).getText());
assertNotEquals(0, driver.findElements(USERNAME_EDIT_PREDICATE).size());
}

@Test public void findByByIosClassChainTest() {
assertNotEquals(driver
.findElement(AppiumBy.iOSClassChain("**/XCUIElementTypeButton"))
.getText(), null);
assertNotEquals(driver
.findElements(AppiumBy.iOSClassChain("**/XCUIElementTypeButton"))
.size(), 0);
assertNotEquals(0, driver.findElements(VODQA_LOGO_CLASS_CHAIN).size());
}
}
Loading