Browse Source

espresso e2e tests work

Daniel Zlotin 7 years ago
parent
commit
f178d529b4

+ 2
- 4
android/app/src/main/java/com/reactnativenavigation/react/ReactDevPermission.java View File

16
     public static boolean shouldAskPermission() {
16
     public static boolean shouldAskPermission() {
17
         return NavigationApplication.instance.isDebug() &&
17
         return NavigationApplication.instance.isDebug() &&
18
                 Build.VERSION.SDK_INT >= 23 &&
18
                 Build.VERSION.SDK_INT >= 23 &&
19
-               !Settings.canDrawOverlays(NavigationApplication.instance);
19
+                !Settings.canDrawOverlays(NavigationApplication.instance);
20
     }
20
     }
21
 
21
 
22
     @TargetApi(23)
22
     @TargetApi(23)
28
             Log.w(ReactConstants.TAG, "======================================\n\n");
28
             Log.w(ReactConstants.TAG, "======================================\n\n");
29
             Log.w(ReactConstants.TAG, msg);
29
             Log.w(ReactConstants.TAG, msg);
30
             Log.w(ReactConstants.TAG, "\n\n======================================");
30
             Log.w(ReactConstants.TAG, "\n\n======================================");
31
-            for (int i = 0; i < 5; i++) {
32
-                Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
33
-            }
31
+            Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
34
         }
32
         }
35
     }
33
     }
36
 }
34
 }

+ 4
- 0
playground/android/app/build.gradle View File

27
     androidTestCompile 'com.android.support:support-annotations:25.1.1'
27
     androidTestCompile 'com.android.support:support-annotations:25.1.1'
28
     androidTestCompile 'com.android.support.test:runner:0.5'
28
     androidTestCompile 'com.android.support.test:runner:0.5'
29
     androidTestCompile 'com.android.support.test:rules:0.5'
29
     androidTestCompile 'com.android.support.test:rules:0.5'
30
+    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
30
     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
31
     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
31
         exclude module: 'jsr305'
32
         exclude module: 'jsr305'
32
     }
33
     }
34
+    androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.2') {
35
+        exclude module: 'jsr305'
36
+    }
33
     androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
37
     androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
34
         exclude module: 'support-annotations'
38
         exclude module: 'support-annotations'
35
         exclude module: 'support-v4'
39
         exclude module: 'support-v4'

+ 9
- 0
playground/android/app/src/androidTest/AndroidManifest.xml View File

1
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+    xmlns:tools="http://schemas.android.com/tools"
3
+    package="com.reactnativenavigation.playground">
4
+
5
+    <uses-sdk
6
+        android:minSdkVersion="18"
7
+        tools:overrideLibrary="android.support.test.uiautomator.v18" />
8
+
9
+</manifest>

+ 32
- 5
playground/android/app/src/androidTest/java/com/reactnativenavigation/playground/ApplicationTest.java View File

1
 package com.reactnativenavigation.playground;
1
 package com.reactnativenavigation.playground;
2
 
2
 
3
-import android.support.test.espresso.action.ViewActions;
3
+import android.app.Activity;
4
+import android.app.Instrumentation;
5
+import android.provider.Settings;
6
+import android.support.test.espresso.intent.Intents;
4
 import android.support.test.rule.ActivityTestRule;
7
 import android.support.test.rule.ActivityTestRule;
5
 import android.support.test.runner.AndroidJUnit4;
8
 import android.support.test.runner.AndroidJUnit4;
9
+import android.support.test.uiautomator.UiDevice;
10
+import android.support.test.uiautomator.UiObjectNotFoundException;
11
+import android.support.test.uiautomator.UiSelector;
6
 
12
 
7
 import org.junit.Rule;
13
 import org.junit.Rule;
8
 import org.junit.Test;
14
 import org.junit.Test;
9
 import org.junit.runner.RunWith;
15
 import org.junit.runner.RunWith;
10
 
16
 
17
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
11
 import static android.support.test.espresso.Espresso.onView;
18
 import static android.support.test.espresso.Espresso.onView;
19
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
20
+import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction;
21
+import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
12
 import static android.support.test.espresso.matcher.ViewMatchers.withText;
22
 import static android.support.test.espresso.matcher.ViewMatchers.withText;
13
 
23
 
14
 @RunWith(AndroidJUnit4.class)
24
 @RunWith(AndroidJUnit4.class)
15
 public class ApplicationTest {
25
 public class ApplicationTest {
16
 
26
 
17
     @Rule
27
     @Rule
18
-    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class);
28
+    public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class, false, false);
19
 
29
 
20
     @Test
30
     @Test
21
-    public void startsTheApp() {
22
-        
23
-        onView(withText("Playground")).perform(ViewActions.click());
31
+    public void startAppShowsTheSplash() throws InterruptedException {
32
+        Intents.init();
33
+        Intents.intending(hasAction(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)).respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, null));
34
+
35
+        rule.launchActivity(null);
36
+
37
+        onView(withText("Splash :)")).check(matches(isDisplayed()));
38
+        Intents.release();
39
+    }
40
+
41
+    @Test
42
+    public void startAppLoadsBridgeShowsWelcomeScreen() throws UiObjectNotFoundException {
43
+        rule.launchActivity(null);
44
+
45
+        UiDevice.getInstance(getInstrumentation()).findObject(new UiSelector().text("Playground")).click();
46
+        UiDevice.getInstance(getInstrumentation()).findObject(new UiSelector().text("Permit drawing over other apps")).click();
47
+        UiDevice.getInstance(getInstrumentation()).pressBack();
48
+        UiDevice.getInstance(getInstrumentation()).pressBack();
49
+
50
+        onView(withText("React Native Navigation!")).check(matches(isDisplayed()));
24
     }
51
     }
25
 }
52
 }

+ 1
- 0
playground/scripts/e2e.android.js View File

7
 function e2e() { //eslint-disable-line
7
 function e2e() { //eslint-disable-line
8
   try {
8
   try {
9
     shellUtils.exec.execSync(`echo 'travis_fold:start:android-espresso'`);
9
     shellUtils.exec.execSync(`echo 'travis_fold:start:android-espresso'`);
10
+    shellUtils.exec.execSync(`cd android && ./gradlew --stop`);
10
     shellUtils.exec.execSync(`cd android && ./gradlew connectedDebugAndroidTest`);
11
     shellUtils.exec.execSync(`cd android && ./gradlew connectedDebugAndroidTest`);
11
   } finally {
12
   } finally {
12
     shellUtils.exec.execSync(`echo 'travis_fold:end:android-espresso'`);
13
     shellUtils.exec.execSync(`echo 'travis_fold:end:android-espresso'`);