Monkeyrunner for multi-device UI testing _monkeyrunner

Source: Internet
Author: User

Monkeyrunner for multi-device UI testing

#导入我们需要用到的包和类并且起别名 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, some operations on viewnode, etc. from Com.android.monkeyrunner.easy Import Easymonkeydevice #提供了根据ID进行访问方法touch, drag, etc. from Com.android.monkeyrunner.easy  The import by #根据ID返回PyObject的方法 the from com.android.hierarchyviewerlib.models import Viewnode as vn #代表一个控件 to get control properties Templist = [] #设置一个空列表, used to put the contents of the device deviceslist =[] #设置一个空列表, used to put the split device content devices = [] #设置一个空列表, used to read the partition of the device content snapshot = [] #设置一个空列表, used to read Take a screenshot of text = [] #设置一个空列表, to read the result text #已经将设备列表导出adb devices>e:\devices.txt #将设备列表导入到templist中 f = open ("E:\devices.txt") # Read file while true:line = F.readline () #逐行读 Print line if Line:templist.append (Line.strip ()) #删除所读行的空格, increasing
To the Templist list, the default is \tdevices print templist else:break after each element; F.closE () #关闭 print templist templist.pop (0) #删除下标为0的元素, now Templist list element is [' emulator-5554\tdevices ', ' emulator-5556\tdevices ' , the '] print templist print len (templist) #将每个元素使用 \ t split and imported into the new list deviceslist for the I in Range (0,len (templist)-1): Devicesl


Ist.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.A
        Ppend (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 ' #启动activity D Evices[i].startactivity (' com.sky.jisuanji/. Jisuanjizixieactivity ') Easy_device = Easymonkeydevice (Devices[i]) #初始化EasyMonkeyDevice模块, must be placed after startactivity, Used to access control Hviewer = Devices[i].gethierarchyviewer () # to parse the current UI view #输入账号 cotent= ' 6000000891 ' Device.typ E (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) #点击more Easy_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 Snapsh OT ' #创建时间字符串 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 '


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.