Compare commits
1 Commits
b5817865e4
...
514c6b85c3
Author | SHA1 | Date | |
---|---|---|---|
514c6b85c3 |
@ -21,7 +21,7 @@ import androidx.test.uiautomator.UiDevice
|
||||
import androidx.test.uiautomator.UiSelector
|
||||
import org.hamcrest.CoreMatchers.allOf
|
||||
import org.hamcrest.Matchers.hasToString
|
||||
import org.junit.Before
|
||||
import org.junit.BeforeClass
|
||||
import java.util.Locale
|
||||
|
||||
fun performLogin(someUrl: String? = null) {
|
||||
@ -128,36 +128,39 @@ fun testAddSourceWithUrl(
|
||||
}
|
||||
|
||||
open class WithANRException {
|
||||
// Running count of the number of Android Not Responding dialogues to prevent endless dismissal.
|
||||
private var anrCount = 0
|
||||
companion object {
|
||||
// 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).
|
||||
private val rootViewWithoutFocusExceptionMsg =
|
||||
java.lang.String.format(
|
||||
Locale.ROOT,
|
||||
"Waited for the root of the view hierarchy to have " +
|
||||
"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. " +
|
||||
"Root:",
|
||||
)
|
||||
// `RootViewWithoutFocusException` class is private, need to match the message (instead of using type matching).
|
||||
private val rootViewWithoutFocusExceptionMsg =
|
||||
java.lang.String.format(
|
||||
Locale.ROOT,
|
||||
"Waited for the root of the view hierarchy to have " +
|
||||
"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. " +
|
||||
"Root:",
|
||||
)
|
||||
|
||||
@Before
|
||||
fun setUpHandler() {
|
||||
Espresso.setFailureHandler { 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()
|
||||
}
|
||||
|
||||
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)
|
||||
@JvmStatic
|
||||
@BeforeClass
|
||||
fun setUpHandler() {
|
||||
Espresso.setFailureHandler { 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()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user