Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug UIAutomator scripts with Eclipse

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?

like image 544
neodymium Avatar asked Feb 24 '14 03:02

neodymium


People also ask

How do I run debug in eclipse?

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead.

What is the use of debugging button?

Debugging allows you to run a program interactively while watching the source code and the variables during the execution. A breakpoint in the source code specifies where the execution of the program should stop during debugging. Once the program is stopped you can investigate variables, change their content, etc.


1 Answers

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) Remote Java Application
  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!

like image 176
neodymium Avatar answered Oct 12 '22 03:10

neodymium