2

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.

Christopher
  • 9,682
  • 7
  • 47
  • 76
  • I am also interested in this because I need to test an app that runs on multiple displays. Found anything yet? Espresso, UiAutomator, etc? – Daniel Bejan Sep 01 '21 at 13:23
  • Unfortunately, no. We didn't found a solution. Espresso was out of scope since we need to test multiple app at the same time. One workaround was to use `am stack list` to see the activity stack and afterwards we could move the stack entry to th main display with `am display move-stack 0`. But it was not really satisfying. – Christopher Sep 02 '21 at 05:48

1 Answers1

0

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.

Lino
  • 5,084
  • 3
  • 21
  • 39