Espresso UiObject.click() on the app to resume from recent apps

466 Views Asked by At

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]
0

There are 0 best solutions below