Error in using UIAutomatorviewer for testing Android app in Appium

限于喜欢 提交于 2019-12-17 16:16: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?

回答1:


After my tryst with the uiautomator viewer i came to know that we get the error only when:

appium server is running and we try to capture the screenshot using uiautomatorviewer.

So, whenever you want to use uiautomatorviewer make sure that server is in stopped state.




回答2:


I fixed the same issue by using following methods.

(1) Connect your Android device to your development machines;

(2) Go to command line in terminal or DOS command line for Windows;

(3) Using "adb shell" into your Android devices;

(4) Change the user to root by input "su root" in command line;

(5) Change the access right to /data/local/tmp by input "chmod 777 /data/local/tmp";

(6) Go back to uiautomatorviewer and do screen shot again, the error should be gone;

I guess there are some file can't be access if it doesn't own right in /data/local/tmp.




回答3:


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:


Easiest solution..

Restart the device. Restart uiautomatorviewer.

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




回答5:


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




回答6:


I had the same problem because I used "adbd insecure". So I just disabled "adbd insecure", and reload uiautomatorviewer, everything is OK.




回答7:


In case of rooted devices: Enable the root access in developer options for adb. Restart adb as root




回答8:


I have spent over a week to resolve this issue. When you connect your device and using ASM 3.0, when screen is projected open the UIAutomator to capture the current android screen. Without Appium it should capture. For use Android Studio instead of android sdk. Uninstall and reinstall Android Studio. It is working perfect for me now.




回答9:


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:

  • 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:

That's it. Hope it helps!




回答10:


I got also the same issue (Also if Appium Server was not running). After switch, OFF / ON USB-Debugging was working for me.




回答11:


I got it resolved

I closed the Appium Server running on my machine and opened it again. Later open uiautomater, and it worked for me




回答12:


we have to use device which has API level morethan 17 or jelly bean




回答13:


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




回答14:


What worked for me:

stop appium
open an emulator device (tested with Android 7.1.1)
go into settings > developer options > Enable view attribute inspection
open a shell on the computer, cmd or terminal depending on your OS
enter the following commands:
adb shell
su
cd /data
cd /local
chmod 777 tmp

start uiautomatorviewer
take an xml screenshot

"su chmod 777 /data/local/tmp" didnt work for me so I drilled down and it worked.
I assume that you have to do this in an emulator and not a physical device unless the device is rooted. ¯ \ _ (ツ)_/¯

Lotsa Luck!




回答15:


This happens because adb is using port and it's blocked by appium server.

I have found out best solution for this

Kill the adb.exe from taskbar processes and try launching uiautomatorviewer again




回答16:


Check whether you have enabled these under "developer options" in the phone.

  1. Verify apps via USB
  2. View attribute inspection
  3. USB debugging



回答17:


The one that works is in this path:

Android/Sdk/tools/bin/uiautomatorviewer

Paste this in your terminal and it will run automator that works




回答18:


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




回答19:


try switching Off and then ON the USB debugging option.. this work for me



来源:https://stackoverflow.com/questions/25201743/error-in-using-uiautomatorviewer-for-testing-android-app-in-appium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!