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
 package com.reactnativenavigation.e2e.androide2e;
1
 package com.reactnativenavigation.e2e.androide2e;
2
 
2
 
3
+import android.content.Intent;
4
+import android.net.Uri;
5
+import android.provider.Settings;
3
 import android.support.test.uiautomator.By;
6
 import android.support.test.uiautomator.By;
4
 
7
 
5
 import org.junit.FixMethodOrder;
8
 import org.junit.FixMethodOrder;
6
 import org.junit.Test;
9
 import org.junit.Test;
7
 import org.junit.runners.MethodSorters;
10
 import org.junit.runners.MethodSorters;
8
 
11
 
12
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
13
+
9
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
14
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
10
 public class ApplicationLifecycleTest extends BaseTest {
15
 public class ApplicationLifecycleTest extends BaseTest {
11
 
16
 
59
 		elementByText("PUSH").click();
64
 		elementByText("PUSH").click();
60
 		assertExists(By.text("Pushed Screen"));
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
 		device().pressRecentApps();
69
 		device().pressRecentApps();
67
 		elementByText("Playground").click();
70
 		elementByText("Playground").click();
68
 		assertMainShown();
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
 	}
48
 	}
49
 
49
 
50
 	public void acceptOverlayPermissionIfNeeded() throws Exception {
50
 	public void acceptOverlayPermissionIfNeeded() throws Exception {
51
-		if (elementByText("Draw over other apps").waitForExists(300)) {
51
+		if (isRequestingOverlayPermission()) {
52
 			if (!elementByText("Playground").exists()) {
52
 			if (!elementByText("Playground").exists()) {
53
 				scrollToText("Playground");
53
 				scrollToText("Playground");
54
 			}
54
 			}
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
 	public UiObject elementByText(String text) {
66
 	public UiObject elementByText(String text) {
63
 		return device().findObject(new UiSelector().text(text));
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
 	public void scrollToText(String txt) throws Exception {
74
 	public void scrollToText(String txt) throws Exception {
67
 		new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
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
 
2
 
3
 import android.support.test.uiautomator.By;
3
 import android.support.test.uiautomator.By;
4
 
4
 
5
-import org.junit.Ignore;
6
 import org.junit.Test;
5
 import org.junit.Test;
7
 
6
 
8
-@Ignore
9
 public class ScreenStackTest extends BaseTest {
7
 public class ScreenStackTest extends BaseTest {
10
 
8
 
11
 	@Test
9
 	@Test