一下代码涉及自动执行camera,属性一个小设置,恢复初始值,并在中间添加截屏功能
将两个截屏进行前后对比,并返回值
适合初学者,刚刚了解monkeyrunner 的人员来看
注意:一下脚本如果不能执行,去掉文字性的注释即可
#进行导入
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
#连接设备
device= MonkeyRunner.waitForConnection()
#运行camera
device.startActivity('com.jrdcom.android.gallery3d/com.android.jrdcamera.CameraLauncher')
#设置停顿2秒
MonkeyRunner.sleep(2)
#点击menu菜单
device.press('KEYCODE_MENU',MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(2)
#点击属性设置
device.touch(340,315,MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(2)
#点击恢复初始值
device.touch(153,744,MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(2)
#点击ok确认
device.touch(360,470,MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(5)
#截屏
result = device.takeSnapshot()
#点击home键
device.press('KEYCODE_HOME',MonkeyDevice.DOWN_AND_UP)
#一下两行去掉#就是再次启动camera
#device.startActivity('com.jrdcom.android.gallery3d/com.android.jrdcamera.CameraLauncher')
#MonkeyRunner.sleep(5)
#新的截屏
newresult = device.takeSnapshot()
#将两个截屏进行对比,并返回值,true表示一样,false表示不一样
print(newresult.sameAs(result,0.9))
#一下两行将截屏进行保存
result.writeToFile('C:/Users/val_olshao/Desktop/snap/shot1.png','png')
newresult.writeToFile('C:/Users/val_olshao/Desktop/snap/shot2.png','png')