Compare commits

..

1 Commits

Author SHA1 Message Date
ec6433497a ci: Instrumentation tests coverage in ci.
Some checks are pending
Check PR code / BuildAndTestAndCoverage (pull_request) Has started running
2025-03-25 21:16:03 +01:00
3 changed files with 18 additions and 3 deletions

View File

@ -93,6 +93,6 @@ class `1-LoginActivityTest` : WithANRException() {
performLogin()
onView(withText(R.string.gdpr_dialog_title)).check(matches(isDisplayed()))
onView(withText("OK")).perform(click())
onView(withId(R.id.swipeRefreshLayout)).perform(waitUntilNotLoading(300000))
checkHomeLoadingDone()
}
}

View File

@ -15,6 +15,7 @@ import androidx.test.espresso.action.ViewActions.typeTextIntoFocusedView
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.base.DefaultFailureHandler
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
@ -24,6 +25,7 @@ import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.not
import org.hamcrest.Matchers.hasToString
import org.junit.BeforeClass
import java.io.BufferedOutputStream
@ -139,6 +141,10 @@ fun testAddSourceWithUrl(
onView(withText(sourceName)).check(matches(isDisplayed()))
}
fun checkHomeLoadingDone() {
onView(withId(R.id.swipeRefreshLayout)).inRoot(not(isDialog())).perform(waitUntilNotLoading(300000))
}
@Suppress("detekt:UtilityClassWithPublicConstructor")
open class WithANRException {
companion object {

View File

@ -24,6 +24,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withParent
import androidx.test.espresso.matcher.ViewMatchers.withResourceName
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.util.HumanReadables
import androidx.test.espresso.util.TreeIterables
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.any
import org.hamcrest.Description
@ -55,7 +56,7 @@ fun waitUntilNotLoading(millis: Long): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> = any(View::class.java)
override fun getDescription(): String = "wait for a specific view is hidden during $millis millis."
override fun getDescription(): String = "wait for a specific view is not loading during $millis millis."
override fun perform(
uiController: UiController,
@ -66,7 +67,15 @@ fun waitUntilNotLoading(millis: Long): ViewAction {
val endTime = startTime + millis
do {
// found view with required ID
// either the empty view is displayed
for (child in TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (withId(R.id.emptyText).matches(child) && !child.isShown) {
return
}
}
// or the refresh layout is refreshing
if (view is SwipeRefreshLayout && !view.isRefreshing) {
return
}