[android] - improve reliability of UiAutomator tests

This commit is contained in:
tobrun
2019-03-20 19:13:04 +01:00
committed by Tobrun
parent a33aaceaa9
commit db56d8f03e
2 changed files with 10 additions and 18 deletions

View File

@@ -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)
}
}

View File

@@ -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)
}
}