From a40bcd8e272af20331acb105415ccc07e384993c Mon Sep 17 00:00:00 2001 From: Daniel Zlotin Date: Mon, 1 Jan 2018 16:36:56 +0200 Subject: [PATCH 1/2] fixing android tests --- AndroidE2E/app/build.gradle | 27 ++++++----- .../e2e/androide2e/BaseTest.java | 46 +++++++++---------- .../e2e/androide2e/TopLevelApiTest.java | 2 +- .../e2e/androide2e/TopTabsTest.java | 2 +- AndroidE2E/build.gradle | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- lib/android/app/build.gradle | 2 +- 7 files changed, 47 insertions(+), 40 deletions(-) diff --git a/AndroidE2E/app/build.gradle b/AndroidE2E/app/build.gradle index 2d294351f11..2b95fe03567 100644 --- a/AndroidE2E/app/build.gradle +++ b/AndroidE2E/app/build.gradle @@ -1,12 +1,17 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.3" + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + compileSdkVersion 27 + buildToolsVersion "27.0.3" defaultConfig { applicationId "com.reactnativenavigation.e2e.androide2e" - minSdkVersion 18 - targetSdkVersion 25 + minSdkVersion 24 + targetSdkVersion 27 versionCode 1 versionName "1.0" @@ -15,12 +20,12 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:25.3.1' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:27.0.2' - androidTestCompile 'org.assertj:assertj-core:2.5.0' - androidTestCompile 'com.android.support:support-annotations:25.3.1' - androidTestCompile 'com.android.support.test:runner:0.5' - androidTestCompile 'com.android.support.test:rules:0.5' - androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2' + androidTestImplementation 'org.assertj:assertj-core:3.8.0' + androidTestImplementation 'com.android.support:support-annotations:27.0.2' + androidTestImplementation 'com.android.support.test:runner:1.0.1' + androidTestImplementation 'com.android.support.test:rules:1.0.1' + androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3' } diff --git a/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/BaseTest.java b/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/BaseTest.java index c77858f6fa6..8f788838fa9 100644 --- a/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/BaseTest.java +++ b/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/BaseTest.java @@ -1,26 +1,17 @@ package com.reactnativenavigation.e2e.androide2e; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.support.test.runner.AndroidJUnit4; -import android.support.test.uiautomator.By; -import android.support.test.uiautomator.BySelector; -import android.support.test.uiautomator.UiDevice; -import android.support.test.uiautomator.UiObject; -import android.support.test.uiautomator.UiScrollable; -import android.support.test.uiautomator.UiSelector; -import android.support.test.uiautomator.Until; - -import org.junit.After; -import org.junit.Before; -import org.junit.runner.RunWith; - -import java.io.File; - -import static android.support.test.InstrumentationRegistry.getInstrumentation; -import static org.assertj.core.api.Java6Assertions.assertThat; +import android.content.pm.*; +import android.graphics.*; +import android.support.test.runner.*; +import android.support.test.uiautomator.*; + +import org.junit.*; +import org.junit.runner.*; + +import java.io.*; + +import static android.support.test.InstrumentationRegistry.*; +import static org.assertj.core.api.Java6Assertions.*; @RunWith(AndroidJUnit4.class) public abstract class BaseTest { @@ -38,6 +29,7 @@ public void beforeEach() throws Exception { @After public void afterEach() throws Exception { device().executeShellCommand("am force-stop " + PACKAGE_NAME); + device().executeShellCommand("am kill " + PACKAGE_NAME); } public UiDevice device() { @@ -97,8 +89,16 @@ public Bitmap captureScreenshot() throws Exception { return bitmap; } - public void swipeOpenLeftSideMenu() { - device().swipe(5, 102, 500, 152, 15); + public void swipeOpenFromLeft() { + int w = device().getDisplayWidth(); + int h = device().getDisplayHeight(); + device().swipe(5, h / 2, w / 2, h / 2, 10); + } + + public void swipeOpenFromRight() { + int w = device().getDisplayWidth(); + int h = device().getDisplayHeight(); + device().swipe(w - 5, h / 2, w / 2, h / 2, 10); } public boolean isDebug() throws Exception { diff --git a/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/TopLevelApiTest.java b/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/TopLevelApiTest.java index 29d06d40982..ce2b06f379a 100644 --- a/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/TopLevelApiTest.java +++ b/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/TopLevelApiTest.java @@ -25,7 +25,7 @@ public void switchToTabBasedApp_SwitchTab() throws Exception { public void switchToTabsWithSideMenu() throws Exception { elementByText("SWITCH TO APP WITH SIDE MENUS").click(); assertExists(By.textStartsWith("This is a side menu center screen tab 1")); - swipeOpenLeftSideMenu(); + swipeOpenFromLeft(); assertExists(By.text("This is a left side menu screen")); } } diff --git a/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/TopTabsTest.java b/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/TopTabsTest.java index 009e1e10b6c..1755b25a87d 100644 --- a/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/TopTabsTest.java +++ b/AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/TopTabsTest.java @@ -10,7 +10,7 @@ public class TopTabsTest extends BaseTest { public void tabsCanBeSwiped() throws Exception { elementByText("PUSH TOP TABS SCREEN").click(); assertExists(By.text("This is top tab 1")); - device().swipe(400, 400, 10, 400, 2); + swipeOpenFromRight(); assertExists(By.text("This is top tab 2")); } } diff --git a/AndroidE2E/build.gradle b/AndroidE2E/build.gradle index 71d4a136cf6..d243f2f0a1a 100644 --- a/AndroidE2E/build.gradle +++ b/AndroidE2E/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -14,6 +15,7 @@ buildscript { allprojects { repositories { + google() mavenLocal() jcenter() mavenCentral() diff --git a/AndroidE2E/gradle/wrapper/gradle-wrapper.properties b/AndroidE2E/gradle/wrapper/gradle-wrapper.properties index 5de41d45619..0a11ba33a33 100644 --- a/AndroidE2E/gradle/wrapper/gradle-wrapper.properties +++ b/AndroidE2E/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Mon Jan 01 12:06:42 IST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip diff --git a/lib/android/app/build.gradle b/lib/android/app/build.gradle index 4e203fcb717..8252b66967b 100644 --- a/lib/android/app/build.gradle +++ b/lib/android/app/build.gradle @@ -68,7 +68,7 @@ dependencies { // tests testImplementation 'junit:junit:4.12' testImplementation 'org.robolectric:robolectric:3.5.1' - testImplementation 'org.assertj:assertj-core:2.8.0' + testImplementation 'org.assertj:assertj-core:3.8.0' testImplementation 'com.squareup.assertj:assertj-android:1.1.1' testImplementation 'org.mockito:mockito-core:2.12.0' } From 6190df2606dfd1ce80c48852a0c784fa5d332f2b Mon Sep 17 00:00:00 2001 From: Daniel Zlotin Date: Mon, 1 Jan 2018 16:46:19 +0200 Subject: [PATCH 2/2] update deps --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbf479f8627..999ab279540 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "eslint-config-xo": "0.18.x", "eslint-config-xo-react": "0.13.x", "eslint-plugin-react": "7.x.x", - "jest": "21.x.x", + "jest": "22.x.x", "jsdoc": "3.x.x", "jsdoc-to-markdown": "3.x.x", "mocha": "4.x.x",