In KitKat we were able to get webview view hierarchy from a UIAutomator dump if focus was placed on the webview. I was wondering if there was substitute functionality for getting webview view hierarchy with the lollipop release, or if that functionality was lost in the release?
Took me a while to work this out, but basically, for practical purposes, yes this functionality was lost in this release.
There are some kludgy work-arounds but they aren’t reliable.
Your best bet is to write an actual unit test that is run by uiautomator, and use the dumpWindowHierarchy API to extract it yourself. If you are doing this it is important to ensure the WebView you wish to extract is created after uiautomator has started (but obviously before you make the call to dumpWindowHierarchy). The best way to achieve that will be depend on your exact circumstances.
I wrote up more speculation on why this may have changed in Lollipop in a blog post.
I'm not sure about what you need to do, but maybe setWebContentsDebuggingEnabled() could help. Enabling this will allow you to debug the content of your WebView using Chrome, it may also affect the behavior of the UiAutomator so give it a chance!
WebView web = ...
web.setWebContentsDebuggingEnabled(true);
A more detailed docs about remote debugging on webviews can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With