Skip to content

Commit b869ea2

Browse files
author
Mykola Mokhnach
committed
Add integration tests
1 parent 146db48 commit b869ea2

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

src/test/java/io/appium/java_client/android/AndroidDriverTest.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616

1717
package io.appium.java_client.android;
1818

19+
import static org.hamcrest.Matchers.equalTo;
20+
import static org.hamcrest.Matchers.lessThan;
1921
import static org.junit.Assert.assertEquals;
2022
import static org.junit.Assert.assertFalse;
2123
import static org.junit.Assert.assertNotEquals;
2224
import static org.junit.Assert.assertNotNull;
25+
import static org.junit.Assert.assertThat;
2326
import static org.junit.Assert.assertTrue;
2427

28+
import io.appium.java_client.appmanagement.ApplicationState;
2529
import org.apache.commons.codec.binary.Base64;
2630
import org.apache.commons.io.FileUtils;
2731
import org.junit.Test;
@@ -118,6 +122,17 @@ public class AndroidDriverTest extends BaseAndroidTest {
118122
assert (timeAfter - time > 3000);
119123
}
120124

125+
@Test public void testApplicationsManagement() throws InterruptedException {
126+
String appId = driver.getCurrentPackage();
127+
assertThat(driver.queryAppState(appId), equalTo(ApplicationState.RUNNING_IN_FOREGROUND));
128+
Thread.sleep(500);
129+
driver.runAppInBackground(Duration.ofSeconds(-1));
130+
assertThat(driver.queryAppState(appId), lessThan(ApplicationState.RUNNING_IN_FOREGROUND));
131+
Thread.sleep(500);
132+
driver.activateApp(appId);
133+
assertThat(driver.queryAppState(appId), equalTo(ApplicationState.RUNNING_IN_FOREGROUND));
134+
}
135+
121136
@Test public void pullFileTest() {
122137
byte[] data =
123138
driver.pullFile("data/system/registered_services/android.content.SyncAdapter.xml");
@@ -149,7 +164,7 @@ public class AndroidDriverTest extends BaseAndroidTest {
149164
}
150165

151166
@Test public void getSupportedPerformanceDataTypesTest() {
152-
driver.startActivity(new Activity("io.appium.android.apis", ".ApiDemos"));
167+
driver.startActivity(new Activity(APP_ID, ".ApiDemos"));
153168

154169
List<String> dataTypes = new ArrayList<>();
155170
dataTypes.add("cpuinfo");
@@ -169,7 +184,7 @@ public class AndroidDriverTest extends BaseAndroidTest {
169184
}
170185

171186
@Test public void getPerformanceDataTest() throws Exception {
172-
driver.startActivity(new Activity("io.appium.android.apis", ".ApiDemos"));
187+
driver.startActivity(new Activity(APP_ID, ".ApiDemos"));
173188

174189
List<String> supportedPerformanceDataTypes = driver.getSupportedPerformanceDataTypes();
175190

@@ -185,7 +200,7 @@ public class AndroidDriverTest extends BaseAndroidTest {
185200
}
186201

187202
@Test public void getCurrentPackageTest() {
188-
assertEquals("io.appium.android.apis",driver.getCurrentPackage());
203+
assertEquals(APP_ID, driver.getCurrentPackage());
189204
}
190205

191206
}

src/test/java/io/appium/java_client/android/BaseAndroidTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.File;
2929

3030
public class BaseAndroidTest {
31+
public static final String APP_ID = "io.appium.android.apis";
3132
private static AppiumDriverLocalService service;
3233
protected static AndroidDriver<AndroidElement> driver;
3334

src/test/java/io/appium/java_client/ios/AppXCUITTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.io.File;
1212

1313
public class AppXCUITTest extends BaseIOSTest {
14+
public static final String BUNDLE_ID = "io.appium.TestApp";
1415

1516
/**
1617
* initialization.

src/test/java/io/appium/java_client/ios/XCUIAutomationTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818

1919
import static io.appium.java_client.touch.offset.ElementOption.element;
2020
import static org.hamcrest.Matchers.empty;
21+
import static org.hamcrest.Matchers.equalTo;
2122
import static org.hamcrest.Matchers.greaterThan;
2223
import static org.hamcrest.Matchers.is;
24+
import static org.hamcrest.Matchers.lessThan;
2325
import static org.hamcrest.Matchers.not;
2426
import static org.junit.Assert.assertEquals;
2527
import static org.junit.Assert.assertNotNull;
2628
import static org.junit.Assert.assertThat;
2729

30+
import io.appium.java_client.appmanagement.ApplicationState;
31+
import io.appium.java_client.remote.MobileCapabilityType;
2832
import org.junit.After;
2933
import org.junit.Test;
3034
import org.openqa.selenium.DeviceRotation;
@@ -62,6 +66,26 @@ public class XCUIAutomationTest extends AppXCUITTest {
6266
assertThat(System.currentTimeMillis() - msStarted, greaterThan(3000L));
6367
}
6468

69+
@Test public void testApplicationsManagement() throws InterruptedException {
70+
// This only works since Xcode9
71+
try {
72+
if (Double.parseDouble(
73+
(String) driver.getCapabilities()
74+
.getCapability(MobileCapabilityType.PLATFORM_VERSION)) < 11) {
75+
return;
76+
}
77+
} catch (NumberFormatException | NullPointerException e) {
78+
return;
79+
}
80+
assertThat(driver.queryAppState(BUNDLE_ID), equalTo(ApplicationState.RUNNING_IN_FOREGROUND));
81+
Thread.sleep(500);
82+
driver.runAppInBackground(Duration.ofSeconds(-1));
83+
assertThat(driver.queryAppState(BUNDLE_ID), lessThan(ApplicationState.RUNNING_IN_FOREGROUND));
84+
Thread.sleep(500);
85+
driver.activateApp(BUNDLE_ID);
86+
assertThat(driver.queryAppState(BUNDLE_ID), equalTo(ApplicationState.RUNNING_IN_FOREGROUND));
87+
}
88+
6589
@Test public void testPutIntoBackgroundWithoutRestore() {
6690
assertThat(driver.findElementsById("IntegerA"), is(not(empty())));
6791
driver.runAppInBackground(Duration.ofSeconds(-1));

0 commit comments

Comments
 (0)