Error in using UIAutomatorviewer for testing Andro

2019-01-18 03:45发布

I have to automate an Android application, I am doing the same through Appium. The problem I am facing is after launching the Appium server, the app is getting installed in the emulator 4.4.2 and to inspect the element I am using UIAutomatorviewer which comes default with SDK. But while inspecting the element of the app, I am getting the error![enter image description here][1]

Error obtaining UI hierarchy
Reason:Error while obtaining UI hierarchy XML file.com.android.ddmlb.SynchException.Remote object doesn't exist.

I tried to find the solution so that I can inspect the element so that I can script, but in vain.

  1. Can someone please tell how to fix the issue so that I can inspect elements?
  2. Is there any other way I can inspect element in the app apart from using UIAutomator viewer?

19条回答
The star\"
2楼-- · 2019-01-18 04:31

1) stop appium Server

2) open an emulator device

3) go into settings > developer options > Enable view attribute inspection

4) developer options in invisible? Go into settings > Tap on About device/phone > Scroll down till the last option(Build number) > Continuously Tap on "Build number" for 7 times > you should get an Toast message "You're a developer" > come back from that screen > Go back into settings > Now you should see developer options Tap on it > Enable view attribute inspection

5) You should no more get this error message

查看更多
不美不萌又怎样
3楼-- · 2019-01-18 04:34

Make sure everything on your screen is static. And flashing input cursor is also not allowed. Any painting actions will stop uiautomator from dumping current UI.

You can test by using following adb command:

adb shell uiautomator dump /data/local/tmp/uidump.xml

if the message ERROR: could not get idle state. appears, you are suffering from this issue.

See lines 87 & 101 of DumpCommand:

try {
  ...   
  uiAutomation.waitForIdle(1000, 1000 * 10);
  ...
} catch (TimeoutException re) {
  System.err.println("ERROR: could not get idle state.");
  return;
}
查看更多
老娘就宠你
4楼-- · 2019-01-18 04:34

Answer to your question #2 You can inspect Android app directly from your real Android device.

You need to:

  • Connect Android device to your computer/laptop
  • Go to Android device Settings -> Enable Developer Options and Android debbuging

Please see here:
Android device settings

  • Start the app you wish to inspect in your Android device

  • Open up the Chrome browser on your computer/laptop and do a right click -> More Tools -> Inspect devices -> Click on your device -> (Click on Android device OK to authorize) -> Click Inspect

Please see here: Inspect whatever from your Android device

That's it. Hope it helps!

查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-18 04:35

Easiest solution..

Restart the device. Restart uiautomatorviewer.

Worked like a charm for me .... :P

查看更多
走好不送
6楼-- · 2019-01-18 04:37

Stop the Appium Server. Then try again. It works.

查看更多
SAY GOODBYE
7楼-- · 2019-01-18 04:40

Way to bypass the ERROR:

could not get idle state.

By using uiautomator to get uix and screenshot.

public class DeviceMethods extends UiAutomatorTestCase {
public void dump(){


    try {
        getUiDevice().dumpWindowHierarchy("window_dump.uix") ;
        getUiDevice().takeScreenshot(new File("/data/local/tmp/window_dump.png"));


    } catch (Exception e) {

    }

}

you need to create the uiautomator jar and push it to /data/local/tmp

use this tutorial on how to use uiautomator

after you get the files just open them in uiautomatorviewer

查看更多
登录 后发表回答