0

I have a few Espresso tests that fail randomly when trying to click a button. Sometimes, the tests fail with a ViewNotFoundException. It appears that the Activity state during this exception is one step behind the expected state.

Note that inserting a Thread.sleep() does not solve the issue.

What are possible workarounds to fix those tests?

Mike76
  • 899
  • 1
  • 9
  • 31
  • Is it possible to get the whole trace ? Is there some network call during when you are planning to click? – ponkape Oct 09 '19 at 11:32
  • There are network calls, but these network calls do not matter for the button that is clicked. – Mike76 Oct 09 '19 at 11:37
  • Possible duplicate of [Android Espresso wait for text to appear](https://stackoverflow.com/questions/49796132/android-espresso-wait-for-text-to-appear) – jeprubio Oct 09 '19 at 14:33
  • You can set either an `IdlingResource` or the `waitId` method from https://stackoverflow.com/questions/49796132/android-espresso-wait-for-text-to-appear – jeprubio Oct 09 '19 at 14:34

1 Answers1

0

It is possible that you are falling behind because of asynchronous tests. Thread.sleep() is not a viable solution, please try to use IdlingResource instead : https://developer.android.com/training/testing/espresso/idling-resource Maybe this will help little bit better: https://medium.com/@pedroabinajm/espresso-my-test-is-flaky-28d20cf9b7b7

voy
  • 696
  • 7
  • 14