blob: 4d39b55a253a7f9df4d1a7506c13002786aa483b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
package com.mapbox.mapboxsdk.integration
import android.content.Intent
import android.support.test.InstrumentationRegistry
import android.support.test.uiautomator.*
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert
import org.junit.Before
const val LAUNCH_TIMEOUT = 2500L
private const val TEST_APP_PACKAGE = "com.mapbox.mapboxsdk.testapp"
abstract class BaseIntegrationTest {
protected lateinit var device: UiDevice
@Before
open fun beforeTest() {
// Initialize UiDevice instance
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
// Start from the home screen
device.pressHome()
// Wait for launcher
val launcherPackage: String = device.launcherPackageName
MatcherAssert.assertThat(launcherPackage, CoreMatchers.notNullValue())
device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT)
// Launch the app
val context = InstrumentationRegistry.getInstrumentation().context
val intent = context.packageManager.getLaunchIntentForPackage(TEST_APP_PACKAGE).apply {
// Clear out any previous instances
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
}
context.startActivity(intent)
// Wait for the app to appear
device.wait(
Until.hasObject(By.pkg(TEST_APP_PACKAGE).depth(0)),
LAUNCH_TIMEOUT
)
}
fun openFeature(featureName: String) {
scrollRecyclerViewTo(featureName)
device.findObject(UiSelector().text(featureName)).clickAndWaitForNewWindow()
device.waitForIdle(LAUNCH_TIMEOUT)
}
fun scrollRecyclerViewTo(recycleItem: String) {
val appView = UiScrollable(UiSelector().scrollable(true))
appView.scrollIntoView(UiSelector().text(recycleItem))
}
fun pressHomeReturnWithRecentApps(){
device.pressRecentApps()
device.findObject(UiSelector().text(InstrumentationRegistry.getTargetContext().getString(InstrumentationRegistry.getTargetContext().applicationInfo.labelRes))).click()
}
}
|