How do I debug UIAutomator scripts with Eclipse

后端 未结 1 593
独厮守ぢ
独厮守ぢ 2021-02-09 17:14

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

相关标签:
1条回答
  • 2021-02-09 17:34

    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!

    0 讨论(0)
提交回复
热议问题