Compare commits

..

1 Commits

Author SHA1 Message Date
514c6b85c3 ci: Instrumentation tests coverage in ci.
Some checks failed
Check PR code / EspressoReports (pull_request) Failing after 51m28s
2025-03-18 12:32:39 +01:00

View File

@ -21,7 +21,7 @@ import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector import androidx.test.uiautomator.UiSelector
import org.hamcrest.CoreMatchers.allOf import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.Matchers.hasToString import org.hamcrest.Matchers.hasToString
import org.junit.Before import org.junit.BeforeClass
import java.util.Locale import java.util.Locale
fun performLogin(someUrl: String? = null) { fun performLogin(someUrl: String? = null) {
@ -128,36 +128,39 @@ fun testAddSourceWithUrl(
} }
open class WithANRException { open class WithANRException {
// Running count of the number of Android Not Responding dialogues to prevent endless dismissal. companion object {
private var anrCount = 0 // Running count of the number of Android Not Responding dialogues to prevent endless dismissal.
private var anrCount = 0
// `RootViewWithoutFocusException` class is private, need to match the message (instead of using type matching). // `RootViewWithoutFocusException` class is private, need to match the message (instead of using type matching).
private val rootViewWithoutFocusExceptionMsg = private val rootViewWithoutFocusExceptionMsg =
java.lang.String.format( java.lang.String.format(
Locale.ROOT, Locale.ROOT,
"Waited for the root of the view hierarchy to have " + "Waited for the root of the view hierarchy to have " +
"window focus and not request layout for 10 seconds. If you specified a non " + "window focus and not request layout for 10 seconds. If you specified a non " +
"default root matcher, it may be picking a root that never takes focus. " + "default root matcher, it may be picking a root that never takes focus. " +
"Root:", "Root:",
) )
@Before private fun handleAnrDialogue() {
fun setUpHandler() { val device = UiDevice.getInstance(getInstrumentation())
Espresso.setFailureHandler { error, viewMatcher -> // If running the device in English Locale
val waitButton = device.findObject(UiSelector().textContains("wait"))
if (waitButton.exists()) waitButton.click()
}
if (error.message!!.contains(rootViewWithoutFocusExceptionMsg) && anrCount < 3) { @JvmStatic
anrCount++ @BeforeClass
handleAnrDialogue() fun setUpHandler() {
} else { // chain all failures down to the default espresso handler Espresso.setFailureHandler { error, viewMatcher ->
DefaultFailureHandler(getInstrumentation().targetContext).handle(error, viewMatcher)
if (error.message!!.contains(rootViewWithoutFocusExceptionMsg) && anrCount < 3) {
anrCount++
handleAnrDialogue()
} else { // chain all failures down to the default espresso handler
DefaultFailureHandler(getInstrumentation().targetContext).handle(error, viewMatcher)
}
} }
} }
} }
private fun handleAnrDialogue() {
val device = UiDevice.getInstance(getInstrumentation())
// If running the device in English Locale
val waitButton = device.findObject(UiSelector().textContains("wait"))
if (waitButton.exists()) waitButton.click()
}
} }