I'm starting to use this Gradle Managed Devices
feature and I'm facing some problems when running my Espresso
tests.
I setup the device as follows :
testOptions {
animationsDisabled = true
managedDevices {
devices {
maybeCreate<ManagedVirtualDevice>("pixel2api30").apply {
device = "Pixel 2"
apiLevel = 30
systemImageSource = "google-atd"
}
}
}
}
And then I have an Activity
that when I press a Button
it opens either a ChromeCustomTab
or a WebView
, the thing is that in my device, emulator (locally) it works but when I try to run them in GMD
it doesn't and throws me this error.
es.MyTest > testName[pixel2api30] FAILED
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://www.example.es/... (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2067)
And what I'm doing is this :
Intents.init()
try {
val expectedIntent = allOf(
hasAction(Intent.ACTION_VIEW),
anyOf(
hasPackage("com.android.chrome"),
hasPackage("com.android.webview")
),
hasData(Uri.parse(url)),
)
//on click to the button to open the `ChromeCustomTab`
intended(expectedIntent)
} finally {
Intents.release()
}
I also have this for opening a WebView
and it works though
Intents.init()
try {
//click to the button
intended(
allOf(
hasAction(Intent.ACTION_VIEW),
hasData(Uri.parse(url)),
),
)
} finally {
Intents.release()
}
Also what I saw is that some test are too fast and makes my MockWebServer
and my Dispatcher
to fail sometimes so I had to add a small wait to the views.