1、eclipse或者pycharm编写monkeyrunner脚本:
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage device=MonkeyRunner.waitForConnection() package ='com.wuba.zhuanzhuan' activity = '.presentation.view.activity.LaunchActivity' component = package +'/'+ activity device.startActivity(component) MonkeyRunner.sleep(2) result = device.takeSnapshot() result.writeToFile('D:TEST.png','png')
pycharm:
eclipse:
两个都会报错,但是不管啦。
个人比较喜欢pycharm,比较人性化,右击左侧的文件test.py,会有file path,文件的保存路径。
2、查看保存路径:
E:pycharm un est.py
E:javaworkspaceTestPythonaTest.py
3、手机连接电脑。打开USB调试。电脑打开cmd,
分别输入:
monkeyrunner E:pycharm un est.py 和 monkeyrunner E:javaworkspaceTestPythonaTest.py
4、等待,果真,手机打开了应用“转转”,并且截取图片保存到了D盘