UiAutomatorViewer doesn't work with secondary/multiple displays

Viewed 388

I have a multiple display scenario, which I want to test with Appium in the end. However, right now I am struggeling already with UiAutomatorViewer.

This is my scenario:

  • I have setted up Android Emulator with a secondary display: The left screen has Chrome launched, the right side YouTube (just some abitrary apps).

enter image description here

  • When I launch uiautomatorviewer (or appium using uiautomator2), it just retrieves me the content of the "main" display and I can just access the elements on this screen. Appium is showing me the same content.

enter image description here

I don't know, how I can access the secondary display as well. In a perfect approach, I would basically be able to identify all apps on all displays. Is this somehow possible?

In addition, I need to test multiple apps. Because of that single app approaches like Espresso don't work for me.

1 Answers

According to the source code, UI automator viewer dumps the view hierarchy of the active window and the screenshot is the one from the default display.

If you want to use ui automator viewer and analyze the right screenshot (and the corresponding UI hierarchy), a possible workaround might be to create both files programmatically and provide them to ui automator viewer:

adb shell am start com.google.android.calendar --display 0
adb shell screencap -d 0 -p /sdcard/screencapture0.png
adb pull /sdcard/screencapture0.png .
adb shell uiautomator dump 
adb pull /sdcard/window_dump.xml
mv window_dump.xml window_dump0.uix

now you can select "Open" on ui automator viewer and select screencapture0.png and window_dump0.uix.

By opening an app on the secondary display the focus moves to the other display and you can reinvoke the same commands to get the 2 files:

adb shell am start com.google.android.calendar --display 1
adb shell screencap -d 1 -p /sdcard/screencapture1.png
adb pull /sdcard/screencapture1.png .
adb shell uiautomator dump 
adb pull /sdcard/window_dump.xml
mv window_dump.xml window_dump1.uix

and this time the files to provide to ui automator viewer are screencapture1.png and window_dump1.uix.

Not sure if the same approach can be leveraged also to execute the tests against a specific screen.

Related