jeudi 29 août 2019

How to wait toast to showed up

I would like to create androidTest for my app. I've started with the login module witch contains multiple fragments and end with a new activity (in another module).

The last screen of login module start a CoroutineWorker to fetch data from our API. The user can see the progress of the worker through a notification. At the end of the worker (takes 30s to 5min), a toast appear with a message : "Success" or "fail"

So, when the test come to the new activity, I would like to wait this toast and check if the message is "Success"

I used this code to check the toast (using UiAutomator and Espresso)


private val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

uiDevice.wait(Until.hasObject(By.text("Synchronization finished")), 20000)




For some reason, espresso end the test before the end of the worker, I'm guessing this is because the app is idling but I'm not sure.

Aucun commentaire:

Enregistrer un commentaire