How do I debug UiAutomator scripts with Eclipse

网上千篇一律的介绍UiAutomator测试了,近期在用UiAutomator写UI自动自动化测试,在开发scripts过程中发现写的TestCase过多了调试很不方便。使用打印log调试效率特别低。在Android Deveplopers官网上有adb shell uiautomator runtest XXX.jar -e debug true -c + 类名,在启动Uiautomator测试之前等待一个debug模式连接手机。但在官网上没找到如何debug。在Google中看到一个,立马分享晒一晒

理解的关键在于如何使用DDMS(Dalvik Debug Monitor Server),并且通过Eclipse里的java进行远程debug(即在pc端远程debug手机端中的uiautomator)。

以下是远程debug Uiautomator测试的的具体操作步骤:

   1、 启动Debug Configration,并在此创建一个实例,用于加载UiAutomaotr Project,使UiAutomaotr Project在debug调试中按照自己定义的模型运行,如图11.jpg,22.jpg所示

  

 

  备注:其中的Port端口号建议自己另外定义。因为默认的端口号容易被其他进程占用,会导致后面Debug失败的现象。我第一次就没定义启动失败告终。

2、在cmd中运行命令ant build把编写好的UiAutomator scripts打成一个jar包,运行adb push xxxx.jar /data/local/tmp 把包push到手机中,运行命令adb shell uiautomator runtest XXX.jar -e debug true -c Class_Name(可以实现一键自动化,即运行ant run即可实现上述所有的操作)。在cmd会出现如图所示,即在启动uiautomator测试之前等待debug连接:


3、启动Eclipse中的DDMS,如图所示:

   ,可以看到一个红色的虫子,那个就是还代表设置成功

4、切回到Java编辑页面,在Script中打好断点,用之前在Debug Configration中编辑好的debug来启动,如图所示:

猜你喜欢

转载自ilovejoe.iteye.com/blog/2101748
今日推荐