入门monkeyrunner7-monkeyrunner demo3 EasyMonkeyDevice+hierarchyviewer +monkeyrunner+截图对比
生活随笔
收集整理的這篇文章主要介紹了
入门monkeyrunner7-monkeyrunner demo3 EasyMonkeyDevice+hierarchyviewer +monkeyrunner+截图对比
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 #該demo為monkeyrunner測試安卓系統自帶的計計算器
2 #測試圖片對比,測試EasyMonkeyDevice對象,一些他的元素操作
3 #作者:Mads Spiral QQ:79523822 如有疑問留言或者加qq,驗證wyx
4 #coding=utf-8
5 import sys
6 import time
7 from com.android.monkeyrunner import MonkeyRunner as mr
8 from com.android.monkeyrunner import MonkeyDevice as md
9 from com.android.monkeyrunner import MonkeyImage as mi
10 from com.android.chimpchat.hierarchyviewer import HierarchyViewer,ViewNode
11 from com.android.monkeyrunner.easy import EasyMonkeyDevice,By
12
13 #圖片對比
14 def img():
15 result1 = device.takeSnapshot()
16 result1.writeToFile(path+"第一張截圖".decode('utf-8')+now+'.png','png')
17 #點擊了按鈕7,105.514
18 device.touch(105,514,'DOWN_AND_UP')
19 #輸入8
20 device.type("8")
21 #拖動,坐標開始到坐標結束,0.1為所用時間,1,從9(461.490)到7(63,493)
22 #device.drag((461.490),(63,493),0.1,1)
23 result2 = device.takeSnapshot()
24 result2.writeToFile(path+"第二張截圖".decode('utf-8')+now+'.png','png')
25 if(result1.sameAs(result2,0.9)):
26 #這里需要help,為什么控制臺顯示為亂碼,知道的朋友請留言
27 #str1="搜索框圖片對比成功"
28 #str1.decode('unicode').encode('gb18030')
29 #print str1
30 print "img success"
31 log.write("搜索框圖片對比成功\n”)
32 else:
33 #str2="搜索框圖片對比失敗"
34 #str2.decode('unicode').encode('gb18030')
35 #print str2
36 print "img falied"
37 log.write("搜索框圖片對比失敗”)
38 #如果要從文件夾讀取指定的圖片
39 #result=MonkeyRunner.loadImageFromFile('D:/picture2/demo.png')
40
41 '''測試EasyMonkeyDevice的一些方法,一些方法請看
42 http://blog.csdn.net/zhubaitian/article/details/39992597'''
43 def easyMonkeyDevice():
44 easydevice=EasyMonkeyDevice(device)
45
46 def easyMonkeyDevicetest():
47 mr.sleep(5.0)
48 #觸摸,下面兩句話可以合成一句話easydevice.touch(By.id("id/mul"),MonkeyDevice.DOWN_AND_UP)
49 DisagreeButton=By.id("id/digit9")
50 easydevice.touch(DisagreeButton,MonkeyDevice.DOWN_AND_UP)
51 #輸入 easydevice.type(By.id(""),'new')
52 #是否存在 easydevice.exist(By.id("")),返回一個bool值
53 #是否可見 easydevice.visible(By.id(""))
54 #獲取該id控件的文本 easydevice.getText(By.id(""))
55 #獲取該id控件的坐標 easydevice.locate(By.id(""))
56
57 #HierarchyViewer和ViewNode,獲取控件的width、height、坐標、文本
58 def hieview():
59 easyMonkeyDevice()
60 hv=easydevice.getHierarchyViewer()
61 hvid=hv.findViewById("com.android.calculator2:id/digit9")
62 print("Width: "+str(hvid.width))
63 print("Height: "+str(hvid.height))
64 hvview=hv.getAbsoluteCenterOfView(hvid)
65 print("vnT528dCoordinate1X: "+str(hvview.x))
66 print("vnT528dCoordinate1Y: "+str(hvview.y))
67 hvview2=hvT528d.getAbsolutePositionOfView(hvid)
68 print("vnT528dCoordinate2X: "+str(hvview2.x))
69 print("vnT528dCoordinate2Y: "+str(hvview2.y))
70
71
72 logpath='D:\\'
73 path='D:\\'
74 device=mr.waitForConnection()
75 if device:
76 print "connect device successed"
77 #若安裝淘寶apk。參數是apk文件的位置,因為python不支持中文輸入,所以在后面用了.decode('utf-8')這個方法轉碼。
78 #device.installPackage ('D:\\apk\\淘寶.apk'.decode('utf-8'))
79 now=time.strftime("%Y-%m-%d-%H-%M-%S")
80 log=open(logpath+"log"+now+".txt",'w')
81 activity='com.android.calculator2/com.android.calculator2.Calculator'
82 device.startActivity(activity)
83 mr.sleep(5.0)
84 #img()
85 easyMonkeyDevice()
86 easyMonkeyDevicetest()
87 hieview()
88
89 else:
90 print "connect device failed"
?
轉載于:https://www.cnblogs.com/wyx123/articles/4189956.html
總結
以上是生活随笔為你收集整理的入门monkeyrunner7-monkeyrunner demo3 EasyMonkeyDevice+hierarchyviewer +monkeyrunner+截图对比的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 查看oracle死锁进程并结束死锁
- 下一篇: JQuery学习系列总结—菜单制作