Skip to content

Commit 997e669

Browse files
test: Replace iOS test app with VodQA app (#2364)
1 parent a9812cb commit 997e669

File tree

11 files changed

+167
-219
lines changed

11 files changed

+167
-219
lines changed

src/e2eIosTest/java/io/appium/java_client/ios/AppIOSTest.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
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+
117
package io.appium.java_client.ios;
218

319
import io.appium.java_client.ios.options.XCUITestOptions;
4-
import io.appium.java_client.utils.TestUtils;
520
import org.junit.jupiter.api.BeforeAll;
21+
import org.openqa.selenium.By;
622
import org.openqa.selenium.SessionNotCreatedException;
723

24+
import java.net.MalformedURLException;
25+
import java.net.URL;
826
import java.time.Duration;
927

10-
public class AppIOSTest extends BaseIOSTest {
11-
protected static final String BUNDLE_ID = "io.appium.TestApp";
28+
import static io.appium.java_client.AppiumBy.accessibilityId;
29+
import static io.appium.java_client.AppiumBy.iOSClassChain;
30+
import static io.appium.java_client.AppiumBy.iOSNsPredicateString;
31+
import static io.appium.java_client.utils.TestUtils.IOS_SIM_VODQA_RELEASE_URL;
1232

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

1543
@BeforeAll
16-
public static void beforeClass() {
44+
public static void beforeClass() throws MalformedURLException {
1745
startAppiumServer();
1846

1947
XCUITestOptions options = new XCUITestOptions()
2048
.setPlatformVersion(PLATFORM_VERSION)
2149
.setDeviceName(DEVICE_NAME)
2250
.setCommandTimeouts(Duration.ofSeconds(240))
23-
.setApp(TEST_APP_ZIP)
51+
.setApp(new URL(IOS_SIM_VODQA_RELEASE_URL))
2452
.enableBiDi()
2553
.setWdaLaunchTimeout(WDA_LAUNCH_TIMEOUT);
2654
if (PREBUILT_WDA_PATH != null) {

src/e2eIosTest/java/io/appium/java_client/ios/BaseIOSTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@
2222
import org.junit.jupiter.api.AfterAll;
2323

2424
import java.time.Duration;
25+
import java.util.Optional;
2526

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

2930
protected static AppiumDriverLocalService service;
3031
protected static IOSDriver driver;
3132
protected static final int PORT = 4723;
32-
public static final String DEVICE_NAME = System.getenv("IOS_DEVICE_NAME") != null
33-
? System.getenv("IOS_DEVICE_NAME")
34-
: "iPhone 12";
35-
public static final String PLATFORM_VERSION = System.getenv("IOS_PLATFORM_VERSION") != null
36-
? System.getenv("IOS_PLATFORM_VERSION")
37-
: "14.5";
33+
public static final String DEVICE_NAME = Optional.ofNullable(System.getenv("IOS_DEVICE_NAME"))
34+
.orElse("iPhone 17");
35+
public static final String PLATFORM_VERSION = Optional.ofNullable(System.getenv("IOS_PLATFORM_VERSION"))
36+
.orElse("26.0");
3837
public static final Duration WDA_LAUNCH_TIMEOUT = Duration.ofMinutes(4);
3938
public static final Duration SERVER_START_TIMEOUT = Duration.ofMinutes(3);
4039
protected static String PREBUILT_WDA_PATH = System.getenv("PREBUILT_WDA_PATH");

src/e2eIosTest/java/io/appium/java_client/ios/ClipboardTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public class ClipboardTest extends AppIOSTest {
2525
@Test public void verifySetAndGetClipboardText() {
2626
final String text = "Happy testing";
2727
driver.setClipboardText(text);
28-
assertEquals(driver.getClipboardText(), text);
28+
assertEquals(text, driver.getClipboardText());
2929
}
3030
}

src/e2eIosTest/java/io/appium/java_client/ios/IOSAlertTest.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package io.appium.java_client.ios;
1818

19-
import io.appium.java_client.AppiumBy;
2019
import org.apache.commons.lang3.StringUtils;
2120
import org.junit.jupiter.api.AfterEach;
2221
import org.junit.jupiter.api.MethodOrderer;
@@ -35,34 +34,10 @@
3534

3635
@TestMethodOrder(MethodOrderer.MethodName.class)
3736
public class IOSAlertTest extends AppIOSTest {
38-
3937
private static final Duration ALERT_TIMEOUT = Duration.ofSeconds(5);
4038
private static final int CLICK_RETRIES = 2;
41-
private static final String IOS_AUTOMATION_TEXT = "show alert";
42-
4339
private final WebDriverWait waiter = new WebDriverWait(driver, ALERT_TIMEOUT);
4440

45-
private void ensureAlertPresence() {
46-
int retry = 0;
47-
// CI might not be performant enough, so we need to retry
48-
while (true) {
49-
try {
50-
driver.findElement(AppiumBy.accessibilityId(IOS_AUTOMATION_TEXT)).click();
51-
} catch (WebDriverException e) {
52-
// ignore
53-
}
54-
try {
55-
waiter.until(alertIsPresent());
56-
return;
57-
} catch (TimeoutException e) {
58-
retry++;
59-
if (retry >= CLICK_RETRIES) {
60-
throw e;
61-
}
62-
}
63-
}
64-
}
65-
6641
@AfterEach
6742
public void afterEach() {
6843
try {
@@ -97,4 +72,26 @@ public void getAlertTextTest() {
9772
ensureAlertPresence();
9873
assertFalse(StringUtils.isBlank(driver.switchTo().alert().getText()));
9974
}
75+
76+
private void ensureAlertPresence() {
77+
int retry = 0;
78+
// CI might not be performant enough, so we need to retry
79+
while (true) {
80+
try {
81+
driver.findElement(PASSWORD_EDIT_PREDICATE).sendKeys("foo");
82+
driver.findElement(LOGIN_LINK_ID).click();
83+
} catch (WebDriverException e) {
84+
// ignore
85+
}
86+
try {
87+
waiter.until(alertIsPresent());
88+
return;
89+
} catch (TimeoutException e) {
90+
retry++;
91+
if (retry >= CLICK_RETRIES) {
92+
throw e;
93+
}
94+
}
95+
}
96+
}
10097
}

src/e2eIosTest/java/io/appium/java_client/ios/IOSAppStringsTest.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/e2eIosTest/java/io/appium/java_client/ios/IOSDriverTest.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
import org.junit.jupiter.api.BeforeEach;
2222
import org.junit.jupiter.api.Disabled;
2323
import org.junit.jupiter.api.Test;
24-
import org.openqa.selenium.By;
2524
import org.openqa.selenium.ScreenOrientation;
26-
import org.openqa.selenium.WebElement;
2725
import org.openqa.selenium.remote.RemoteWebElement;
2826
import org.openqa.selenium.remote.Response;
2927
import org.openqa.selenium.remote.http.HttpMethod;
@@ -65,13 +63,12 @@ public void addCustomCommandWithSessionIdTest() {
6563

6664
@Test
6765
public void addCustomCommandWithElementIdTest() {
68-
WebElement intA = driver.findElement(By.id("IntegerA"));
69-
intA.clear();
66+
var usernameEdit = driver.findElement(USERNAME_EDIT_PREDICATE);
7067
driver.addCommand(HttpMethod.POST,
7168
String.format("/session/%s/appium/element/%s/value", driver.getSessionId(),
72-
((RemoteWebElement) intA).getId()), "setNewValue");
69+
((RemoteWebElement) usernameEdit).getId()), "setNewValue");
7370
final Response setNewValue = driver.execute("setNewValue",
74-
Map.of("id", ((RemoteWebElement) intA).getId(), "text", "8"));
71+
Map.of("id", ((RemoteWebElement) usernameEdit).getId(), "text", "foo"));
7572
assertNotNull(setNewValue.getSessionId());
7673
}
7774

@@ -114,25 +111,22 @@ public void getDeviceTimeTest() {
114111
}
115112

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

121118
@Test public void keyboardTest() {
122-
WebElement element = driver.findElement(By.id("IntegerA"));
123-
element.click();
119+
driver.findElement(USERNAME_EDIT_PREDICATE).click();
124120
assertTrue(driver.isKeyboardShown());
125121
}
126122

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

135-
@Disabled("The app crashes when restored from the background")
136130
@Test
137131
public void applicationsManagementTest() {
138132
driver.runAppInBackground(Duration.ofSeconds(-1));
@@ -144,24 +138,4 @@ public void applicationsManagementTest() {
144138
() -> driver.queryAppState(BUNDLE_ID) == ApplicationState.RUNNING_IN_FOREGROUND,
145139
Duration.ofSeconds(10), Duration.ofSeconds(1));
146140
}
147-
148-
@Disabled("The app crashes when restored from the background")
149-
@Test
150-
public void putAIntoBackgroundWithoutRestoreTest() {
151-
waitUntilTrue(() -> !driver.findElements(By.id("IntegerA")).isEmpty(),
152-
Duration.ofSeconds(10), Duration.ofSeconds(1));
153-
driver.runAppInBackground(Duration.ofSeconds(-1));
154-
waitUntilTrue(() -> driver.findElements(By.id("IntegerA")).isEmpty(),
155-
Duration.ofSeconds(10), Duration.ofSeconds(1));
156-
driver.activateApp(BUNDLE_ID);
157-
}
158-
159-
@Disabled
160-
@Test public void touchIdTest() {
161-
driver.toggleTouchIDEnrollment(true);
162-
driver.performTouchID(true);
163-
driver.performTouchID(false);
164-
//noinspection SimplifiableAssertion,EqualsWithItself
165-
assertEquals(true, true);
166-
}
167141
}
Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
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+
117
package io.appium.java_client.ios;
218

3-
import io.appium.java_client.AppiumBy;
4-
import org.junit.jupiter.api.Disabled;
5-
import org.junit.jupiter.api.MethodOrderer;
619
import org.junit.jupiter.api.Test;
7-
import org.junit.jupiter.api.TestMethodOrder;
8-
import org.openqa.selenium.WebElement;
9-
import org.openqa.selenium.support.ui.WebDriverWait;
10-
11-
import java.time.Duration;
20+
import org.openqa.selenium.By;
1221

13-
import static org.hamcrest.MatcherAssert.assertThat;
14-
import static org.hamcrest.core.Is.is;
15-
import static org.hamcrest.core.IsNot.not;
16-
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
23+
import static org.openqa.selenium.By.className;
1724

18-
@TestMethodOrder(MethodOrderer.MethodName.class)
1925
public class IOSElementTest extends AppIOSTest {
26+
private static final By SLIDER_CLASS = className("XCUIElementTypeSlider");
2027

21-
@Test
22-
public void findByAccessibilityIdTest() {
23-
assertThat(driver.findElements(AppiumBy.accessibilityId("Compute Sum")).size(), not(is(0)));
24-
}
25-
26-
// FIXME: Stabilize the test on CI
27-
@Disabled
2828
@Test
2929
public void setValueTest() {
30-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
30+
driver.findElement(LOGIN_LINK_ID).click();
31+
driver.findElement(SLIDER_MENU_ITEM_PREDICATE).click();
3132

32-
WebElement slider = wait.until(
33-
driver1 -> driver1.findElement(AppiumBy.className("XCUIElementTypeSlider")));
34-
slider.sendKeys("0%");
35-
assertEquals("0%", slider.getAttribute("value"));
33+
var slider = driver.findElement(SLIDER_CLASS);
34+
var previousValue = slider.getAttribute("value");
35+
slider.sendKeys("0.5");
36+
assertNotEquals(slider.getAttribute("value"), previousValue);
3637
}
3738
}

src/e2eIosTest/java/io/appium/java_client/ios/IOSSearchingTest.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,25 @@
1616

1717
package io.appium.java_client.ios;
1818

19-
import io.appium.java_client.AppiumBy;
2019
import org.junit.jupiter.api.Test;
2120

2221
import static org.junit.jupiter.api.Assertions.assertNotEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2323

2424
public class IOSSearchingTest extends AppIOSTest {
25-
26-
@Test public void findByAccessibilityIdTest() {
27-
assertNotEquals(driver
28-
.findElement(AppiumBy.accessibilityId("ComputeSumButton"))
29-
.getText(), null);
30-
assertNotEquals(driver
31-
.findElements(AppiumBy.accessibilityId("ComputeSumButton"))
32-
.size(), 0);
25+
@Test
26+
public void findByAccessibilityIdTest() {
27+
assertNotNull(driver.findElement(LOGIN_LINK_ID).getText());
28+
assertNotEquals(0, driver.findElements(LOGIN_LINK_ID).size());
3329
}
3430

35-
@Test public void findByByIosPredicatesTest() {
36-
assertNotEquals(driver
37-
.findElement(AppiumBy.iOSNsPredicateString("name like 'Answer'"))
38-
.getText(), null);
39-
assertNotEquals(driver
40-
.findElements(AppiumBy.iOSNsPredicateString("name like 'Answer'"))
41-
.size(), 0);
31+
@Test
32+
public void findByByIosPredicatesTest() {
33+
assertNotNull(driver.findElement(USERNAME_EDIT_PREDICATE).getText());
34+
assertNotEquals(0, driver.findElements(USERNAME_EDIT_PREDICATE).size());
4235
}
4336

4437
@Test public void findByByIosClassChainTest() {
45-
assertNotEquals(driver
46-
.findElement(AppiumBy.iOSClassChain("**/XCUIElementTypeButton"))
47-
.getText(), null);
48-
assertNotEquals(driver
49-
.findElements(AppiumBy.iOSClassChain("**/XCUIElementTypeButton"))
50-
.size(), 0);
38+
assertNotEquals(0, driver.findElements(VODQA_LOGO_CLASS_CHAIN).size());
5139
}
5240
}

0 commit comments

Comments
 (0)