UIAutomator 1 or 2 ? - what is Android 7+ hybrid app testing strategy

We have the hybrid app fully covered by Appium tests which work well with UIAutomator 1 for native context as well as for WebView.

Unfortunately, based on many post and trials (e.g. here) looks like like UIAutomator 1 is not longer supported for newer Androids and doesn’t work in native context (neither xPath nor UISelector queries work).

From other hand UIAutomator2 works totally in different way. It fixes the Android 7 searches in native context but in WebView seems to be useless due to the UIObject2 usage which becomes stale quickly for fast changing UI.

For example with new UIAutomator2 I’m unable to reliably use getElementSize from WebdriverIO because from time to time it throws android.support.test.uiautomator.StaleObjectException .
That command gets elementID in first step and than uses it in size command like this:

[appium] [HTTP] --> GET /wd/hub/session/a8a3e663-8717-4d08-a7fd-a4a009cc3227/element/6be08f7a-3cee-4b6e-8a75-5e23ea3a9d0e/size {}

Unfortunately even if the queried element still exists, it’s not found, because in the meantime (matter of milliseconds) something else changed on the view.

So the question are:

  1. What is the best approach to tackle that issue ?
  2. Is there any possibility to still use old UIObject with UIAutomator2 ?
1 Like

Agree. StaleObjectException is a bug forcing duplicate code to avoid it. I’m interesting too when this nasty bug will be fixed in which version of Appium? For now uiautomator2 is not usable.

  1. did you try switch to WebView before looking for element size?
  2. how you are looking for element? by id or uiAutomator (like new UiSelector()…) ?

I also would like to know when it will be changed/fixed is there any ETA ?

This exception is really problematic, cause most of my tests to fail
Can anyone suggest a workaround? Nothing seems to help…