Android Automation Test-Monkeyrunner (iii) handy Practice test scripts

Source: Internet
Author: User

#Coding=utf-8ImportOSImport Time#Import monkeyrunner Three module fromCom.android.monkeyrunnerImportMonkeyrunner, Monkeydevice, Monkeyimageruncomponent="com.dest.mr/.ui.home.homelaunchernew"Path='d:/pic/'LogPath='d:/log/'#new log file.txtLog = open (LogPath +'dest'+". txt",'W')#Connection Devicedevice =monkeyrunner.waitforconnection ()if  notDevice:log.write ('connection failed \ n') Sys.exit (1)Else: Log.write ('connection passed \ n') device.startactivity (component=runcomponent) Time.sleep (5)#Device.shell ("Logcat | grep ' com.dest.mr ' > sdcard/destlog.txt ")#Os.system ("adb logcat | findstr" com.dest.mr ">> d:/log/logcat.txt") forIinchRange (3):        #Save Log to File.txtLog.write ('start app ....'+ STR (i) +'\ n') Desthome=device.takesnapshot () desthome.writetofile (Path+'Desthome'+ STR (i) +'. PNG','PNG')        #Import Home Pictures for comparing the resultsHometure = Monkeyrunner.loadimagefromfile ('D:/pic/tdesthome.png')                if(Desthome.sameas (hometure,0.9)):                Print 'desthome pic is the same \ n'Log.write ('test passed \ n')        Else:                Print 'test byebye \ n'Log.write ('test failed \ n')                #Open UserInfoDevice.touch (850,68,'down_and_up') Time.sleep (2) UserInfo=device.takesnapshot () userinfo.writetofile (Path+'UserInfo'+ STR (i) +'. PNG','PNG') Ufoture= Monkeyrunner.loadimagefromfile ('D:/pic/tuserinfo.png')                if(Userinfo.sameas (ufoture,0.75)):                Print 'userinfo pic is the same \ n'Log.write ('userinfo test passed \ n')        Else:                Print 'userinfo pic is not the same'Log.write ('userinfo test failed \ n')        #Click Mobile, into MyInfo pageDevice.touch (550,200,'down_and_up') Time.sleep (2) MyInfo=device.takesnapshot () myinfo.writetofile (Path+'MyInfo'+ STR (i) +'. PNG','PNG') Device.drag (500,550), (300,250), 0.5) Time.sleep (2) device.press ('Keycode_back','down_and_up') Time.sleep (2) Device.touch (60,80,'down_and_up') Time.sleep (2)

Android Automation Test-Monkeyrunner (iii) handy Practice test scripts

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.