You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest { @test
fun useAppContext() {
val pkgName = "com.qin.demo"
val deviceContext = ApplicationProvider.getApplicationContext()
val intent = deviceContext.packageManager.getLaunchIntentForPackage(pkgName)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
deviceContext.startActivity(intent)
}
}
The text was updated successfully, but these errors were encountered:
To launch other apps, you will need to use uiautomator. androidjunit4 is just the runner.
Per the docs:
// Launch the app
val context = ApplicationProvider.getApplicationContext<Context>()
val intent = context.packageManager.getLaunchIntentForPackage(
BASIC_SAMPLE_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(BASIC_SAMPLE_PACKAGE).depth(0)),
LAUNCH_TIMEOUT
)
}
}
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@test
fun useAppContext() {
val pkgName = "com.qin.demo"
val deviceContext = ApplicationProvider.getApplicationContext()
val intent = deviceContext.packageManager.getLaunchIntentForPackage(pkgName)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
deviceContext.startActivity(intent)
}
}
The text was updated successfully, but these errors were encountered: