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 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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user