|
@@ -1,24 +1,28 @@
|
1
|
1
|
package com.reactnativenavigation.e2e.androide2e;
|
2
|
2
|
|
3
|
|
-import android.content.Intent;
|
4
|
3
|
import android.support.test.runner.AndroidJUnit4;
|
5
|
|
-import android.support.test.uiautomator.By;
|
6
|
4
|
import android.support.test.uiautomator.UiDevice;
|
7
|
|
-import android.support.test.uiautomator.Until;
|
|
5
|
+import android.support.test.uiautomator.UiScrollable;
|
|
6
|
+import android.support.test.uiautomator.UiSelector;
|
8
|
7
|
|
9
|
8
|
import org.junit.After;
|
10
|
9
|
import org.junit.Before;
|
|
10
|
+import org.junit.FixMethodOrder;
|
11
|
11
|
import org.junit.Test;
|
12
|
12
|
import org.junit.runner.RunWith;
|
|
13
|
+import org.junit.runners.MethodSorters;
|
|
14
|
+
|
|
15
|
+import java.io.IOException;
|
13
|
16
|
|
14
|
17
|
import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
15
|
18
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
16
|
19
|
|
17
|
20
|
@RunWith(AndroidJUnit4.class)
|
|
21
|
+@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
|
18
|
22
|
public class ApplicationLifecycleTest {
|
19
|
23
|
|
20
|
24
|
private static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
|
21
|
|
- private static final int TIMEOUT = 10000;
|
|
25
|
+ private static final int TIMEOUT = 2000;
|
22
|
26
|
|
23
|
27
|
@Before
|
24
|
28
|
public void beforeEach() {
|
|
@@ -26,26 +30,48 @@ public class ApplicationLifecycleTest {
|
26
|
30
|
}
|
27
|
31
|
|
28
|
32
|
@After
|
29
|
|
- public void afterEach() {
|
30
|
|
- //
|
|
33
|
+ public void afterEach() throws IOException {
|
|
34
|
+ uiDevice().executeShellCommand("am force-stop " + PACKAGE_NAME);
|
31
|
35
|
}
|
32
|
36
|
|
33
|
37
|
@Test
|
34
|
|
- public void showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
|
|
38
|
+ public void _1_showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
|
35
|
39
|
launchTheApp();
|
36
|
40
|
// assertThat(uiDevice().wait(Until.hasObject(By.desc("NavigationSplashView")), TIMEOUT)).isTrue();
|
37
|
41
|
acceptOverlayPermissionIfNeeded();
|
38
|
42
|
assertMainShown();
|
39
|
43
|
}
|
40
|
44
|
|
|
45
|
+ @Test
|
|
46
|
+ public void _2_relaunchFromBackground() throws Exception {
|
|
47
|
+ launchTheApp();
|
|
48
|
+ assertMainShown();
|
|
49
|
+
|
|
50
|
+ uiDevice().pressHome();
|
|
51
|
+ uiDevice().pressRecentApps();
|
|
52
|
+ uiDevice().findObject(new UiSelector().text("Playground")).click();
|
|
53
|
+ assertMainShown();
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ @Test
|
|
57
|
+ public void _3_relaunchAfterClose() throws Exception {
|
|
58
|
+ launchTheApp();
|
|
59
|
+ assertMainShown();
|
|
60
|
+
|
|
61
|
+ uiDevice().pressBack();
|
|
62
|
+
|
|
63
|
+ launchTheApp();
|
|
64
|
+ assertMainShown();
|
|
65
|
+ }
|
|
66
|
+
|
41
|
67
|
private void assertMainShown() {
|
42
|
|
- assertThat(uiDevice().findObject(By.text("React Native Navigation!"))).isNotNull();
|
|
68
|
+ assertThat(uiDevice().findObject(new UiSelector().text("React Native Navigation!")).exists()).isTrue();
|
43
|
69
|
}
|
44
|
70
|
|
45
|
71
|
private void acceptOverlayPermissionIfNeeded() throws Exception {
|
46
|
|
- if (uiDevice().findObject(By.text("Draw over other apps")) != null) {
|
47
|
|
- uiDevice().findObject(By.text("Playground")).click();
|
48
|
|
- uiDevice().findObject(By.text("Permit drawing over other apps")).click();
|
|
72
|
+ if (uiDevice().findObject(new UiSelector().text("Draw over other apps")).exists()) {
|
|
73
|
+ uiDevice().findObject(new UiSelector().text("Playground")).click();
|
|
74
|
+ uiDevice().findObject(new UiSelector().text("Permit drawing over other apps")).click();
|
49
|
75
|
uiDevice().pressBack();
|
50
|
76
|
uiDevice().pressBack();
|
51
|
77
|
}
|
|
@@ -54,11 +80,9 @@ public class ApplicationLifecycleTest {
|
54
|
80
|
private void launchTheApp() throws Exception {
|
55
|
81
|
uiDevice().wakeUp();
|
56
|
82
|
uiDevice().pressHome();
|
57
|
|
- uiDevice().waitForIdle();
|
58
|
|
- Intent intent = getInstrumentation().getContext().getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME);
|
59
|
|
- assertThat(intent).isNotNull();
|
60
|
|
- getInstrumentation().getContext().startActivity(intent);
|
61
|
|
- uiDevice().wait(Until.hasObject(By.pkg(PACKAGE_NAME).depth(0)), TIMEOUT);
|
|
83
|
+ uiDevice().findObject(new UiSelector().description("Apps")).clickAndWaitForNewWindow();
|
|
84
|
+ new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView("Playground");
|
|
85
|
+ uiDevice().findObject(new UiSelector().text("Playground")).clickAndWaitForNewWindow();
|
62
|
86
|
}
|
63
|
87
|
|
64
|
88
|
private UiDevice uiDevice() {
|