How do I debug UIAutomator scripts with Eclipse

泪湿孤枕 提交于 2020-01-01 03:17:09

问题


From what I can see, when a UIAutomator script is compiled into a jar file and it gets run by using the adb shell command. I can see that there is a -e debug command line option which waits for a debugger to connect before starting but how do I connect this to the debugger from Eclipse so I can debug my UI Automator script?


回答1:


I've worked it out. The process is a little long winded but it works!

The key to this is understanding how to use the Dalvik Debug Monitor Server (DDMS) and understanding remote debugging with Java and Eclipse. In brief follow the following steps:

  1. Set up a DDMS perspective in Eclipse by clicking Window > Open Perspective > Other... > DDMS. You should see your device listed in the Devices tab, assuming you have an emulator/device running.
  2. Set up a remote debugging configuration. To do this go to Run > Debug Configurations...
  3. Right click on Remote Java Application from the left hand panel and click 'New' to create a new configuration.
  4. In the connection properties use localhost and port 8700. In my case I am using an emulator that is running on my local development machine. The default port for DDMS is 8700. If this is not the case for your setup you can check what port needs to be from the DDMS perspective after the UI Automator script is run in debug mode. (See steps 7-9 below)

  5. Ensure that the project you've selected is the UI Automation project that you will be running. In the "Source" tab you may also add the UI Automation project there also. (Not sure if this is mandatory or not)
  6. Click "Apply" and then close.
  7. Now we will start running the UI Automator script with the debug option using the command line. For my example the command is (all on one line):

    adb shell uiautomator runtest AndroidUIAutomation.jar -c com.example.uiautomation.TestUiAutomation -e debug true

  8. It will then say:

    Sending WAIT chunk

  9. In Eclipse go into the DDMS perspective. Under the Devices tab you should see a process with a little red bug symbol. Next to it will be a question mark. In the last column in the table there will be two port numbers such as 8602/8700. The port 8700 is the one you will connect your remote debugging session to. This is what should be configured in step 4 above.

  10. Now you are ready to start remote debugging. Set a breakpoint somewhere in the UI Automator script. Then debug by going to Run > Debug Configurations... and then select the Remote Java Application configuration that you created earlier and then click on "Debug".

If everything has gone well, then you should be able to debug your UI Automator script!



来源:https://stackoverflow.com/questions/21978292/how-do-i-debug-uiautomator-scripts-with-eclipse

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