2019独角兽企业重金招聘Python工程师标准>>>

一、环境

    windows 10  + python3.6

二、需求

    1、模拟android设备高频点击事件;

    2、模拟规定次数的点击事件或模拟规定时间内的点击事件;

三、code

    1、模拟规定时间内的点击事件

#!/usr/bin/env python3 # coding=utf-8import subprocessimport timedef loop_click_for_android(run_time=5):    res = subprocess.Popen('adb devices',                           shell=True, stdout=subprocess.PIPE)    res.stdout.read()    inputs = str(input("请确保已打开测试页面(y/n): "))    if inputs == "y":        num = 0        node_time = time.time()        start_buttun = subprocess.Popen("adb shell input tap 600 1660")        if start_buttun:            while True:                result = subprocess.Popen("adb shell input tap 600 1660")                if result:                    num += 1                    if node_time + run_time <= time.time():                        break                    else:                        continue        print("发送点击次数{}".format(num))   # 次数统计并不准确    else:        print("程序关闭~")        exit(1)loop_click_for_android()

    2、模拟规定次数的点击事件

# !/usr/bin/env python3# coding=utf-8import subprocessimport timedef loop_click_for_android(run_num=150):    res = subprocess.Popen('adb devices',                           shell=True, stdout=subprocess.PIPE)    res.stdout.read()    inputs = str(input("请确保已打开测试页面(y/n): "))    if inputs == "y":        num = 0        node_time = time.time()        start_buttun = subprocess.Popen("adb shell input tap 600 1660")        if start_buttun:            while True:                result = subprocess.Popen("adb shell input tap 600 1100")                if result:                    num += 1                    if num == run_num:                        break                    else:                        continue        over_time = time.time()        print("{}次点击的运行时间是:{}".format(run_num, over_time-node_time))   # 次数统计并不准确    else:        print("程序关闭~")        exit(1)loop_click_for_android()

 

转载于:https://my.oschina.net/medivhxu/blog/1619324

更多相关文章

  1. Android(安卓)模拟器实现打电话
  2. android studio下module 未指定output path问题解决办法
  3. android 让通知不被清除或者点击后不消失
  4. android -x86 虚拟机成功安装
  5. [Android(安卓)Studio]设置Button的圆角、点击效果、按钮颜色
  6. android socket通信 模拟器可以 真机不行 是防火墙的原因
  7. 开始搞个android定位demo(1)
  8. android实现点击按钮切换不同的fragment布局
  9. android绑定点击事件的四种方法

随机推荐

  1. Java原子类实现原理分析
  2. 聊下JVM内存模型
  3. JVM垃圾回收机制
  4. 三分钟秒懂BIO/NIO/AIO区别?
  5. 你在 Python 中常常写的 with..as.. 到底
  6. 多文件上传-MVC依赖注入-容器管理依赖对
  7. MYSQL数据库CURD中常用操作命令汇总及代
  8. Python中的arange是什么?和range有什么不
  9. kafka查看版本
  10. 用户管理加登录验证、注册、管理权限