monkeyrunner进行多设备UI测试
生活随笔
收集整理的這篇文章主要介紹了
monkeyrunner进行多设备UI测试
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
monkeyrunner進行多設備UI測試
#導入我們需要用到的包和類并且起別名 import sys,time,datetime from com.android.monkeyrunner import MonkeyRunner as mr from com.android.monkeyrunner import MonkeyDevice as md from com.android.monkeyrunner import MonkeyImage as mi from com.android.chimpchat.hierarchyviewer import HierarchyViewer #根據ID找到ViewNode,對viewnode的一些操作等 from com.android.monkeyrunner.easy import EasyMonkeyDevice #提供了根據ID進行訪問方法touch、drag等 from com.android.monkeyrunner.easy import By #根據ID返回PyObject的方法 from com.android.hierarchyviewerlib.models import ViewNode as vn #代表一個控件,可獲取控件屬性templist = []#設置一個空列表,用來放設備內容 deviceslist =[]#設置一個空列表,用來放分割后的設備內容 devices = [] #設置一個空列表,用來讀取放分割后的設備內容 snapshot = []#設置一個空列表,用來讀取截圖 text = []#設置一個空列表,用來讀取結果文本#已經將設備列表導出adb devices>E:\devices.txt #將設備列表導入到templist中 f = open("E:\devices.txt")#讀取文件 while True:line = f.readline()#逐行讀print lineif line:templist.append(line.strip())#刪除所讀行的空格,增加到templist列表中,默認每個元素后都有\tdevicesprint templistelse:break; f.close() #關閉 print templist templist.pop(0) #刪除下標為0的元素,現在templist列表元素為['emulator-5554\tdevices','emulator-5556\tdevices',''] print templist print len(templist)#將每個元素使用\t分割,并導入到新列表 deviceslist中 for i in range(0,len(templist)-1):deviceslist.append(templist[i].split('\t')) #deviceslist列表元素為[['emulator-5554','devices'],['emulator-5556','devices']]for i in range(len(deviceslist)):#遍歷每個元素print 'current devices:'print deviceslist[i][0]#只讀取元素的前半部分devices.append(mr.waitForConnection(1.0,deviceslist[i][0]))##devices列表元素為['emulator-5554','emulator-5556']if not devices:print >> sys.stderr,"fail"sys.exit(1)else:print 'connnect success'#啟動activitydevices[i].startActivity('com.sky.jisuanji/.JisuanjizixieActivity')easy_device = EasyMonkeyDevice(devices[i])#初始化EasyMonkeyDevice模塊,必須放在startActivity之后,用來通過ID訪問控件hViewer = devices[i].getHierarchyViewer() # 對當前UI視圖進行解析#輸入賬號Cotent='6000000891'device.type(Cotent)mr.sleep(3.0)#點擊確定easy_device.touch(By.id('id/register_input_mobile_btn'),device.DOWN_AND_UP)mr.sleep(30.0)#輸入驗證碼Cotent='5957'device.type(Cotent)mr.sleep(3.0)#點擊確定easy_device.touch(By.id('id/register_check_btn'),device.DOWN_AND_UP)mr.sleep(30.0)#點擊moreeasy_device.touch(By.id('id/layout_tabhost_icon'),device.DOWN_AND_UP)mr.sleep(30.0)#點擊設置easy_device.touch(By.id('id/appsetting'),device.DOWN_AND_UP)mr.sleep(30.0)#點擊賬號easy_device.touch(By.id('id/my_account_layout'),device.DOWN_AND_UP)mr.sleep(30.0)#點擊下線easy_device.touch(By.id('id/setting_layout'),device.DOWN_AND_UP)mr.sleep(30.0)#點擊確定下線easy_device.touch(By.id('id/btn_ok'),device.DOWN_AND_UP)mr.sleep(5.0)#進行takeSnapshot截圖snapshot.append(devices[i].takeSnapshot())print 'end snapshot'#創建時間字符串t = time.strftime("%Y-%m-%d-%X",time.localtime())t = t.replace(":","-")#保存截圖snapshot[0].writeToFile(deviceslist[i][0]+'-'+t+'-'+'.png','png');snapshot.pop()#通過By來獲取text.append(easy_device.getText(By.id('id/text')))print text[i].encode('utf-8')#打印結果#比較設備輸出的結果 for i in range(len(devices)-1):for j in range(1,len(devices)):if text[i]==text[j]:print 'true'else:print 'false'總結
以上是生活随笔為你收集整理的monkeyrunner进行多设备UI测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Science Robotics | 美
- 下一篇: mac 命令行自动安装软件