App自动化测试(五)之swipe滑动操作
App自动化测试之swipe滑动操作
分析滑动坐标
从上图我们可以分析出每个点的坐标,
假设屏幕宽为 width,高为 height
A:(0.5 * width,0.1 * height)
B:(0.5 * width,0.9 * height)
C:(0.1 * width,0.5 * height)
D:(0.9 * width,0.5 * height)
进行滑动操作:
向左滑动:D -->> C
向右滑动:C -->> D
向上滑动:B -->> A
向下滑动:A -->> B
swipe滑动操作
swipe(self, start_x, start_y, end_x, end_y, duration=None)从一个点滑动到另外一个点start_x 是开始滑动的x坐标, start_y 是开始滑动的y坐标end_x 是结束点x坐标,end_y是结束点y坐标duration是持续时间,单位毫秒,可以不填,一般设置为500-1000之间
1、获取屏幕窗口的大小
window_size = driver.get_window_size()
2、获取宽高
# 获取宽度
width = window_size['width']
# 获取高度
height = window_size['height']
3、使用swipe进行滑动操作
a. 向左滑动(D -->> C)
driver.swipe(0.9 * width, 0.5 * height, 0.1 * width, 0.5 * height, 200)
b. 向右滑动(C -->> D)
driver.swipe(0.1 * width, 0.5 * height, 0.9 * width, 0.5 * height, 200)
c. 向上滑动(B -->> A)
driver.swipe(0.5 * width, 0.9 * height, 0.5 * width, 0.1 * height, 200)
d. 向下滑动(A -->> B)
driver.swipe(0.5 * width, 0.1 * height, 0.5 * width, 0.9 * height, 200)
封装滑动操作,使之更加灵活
通过上图可以知道scale是代表的滑动距离所占的比例,可以得到每个点的坐标:
假设屏幕的宽高为 x,y
A:(0.5 * x, (1-scale)/2 * y )
B:(0.5 * x, (1+scale)/2 * y)
C:((1-scale)/2 * x, 0.5 * y)
D:((1+scale)/2 * x, 0.5 * y)
1、封装滑动操作需要的前置条件
class BasePage(object):def __init__(self, driver):self.driver = driver@propertydef get_window_size(self):"""获取窗口大小"""return self.driver.get_window_size()@propertydef x(self):"""获取x轴宽度"""return self.get_window_size['width']@propertydef y(self):"""获取y轴高度"""return self.get_window_size['height']
2、封装向左滑动操作
def swipe_left(self, scale=0.8):"""向左滑动:param scale: 滑动距离所占比例起点:(1+scale)x/2, 0.5y终点:(1-scale)x/2, 0.5y"""self.driver.swipe(self.x * (1 + scale) / 2, self.y * 0.5, self.x * (1 - scale) / 2, self.y * 0.5)
3、封装向右滑动操作
def swipe_right(self, scale=0.8):"""向右滑动:param scale: 滑动距离所占比例起点:(1-scale)x/2, 0.5y终点:(1+scale)x/2, 0.5y"""self.driver.swipe(self.x * (1 - scale) / 2, self.y * 0.5, self.x * (1 + scale) / 2, self.y * 0.5)
4、封装向上滑动操作
def swipe_up(self, scale=0.8):"""向上滑动:param scale: 滑动距离所占比例起点:0.5x, (1+scale)*y/2终点:0.5x, (1-scale)*y/2"""self.driver.swipe(self.x * 0.5, self.y * (1 + scale) / 2, self.x * 0.5, self.y * (1 - scale) / 2)
5、封装向下滑动操作
def swipe_down(self, scale=0.8):"""向下滑动:param scale: 滑动距离所占比例起点:0.5x, (1-scale)*y/2终点:0.5x, (1+scale)*y/2"""self.driver.swipe(self.x * 0.5, self.y * (1 - scale) / 2, self.x * 0.5, self.y * (1 + scale) / 2)
6、封装一个综合滑动操作
def swipe(self, direction, scale):"""综合滑动操作:param direction: 滑动方向 'left','right','up','down':param scale: 滑动距离所占比例Usage:swipe(direction = 'left',scale=0.8)"""swipe_direction = {'left': self.swipe_left,'right': self.swipe_right,'up': self.swipe_up,'down': self.swipe_down}# 如果输入的滑动方向不为'left','right','up','down'则抛出异常if direction not in swipe_direction:raise ValueError("Please enter the correct direction!")return swipe_direction[direction](scale)
App自动化测试(五)之swipe滑动操作相关推荐
- APP自动化测试框架搭建(五)--Python+Appium+pytest-html
第一章 APP自动化环境搭建(Mac版) 第二章 APP自动化环境搭建(Windows版) 第三章 adb命令 第四章 元素定位.元素操作 第五章 APP自动化测试框架搭建 Python+Appium ...
- APP自动化测试框架搭建(六)--uiautomator2、web-editor基础操作
第一章 APP自动化环境搭建(Mac版) 第二章 APP自动化环境搭建(Windows版) 第三章 adb命令 第四章 元素定位.元素操作 第五章 APP自动化测试框架搭建 Python+Appium ...
- 使用Outlook Mail App滑动操作快速处理邮件
If you do email on your phone, swipe actions can help you spin through your inbox much quicker. Here ...
- airtest上的滑动操作swipe
正常来说,方法一的滑动是生效的, 但是在页面有蒙层或是其他怪异的情况下,可能就不生效了,再用方法二 方法一: # 获取设备的高度和宽度 width, height = device().get_cur ...
- APP自动化测试-5.触屏操作及toast处理
APP自动化测试-5.触屏操作及toast处理 文章目录 APP自动化测试-5.触屏操作及toast处理 前言 一.TouchAction常用方法 二.toast识别处理 前言 TouchAction ...
- 软件测试 | app自动化测试(Android)--触屏操作自动化
本文节选自霍格沃兹测试开发学社内部教材 获取更多相关资料 工作中经常需要对应用的页面进行一些滑动.长按.拖动等手势操作,而AppiumDriver 提供了一个模拟手势操作的辅助类 TouchActio ...
- 【App自动化测试】(十五)手机浏览器(webview)自动化测试
目录 1. 手机浏览器自动化前提 1.1 安装chromedriver 1.2 安装对chromedriver版本 1.3 配置capability 1.4 设置chromedriver相关配置 1. ...
- 2022软件测试技能 APP自动化测试 Python+Appium+Uiautomator2 实战教程
系列文章目录 提示:阅读本章之前,请先阅读目录 文章目录 系列文章目录 前言 一.Appium 原理 二.环境搭建,一键搞定 1. 安装Java JDK 2. Android SDK 安装与配置 3. ...
- APP自动化测试框架-UiAutomator2基础入门
前言 很早以前,我用uiautomator+java实践过Android APP自动化测试,不过今天要提的不是uiautomator,而是uiautomator2.听起来uiautomator2像是u ...
最新文章
- 16条很有用的Chrome浏览器命令
- 品牌网络推广方案浅析在编写文章标题时都有什么技巧?
- macOS 的头文件隐藏这么深
- 2015华为(北京)架构师创意课程大纲
- 创新实训个人记录 : 个人工作总结
- PaaS case study
- C# 中 NPOI 库读写 Excel 文件的方法【摘】
- python库的学习系列之 13.2. ConfigParser — Configuration file parser
- android 拨打电话 发送短信 权限,Android开发实现拨打电话与发送信息的方法分析...
- 交错数组(jagged array)
- SVM——支持向量回归(SVR)
- 【基金量化研究系列】大类资产配置研究(六)——多资产风险平价策略
- 电视购物直播系统是如何运行的?视频直播流媒体服务器购物直播应用案例
- 各种路由的概念-直连路由、网关路由、主机路由、网络路由等
- WinDbg 定位句柄泄漏问题
- 菜鸟、小白在autojs和冰狐智能辅助之间如何选择?
- 模块1--BH1750的应用(IIC)
- 微服务等于 Spring Cloud?了解微服务架构和框架
- Mac空格键快速预览不能用了怎么办?
- Nodejs 中运行 JS 代码