• MonkeyRunner_真机_运行脚本(二)


     1 # -*- coding: UTF-8 -*-  
     2 #手机分辨率为1080*1920
     3 import sys
     4 from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
     5 
     6 def install(d):
     7     MonkeyRunner.sleep(3)
     8     d.removePackage('com.xxx.phone')
     9     print "uninstall success!!"
    10     MonkeyRunner.sleep(2)
    11     d.installPackage('d:mkxxxphone.apk')
    12     print "install success!!"
    13     MonkeyRunner.sleep(2)
    14 
    15     d.wake()
    16     d.touch(800,1900,'DOWN_AND_UP')  
    17     MonkeyRunner.sleep(2)
    18     d.startActivity(component="com.xxx.phone/com.xxx.phone.activity.WelcomeActivity") 
    19     MonkeyRunner.sleep(5)
    20     d.wake()
    21     d.drag((800,600),(400,600),0.1,10) 
    22     d.wake()
    23     MonkeyRunner.sleep(2)
    24     d.drag((800,600),(300,600),0.1,10) 
    25     MonkeyRunner.sleep(2)    
    26     d.touch(530,1600,'DOWN_AND_UP') 
    27     MonkeyRunner.sleep(3)
    28     d.touch(533,1007,'DOWN_AND_UP') 
    29     MonkeyRunner.sleep(2)    
    30     d.touch(533,1800,'DOWN_AND_UP') 
    31 
    32 def main():
    33     print "Start"
    34     device=MonkeyRunner.waitForConnection()
    35     if not device:
    36         print "Couldn't connect the device"
    37         sys.exit()
    38     print "Conneted device"
    39     install(device)
    40     
    41     
    42 if __name__ == '__main__':
    43     main()

    1.因为在Notepad默认编码为Ascll,所以在首行加入编码注释(必须放在第一行或者第二行),# -*- coding:utf-8 -*- 

    2.因为是按坐标执行,代码只支持对应的分辨率,手机分辨率可在设置中查看或者画图软件中查看最大坐标值,#手机分辨率为1080*1920

    3. 每个用例可以封装为一个函数 def

  • 相关阅读:
    bzoj 2152: 聪聪可可
    bzoj 2143: 飞飞侠
    bzoj 2132: 圈地计划
    bzoj 2127: happiness
    bzoj 2124: 等差子序列
    bzoj 2120: 数颜色
    对MySQL数据类型的认识
    MySQL详解--锁,事务(转)
    mysql 5.7快速部署
    elasticsearch报错[WARN ][bootstrap ] Unable to lock JVM Memory: error=12,reason=Cannot allocate memory,解决
  • 原文地址:https://www.cnblogs.com/happy-xiaoxiao/p/8268460.html
Copyright © 2020-2023  润新知