From a867c096d6225f498df68c09d540088be0041646 Mon Sep 17 00:00:00 2001 From: tobrun Date: Wed, 20 Mar 2019 19:13:04 +0100 Subject: [android] - improve reliability of UiAutomator tests --- .../mapbox/mapboxsdk/maps/GLSurfaceViewReopenTest.kt | 17 ++++++++--------- .../com/mapbox/mapboxsdk/maps/TextureViewReopenTest.kt | 11 ++--------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/GLSurfaceViewReopenTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/GLSurfaceViewReopenTest.kt index 98b251027f..708b633db4 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/GLSurfaceViewReopenTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/GLSurfaceViewReopenTest.kt @@ -2,15 +2,18 @@ package com.mapbox.mapboxsdk.maps import android.content.Intent import android.support.test.InstrumentationRegistry +import android.support.test.InstrumentationRegistry.getTargetContext import android.support.test.filters.SdkSuppress import android.support.test.runner.AndroidJUnit4 -import android.support.test.uiautomator.* +import android.support.test.uiautomator.By +import android.support.test.uiautomator.UiDevice +import android.support.test.uiautomator.UiSelector +import android.support.test.uiautomator.Until import org.hamcrest.CoreMatchers.notNullValue import org.hamcrest.MatcherAssert.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import java.lang.Thread.sleep private const val BASIC_SAMPLE_PACKAGE = "com.mapbox.mapboxsdk.testapp" private const val LAUNCH_TIMEOUT = 5000L @@ -57,17 +60,13 @@ class GLSurfaceViewReopenTest { @Test fun reopenSimpleMapActivity() { - // return to home screen - device.pressHome() - - // press recents apps button + // press recent apps button to pause the app device.pressRecentApps() - // click to reopen app - device.findObject(UiSelector().description("Mapbox Android SDK TestApp")).click() + // return to app + device.findObject(UiSelector().text(getTargetContext().getString(getTargetContext().applicationInfo.labelRes))).click() // wait for idle device.waitForIdle(LAUNCH_TIMEOUT) - sleep(LAUNCH_TIMEOUT) } } \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/TextureViewReopenTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/TextureViewReopenTest.kt index cd139ccc40..490f279b29 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/TextureViewReopenTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/TextureViewReopenTest.kt @@ -10,9 +10,6 @@ import org.hamcrest.MatcherAssert.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import java.lang.Thread.sleep -import android.support.test.uiautomator.UiSelector -import android.support.test.uiautomator.UiScrollable private const val BASIC_SAMPLE_PACKAGE = "com.mapbox.mapboxsdk.testapp" private const val LAUNCH_TIMEOUT = 5000L @@ -61,17 +58,13 @@ class TextureViewReopenTest { @Test fun reopenTextureViewDebugActivity() { - // return to home screen - device.pressHome() - // press recent apps button device.pressRecentApps() - // click to reopen app - device.findObject(UiSelector().description("Mapbox Android SDK TestApp")).click() + // return to app + device.findObject(UiSelector().text(InstrumentationRegistry.getTargetContext().getString(InstrumentationRegistry.getTargetContext().applicationInfo.labelRes))).click() // wait for idle device.waitForIdle(LAUNCH_TIMEOUT) - sleep(LAUNCH_TIMEOUT) } } \ No newline at end of file -- cgit v1.2.1