2

I'm trying to make an espresso UI test for android application which check whether the session is still exist after background the app and foreground it again

I tried to use that code

    val device = UiDevice.getInstance(getInstrumentation())
    device.pressHome()
    device.pressRecentApps()
    device.findObject(UiSelector().text(getInstrumentation().targetContext.getString(getInstrumentation().targetContext.applicationInfo.labelRes)))
            .click()

And it was working for Android devices with SDK < 29, but when I tried to use it for SDK >= 29, it freezes when it tried to click on the app after press on the recent app

Here is the logcat for the error message

androidx.test.uiautomator.UiObjectNotFoundException: UiSelector[TEXT=My Application]
Lino
  • 5,084
  • 3
  • 21
  • 39
Andrew Emad
  • 277
  • 3
  • 13
  • It sounds like you're essentially trying to test what happens in lifecycle changes. Consider using ActivityScenario for your tests instead of relying on UI Automator, so you can control lifecycle events more safely. – gosr Oct 31 '20 at 21:15

0 Answers0