Browse Source

fixed android e2e samsung bugs

Daniel Zlotin 7 years ago
parent
commit
8a02cb10dc

+ 33
- 3
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java View File

@@ -1,11 +1,16 @@
1 1
 package com.reactnativenavigation.e2e.androide2e;
2 2
 
3
+import android.content.Intent;
4
+import android.net.Uri;
5
+import android.provider.Settings;
3 6
 import android.support.test.uiautomator.By;
4 7
 
5 8
 import org.junit.FixMethodOrder;
6 9
 import org.junit.Test;
7 10
 import org.junit.runners.MethodSorters;
8 11
 
12
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
13
+
9 14
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
10 15
 public class ApplicationLifecycleTest extends BaseTest {
11 16
 
@@ -59,12 +64,37 @@ public class ApplicationLifecycleTest extends BaseTest {
59 64
 		elementByText("PUSH").click();
60 65
 		assertExists(By.text("Pushed Screen"));
61 66
 
62
-		device().pressHome();
63
-		device().waitForIdle();
64
-		device().executeShellCommand("am kill " + PACKAGE_NAME);
67
+		killAppSaveInstanceState_ByTogglingPermissions();
65 68
 
66 69
 		device().pressRecentApps();
67 70
 		elementByText("Playground").click();
68 71
 		assertMainShown();
69 72
 	}
73
+
74
+	private void killAppSaveInstanceState_ByTogglingPermissions() throws Exception {
75
+		device().pressHome();
76
+
77
+		device().waitForIdle();
78
+		launchAppInfoSettings();
79
+		device().waitForIdle();
80
+
81
+		elementByText("Permissions").click();
82
+		elementByText("Storage").click();
83
+		elementByText("Storage").click();
84
+		device().pressBack();
85
+		device().pressBack();
86
+		device().pressHome();
87
+		device().waitForIdle();
88
+	}
89
+
90
+	private void launchAppInfoSettings() {
91
+		Intent intent = new Intent();
92
+		intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
93
+		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
94
+		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
95
+		intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
96
+		Uri uri = Uri.fromParts("package", PACKAGE_NAME, null);
97
+		intent.setData(uri);
98
+		getInstrumentation().getTargetContext().startActivity(intent);
99
+	}
70 100
 }

+ 9
- 1
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/BaseTest.java View File

@@ -48,7 +48,7 @@ public abstract class BaseTest {
48 48
 	}
49 49
 
50 50
 	public void acceptOverlayPermissionIfNeeded() throws Exception {
51
-		if (elementByText("Draw over other apps").waitForExists(300)) {
51
+		if (isRequestingOverlayPermission()) {
52 52
 			if (!elementByText("Playground").exists()) {
53 53
 				scrollToText("Playground");
54 54
 			}
@@ -59,10 +59,18 @@ public abstract class BaseTest {
59 59
 		}
60 60
 	}
61 61
 
62
+	private boolean isRequestingOverlayPermission() {
63
+		return device().wait(Until.hasObject(By.pkg("com.android.settings").depth(0)), 300);
64
+	}
65
+
62 66
 	public UiObject elementByText(String text) {
63 67
 		return device().findObject(new UiSelector().text(text));
64 68
 	}
65 69
 
70
+	public UiObject elementByTextContains(String text) {
71
+		return device().findObject(new UiSelector().textContains(text));
72
+	}
73
+
66 74
 	public void scrollToText(String txt) throws Exception {
67 75
 		new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
68 76
 	}

+ 0
- 2
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ScreenStackTest.java View File

@@ -2,10 +2,8 @@ package com.reactnativenavigation.e2e.androide2e;
2 2
 
3 3
 import android.support.test.uiautomator.By;
4 4
 
5
-import org.junit.Ignore;
6 5
 import org.junit.Test;
7 6
 
8
-@Ignore
9 7
 public class ScreenStackTest extends BaseTest {
10 8
 
11 9
 	@Test