Browse Source

fixing android tests

Daniel Zlotin 7 years ago
parent
commit
a40bcd8e27

+ 16
- 11
AndroidE2E/app/build.gradle View File

1
 apply plugin: 'com.android.application'
1
 apply plugin: 'com.android.application'
2
 
2
 
3
 android {
3
 android {
4
-    compileSdkVersion 25
5
-    buildToolsVersion "25.0.3"
4
+    compileOptions {
5
+        sourceCompatibility JavaVersion.VERSION_1_8
6
+        targetCompatibility JavaVersion.VERSION_1_8
7
+    }
8
+
9
+    compileSdkVersion 27
10
+    buildToolsVersion "27.0.3"
6
     defaultConfig {
11
     defaultConfig {
7
         applicationId "com.reactnativenavigation.e2e.androide2e"
12
         applicationId "com.reactnativenavigation.e2e.androide2e"
8
-        minSdkVersion 18
9
-        targetSdkVersion 25
13
+        minSdkVersion 24
14
+        targetSdkVersion 27
10
         versionCode 1
15
         versionCode 1
11
         versionName "1.0"
16
         versionName "1.0"
12
 
17
 
15
 }
20
 }
16
 
21
 
17
 dependencies {
22
 dependencies {
18
-    compile fileTree(dir: 'libs', include: ['*.jar'])
19
-    compile 'com.android.support:appcompat-v7:25.3.1'
23
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
24
+    implementation 'com.android.support:appcompat-v7:27.0.2'
20
 
25
 
21
-    androidTestCompile 'org.assertj:assertj-core:2.5.0'
22
-    androidTestCompile 'com.android.support:support-annotations:25.3.1'
23
-    androidTestCompile 'com.android.support.test:runner:0.5'
24
-    androidTestCompile 'com.android.support.test:rules:0.5'
25
-    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
26
+    androidTestImplementation 'org.assertj:assertj-core:3.8.0'
27
+    androidTestImplementation 'com.android.support:support-annotations:27.0.2'
28
+    androidTestImplementation 'com.android.support.test:runner:1.0.1'
29
+    androidTestImplementation 'com.android.support.test:rules:1.0.1'
30
+    androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
26
 }
31
 }

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

1
 package com.reactnativenavigation.e2e.androide2e;
1
 package com.reactnativenavigation.e2e.androide2e;
2
 
2
 
3
-import android.content.pm.ApplicationInfo;
4
-import android.content.pm.PackageInfo;
5
-import android.graphics.Bitmap;
6
-import android.graphics.BitmapFactory;
7
-import android.support.test.runner.AndroidJUnit4;
8
-import android.support.test.uiautomator.By;
9
-import android.support.test.uiautomator.BySelector;
10
-import android.support.test.uiautomator.UiDevice;
11
-import android.support.test.uiautomator.UiObject;
12
-import android.support.test.uiautomator.UiScrollable;
13
-import android.support.test.uiautomator.UiSelector;
14
-import android.support.test.uiautomator.Until;
15
-
16
-import org.junit.After;
17
-import org.junit.Before;
18
-import org.junit.runner.RunWith;
19
-
20
-import java.io.File;
21
-
22
-import static android.support.test.InstrumentationRegistry.getInstrumentation;
23
-import static org.assertj.core.api.Java6Assertions.assertThat;
3
+import android.content.pm.*;
4
+import android.graphics.*;
5
+import android.support.test.runner.*;
6
+import android.support.test.uiautomator.*;
7
+
8
+import org.junit.*;
9
+import org.junit.runner.*;
10
+
11
+import java.io.*;
12
+
13
+import static android.support.test.InstrumentationRegistry.*;
14
+import static org.assertj.core.api.Java6Assertions.*;
24
 
15
 
25
 @RunWith(AndroidJUnit4.class)
16
 @RunWith(AndroidJUnit4.class)
26
 public abstract class BaseTest {
17
 public abstract class BaseTest {
38
 	@After
29
 	@After
39
 	public void afterEach() throws Exception {
30
 	public void afterEach() throws Exception {
40
 		device().executeShellCommand("am force-stop " + PACKAGE_NAME);
31
 		device().executeShellCommand("am force-stop " + PACKAGE_NAME);
32
+		device().executeShellCommand("am kill " + PACKAGE_NAME);
41
 	}
33
 	}
42
 
34
 
43
 	public UiDevice device() {
35
 	public UiDevice device() {
97
 		return bitmap;
89
 		return bitmap;
98
 	}
90
 	}
99
 
91
 
100
-	public void swipeOpenLeftSideMenu() {
101
-		device().swipe(5, 102, 500, 152, 15);
92
+	public void swipeOpenFromLeft() {
93
+		int w = device().getDisplayWidth();
94
+		int h = device().getDisplayHeight();
95
+		device().swipe(5, h / 2, w / 2, h / 2, 10);
96
+	}
97
+
98
+	public void swipeOpenFromRight() {
99
+		int w = device().getDisplayWidth();
100
+		int h = device().getDisplayHeight();
101
+		device().swipe(w - 5, h / 2, w / 2, h / 2, 10);
102
 	}
102
 	}
103
 
103
 
104
 	public boolean isDebug() throws Exception {
104
 	public boolean isDebug() throws Exception {

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

25
 	public void switchToTabsWithSideMenu() throws Exception {
25
 	public void switchToTabsWithSideMenu() throws Exception {
26
 		elementByText("SWITCH TO APP WITH SIDE MENUS").click();
26
 		elementByText("SWITCH TO APP WITH SIDE MENUS").click();
27
 		assertExists(By.textStartsWith("This is a side menu center screen tab 1"));
27
 		assertExists(By.textStartsWith("This is a side menu center screen tab 1"));
28
-		swipeOpenLeftSideMenu();
28
+		swipeOpenFromLeft();
29
 		assertExists(By.text("This is a left side menu screen"));
29
 		assertExists(By.text("This is a left side menu screen"));
30
 	}
30
 	}
31
 }
31
 }

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

10
     public void tabsCanBeSwiped() throws Exception {
10
     public void tabsCanBeSwiped() throws Exception {
11
         elementByText("PUSH TOP TABS SCREEN").click();
11
         elementByText("PUSH TOP TABS SCREEN").click();
12
         assertExists(By.text("This is top tab 1"));
12
         assertExists(By.text("This is top tab 1"));
13
-        device().swipe(400, 400, 10, 400, 2);
13
+        swipeOpenFromRight();
14
         assertExists(By.text("This is top tab 2"));
14
         assertExists(By.text("This is top tab 2"));
15
     }
15
     }
16
 }
16
 }

+ 3
- 1
AndroidE2E/build.gradle View File

3
 buildscript {
3
 buildscript {
4
     repositories {
4
     repositories {
5
         jcenter()
5
         jcenter()
6
+        google()
6
     }
7
     }
7
     dependencies {
8
     dependencies {
8
-        classpath 'com.android.tools.build:gradle:2.3.3'
9
+        classpath 'com.android.tools.build:gradle:3.0.1'
9
 
10
 
10
         // NOTE: Do not place your application dependencies here; they belong
11
         // NOTE: Do not place your application dependencies here; they belong
11
         // in the individual module build.gradle files
12
         // in the individual module build.gradle files
14
 
15
 
15
 allprojects {
16
 allprojects {
16
     repositories {
17
     repositories {
18
+        google()
17
         mavenLocal()
19
         mavenLocal()
18
         jcenter()
20
         jcenter()
19
         mavenCentral()
21
         mavenCentral()

+ 2
- 2
AndroidE2E/gradle/wrapper/gradle-wrapper.properties View File

1
-#Mon Dec 28 10:00:20 PST 2015
1
+#Mon Jan 01 12:06:42 IST 2018
2
 distributionBase=GRADLE_USER_HOME
2
 distributionBase=GRADLE_USER_HOME
3
 distributionPath=wrapper/dists
3
 distributionPath=wrapper/dists
4
 zipStoreBase=GRADLE_USER_HOME
4
 zipStoreBase=GRADLE_USER_HOME
5
 zipStorePath=wrapper/dists
5
 zipStorePath=wrapper/dists
6
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip
6
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip

+ 1
- 1
lib/android/app/build.gradle View File

68
     // tests
68
     // tests
69
     testImplementation 'junit:junit:4.12'
69
     testImplementation 'junit:junit:4.12'
70
     testImplementation 'org.robolectric:robolectric:3.5.1'
70
     testImplementation 'org.robolectric:robolectric:3.5.1'
71
-    testImplementation 'org.assertj:assertj-core:2.8.0'
71
+    testImplementation 'org.assertj:assertj-core:3.8.0'
72
     testImplementation 'com.squareup.assertj:assertj-android:1.1.1'
72
     testImplementation 'com.squareup.assertj:assertj-android:1.1.1'
73
     testImplementation 'org.mockito:mockito-core:2.12.0'
73
     testImplementation 'org.mockito:mockito-core:2.12.0'
74
 }
74
 }