Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UiAutomator dump for Lollipop Lost WebView View Hierarchy

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?

like image 435
shibbybird Avatar asked Dec 11 '14 16:12

shibbybird


2 Answers

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.

like image 171
benno Avatar answered Oct 16 '22 14:10

benno


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.

like image 30
bonnyz Avatar answered Oct 16 '22 15:10

bonnyz