Skip to content

Commit 0d29dde

Browse files
moar
1 parent 7440205 commit 0d29dde

File tree

8 files changed

+127
-181
lines changed

8 files changed

+127
-181
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
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;
@@ -10,13 +26,19 @@
1026
import java.time.Duration;
1127

1228
import static io.appium.java_client.AppiumBy.accessibilityId;
29+
import static io.appium.java_client.AppiumBy.iOSClassChain;
1330
import static io.appium.java_client.AppiumBy.iOSNsPredicateString;
1431
import static io.appium.java_client.utils.TestUtils.IOS_SIM_VODQA_RELEASE_URL;
1532

1633
public class AppIOSTest extends BaseIOSTest {
1734
protected static final String BUNDLE_ID = "org.reactjs.native.example.VodQAReactNative";
1835
protected static final By LOGIN_LINK_ID = accessibilityId("login");
36+
protected static final By USERNAME_EDIT_PREDICATE = iOSNsPredicateString("name == \"username\"");
1937
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+
);
2042

2143
@BeforeAll
2244
public static void beforeClass() throws MalformedURLException {

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)