Quellcode durchsuchen

android: e2e works

Daniel Zlotin vor 8 Jahren
Ursprung
Commit
d5a630450c

+ 20
- 15
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java Datei anzeigen

16
 import org.junit.runner.RunWith;
16
 import org.junit.runner.RunWith;
17
 import org.junit.runners.MethodSorters;
17
 import org.junit.runners.MethodSorters;
18
 
18
 
19
-import java.io.IOException;
20
-
21
 import static android.support.test.InstrumentationRegistry.getInstrumentation;
19
 import static android.support.test.InstrumentationRegistry.getInstrumentation;
22
 import static org.assertj.core.api.Java6Assertions.assertThat;
20
 import static org.assertj.core.api.Java6Assertions.assertThat;
23
 
21
 
29
     private static final long TIMEOUT = 3000;
27
     private static final long TIMEOUT = 3000;
30
 
28
 
31
     @Before
29
     @Before
32
-    public void beforeEach() {
33
-        //
30
+    public void beforeEach() throws Exception {
31
+        uiDevice().wakeUp();
32
+        uiDevice().setOrientationNatural();
34
     }
33
     }
35
 
34
 
36
     @After
35
     @After
37
-    public void afterEach() throws IOException {
36
+    public void afterEach() throws Exception {
38
         uiDevice().executeShellCommand("am force-stop " + PACKAGE_NAME);
37
         uiDevice().executeShellCommand("am force-stop " + PACKAGE_NAME);
39
     }
38
     }
40
 
39
 
53
         uiDevice().pressHome();
52
         uiDevice().pressHome();
54
         uiDevice().pressRecentApps();
53
         uiDevice().pressRecentApps();
55
         elementByText("Playground").click();
54
         elementByText("Playground").click();
55
+
56
         assertMainShown();
56
         assertMainShown();
57
     }
57
     }
58
 
58
 
71
     public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
71
     public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
72
         launchTheApp();
72
         launchTheApp();
73
         assertMainShown();
73
         assertMainShown();
74
-
75
         elementByText("PUSH").click();
74
         elementByText("PUSH").click();
76
         assertExists(By.text("Pushed screen"));
75
         assertExists(By.text("Pushed screen"));
77
 
76
 
81
         assertExists(By.text("Pushed screen"));
80
         assertExists(By.text("Pushed screen"));
82
     }
81
     }
83
 
82
 
83
+    @Test
84
+    public void _5_relaunchAfterActivityKilledBySystem() throws Exception {
85
+        launchTheApp();
86
+        assertMainShown();
87
+
88
+        uiDevice().pressHome();
89
+        uiDevice().executeShellCommand("am kill " + PACKAGE_NAME);
90
+
91
+        uiDevice().pressRecentApps();
92
+        elementByText("Playground").click();
93
+        assertMainShown();
94
+    }
95
+
84
     private void assertMainShown() {
96
     private void assertMainShown() {
85
         assertExists(By.text("React Native Navigation!"));
97
         assertExists(By.text("React Native Navigation!"));
86
     }
98
     }
98
     }
110
     }
99
 
111
 
100
     private void launchTheApp() throws Exception {
112
     private void launchTheApp() throws Exception {
101
-        uiDevice().wakeUp();
102
-        uiDevice().pressHome();
103
-        elementByDesc("Apps").clickAndWaitForNewWindow();
104
-        scrollToText("Playground");
105
-        elementByText("Playground").clickAndWaitForNewWindow();
113
+        uiDevice().executeShellCommand("am start -n " + PACKAGE_NAME + "/.MainActivity");
114
+        uiDevice().waitForIdle();
106
         acceptOverlayPermissionIfNeeded();
115
         acceptOverlayPermissionIfNeeded();
107
     }
116
     }
108
 
117
 
114
         return uiDevice().findObject(new UiSelector().text(text));
123
         return uiDevice().findObject(new UiSelector().text(text));
115
     }
124
     }
116
 
125
 
117
-    private UiObject elementByDesc(String text) {
118
-        return uiDevice().findObject(new UiSelector().description(text));
119
-    }
120
-
121
     private void scrollToText(String txt) throws Exception {
126
     private void scrollToText(String txt) throws Exception {
122
         new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
127
         new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
123
     }
128
     }