Код: Выделить всё
-keep class androidx.test.espresso.IdlingRegistry { *; }
-keep class androidx.test.espresso.IdlingResource { *; }
-keep class my.app.namespace.ServerCommunication {
getIdlingResource();
}
< /code>
Но теперь я получаю другую ошибку. < /p>
androidx.test.espresso.PerformException: Error performing 'single click - At Coordinates: 539, 911 and precision: 16, 16' on view 'view.getId() is '.
at androidx.test.espresso.PerformException$Builder.build(PerformException.java:86)
at androidx.test.espresso.base.PerformExceptionHandler.handleSafely(PerformExceptionHandler.java:56)
at androidx.test.espresso.base.PerformExceptionHandler.handleSafely(PerformExceptionHandler.java:31)
at androidx.test.espresso.base.DefaultFailureHandler$TypedFailureHandler.handle(DefaultFailureHandler.java:158)
at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:120)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:385)
at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:212)
at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:140)
at my.app.namespace.test.LoginActivityTest.login(LoginActivityTest.kt:41)
... 36 trimmed
Caused by: java.lang.IllegalStateException: Resource my.app.namespace.ServerCommunication isIdleNow() is returning true, but a message indicating that the resource has transitioned from busy to idle was never sent.
at androidx.test.espresso.base.IdlingResourceRegistry$Dispatcher.handleRaceCondition(IdlingResourceRegistry.java:548)
Код: Выделить всё
package my.app.namespace.test
import android.Manifest
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.rule.GrantPermissionRule
import my.app.namespace.ServerCommunication
import my.app.namespace.activity.LoginActivity
import my.app.namespace.R
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@LargeTest
class LoginActivityTest {
@get:Rule
val activityRule = activityScenarioRule()
@get:Rule
val permissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Manifest.permission.CAMERA,
Manifest.permission.ACCESS_FINE_LOCATION,
)
@Before fun setup() { IdlingRegistry.getInstance().register(ServerCommunication.idlingResource) }
@After fun teardown() { IdlingRegistry.getInstance().unregister(ServerCommunication.idlingResource) }
@Test
fun login() {
onView(withId(R.id.USER_NAME_BOX)).perform(replaceText("test"))
onView(withId(R.id.USER_PASSWORD_BOX)).perform(replaceText("password"))
onView(withId(R.id.LOGIN_BUTTON)).perform(click()) // fails here
onView(withId(R.id.TEXT_BOX)).perform(replaceText("1235"))
onView(withId(R.id.BUTTON_DONE)).perform(click())
onView(withText("OK")).perform(click())
onView(withText("Ok")).perform(click())
}
}
Код: Выделить всё
import androidx.annotation.VisibleForTesting
import androidx.test.espresso.IdlingResource
import androidx.test.espresso.idling.net.UriIdlingResource
object ServerCommunication {
@VisibleForTesting
val idlingResource: IdlingResource get() = uriIdlingResource
private val uriIdlingResource = UriIdlingResource(ServerCommunication::class.java.name, 100)
public fun callApi() {
val uri = "https://example.com"
try {
uriIdlingResource.beginLoad(uri)
// ... do API call
} finally {
uriIdlingResource.endLoad(uri)
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... lingresour