There is an auxiliary class DialogIdlingResource , thanks to which I try to run my tests, all tests pass except this activates and runs to the step of pressing the button:
AcceptanceHelper.clickOnButtonInLayout(R.id.mainSignButton, R.string.common_signin_button_text, R.id.inputLayout) then everything stops, although the test is supposed to work out (namely, check the text in the isDialogRunning method):
@Test fun signInUserWithInvalidEmail() { goToSignIn() AcceptanceHelper.updateValidationTextView(R.string.ui_data_attribute_email, "kokojambo@mail.ru") AcceptanceHelper.updateValidationTextView(R.string.ui_data_attribute_password, VALID_PASSWORD) AcceptanceHelper.clickOnButtonInLayout(R.id.mainSignButton, R.string.common_signin_button_text, R.id.inputLayout) val idlingResource = DialogIdlingResource() registerDialogIdlingResource() unregisterDialogIdlingResource() } private fun registerDialogIdlingResource() { val instrumentation = InstrumentationRegistry.getInstrumentation() idlingResource = DialogIdlingResource() Espresso.registerIdlingResources(idlingResource) } private fun unregisterDialogIdlingResource() { Espresso.unregisterIdlingResources(idlingResource) } I suppose that the error is due to the two methods of registration and UN registration idlingResource
But in fact, everything should work, but maybe somewhere that most likely made a mistake, the code of the auxiliary class:
class DialogIdlingResource(private val waitTimeSeconds: Int = 5) : IdlingResource { private var resourceCallback: IdlingResource.ResourceCallback? = null private var startTime = -1L override fun getName(): String { return DialogIdlingResource::class.java.name } override fun isIdleNow(): Boolean { if (startTime < 0) { startTime = System.currentTimeMillis() } val timeOut = System.currentTimeMillis() - waitTimeSeconds * 1000 > startTime if (timeOut) throw TimeoutException("error") val idle = !isDialogRunning if (idle && resourceCallback != null) { resourceCallback!!.onTransitionToIdle() } return idle } override fun registerIdleTransitionCallback(resourceCallback: IdlingResource.ResourceCallback) { this.resourceCallback = resourceCallback } private val isDialogRunning: Boolean get() { try { onView(Matchers.allOf(withId(R.id.titleTextView), ViewMatchers.withText("Warning"))) .check(ViewAssertions.matches(isDisplayed())) } catch (e: NoMatchingViewException) { e.printStackTrace() System.out.println("some text") } return true } }