Appium 九宫格 手势解锁
分析九宫格定位
整个九宫格是一个 view
self.driver.find_element_by_id("com.elc:id/gesturepwd_create_lockview")
屏幕大小 x 720, y 1280
九宫格定位 x 80, y 488, width 640 height 1048
计算出大小 x 80 y 488
width = 640-80 width 等于 560
height = 1048-488 height 等于 560
九宫格是正方形
计算出第一个坐标 为了好计算,就把坐标的值全部用整数来计算
p11 = int(x + width / 6), int(y + height / 6)
(173, 581)
计算所有的坐标值
定位方式存在一个字典中
a = {
"解锁提示": "com.elc:id/gesturepwd_create_text",
"九宫格": "com.elc:id/gesturepwd_create_lockview",
"继续": "com.elc:id/right_btn",
}
lock_pattern = self.driver.find_element_by_id(a["九宫格"])
x = lock_pattern.location.get('x')
y = lock_pattern.location.get('y')
width = lock_pattern.size.get('width')
height = lock_pattern.size.get('height')
print(x, y, width, height)
offset = width / 6
p11 = int(x + width / 6), int(y + height / 6)
p12 = int(x + width / 2), int(y + height / 6)
p13 = int(x + width - offset), int(y + height / 6)
p21 = int(x + width / 6), int(y + height / 2)
p22 = int(x + width / 2), int(y + height / 2)
p23 = int(x + width - offset), int(y + height / 2)
p31 = int(x + width / 6), int(y + height - offset)
p32 = int(x + width / 2), int(y + height - offset)
p33 = int(x + width - offset), int(y + height - offset)
print(p11, p12, p13)
print(p21, p22, p23)
print(p31, p32, p33)
80 488 560 560 # 九宫格坐标值 与上面计算的一样
(173, 581) (360, 581) (546, 581)
(173, 768) (360, 768) (546, 768)
(173, 954) (360, 954) (546, 954)
计算滑动偏移量(做的效果图是 7)
p3 = p13[0] - p11[0] # 偏移的值是 373
滑动方法 TouchAction
TouchAction(self.driver).press(x=p11[0], y=p11[1]).move_to(x=p3, y=0).wait(1000).move_to(x=0, y=p3).wait(
1000).release().perform()
说明 滑动方法
# 横向滑动
从 173 滑动到 546 坐标的偏移量是 546-173 = 373
第一个值不变 press(x=p11[0], y=p11[1]).move_to(x=373, y =0),因为y 的值是相同的,就不变
# 纵向滑动
move_to(x=0, y=373) 因为x的值不变,移动y 的值
九宫格是正方的形,所以 从第1点到3点是 373, 从3点到9点也是 373
九宫格解锁完毕
这样的写法,不需要固定坐标值,根据不同的设备屏幕大小自动获取到--偏移值
我遇到的坑-- 之前一直以为 TouchAction 的 move_to 是从x y 坐标移动到另一个坐标,而不是偏移量,没有理解清楚,所以这里掉坑里了
最后附上完整的函数
def login_unlock(self):
a = {
"解锁提示": "com.elc:id/gesturepwd_create_text",
"九宫格": "com.elc:id/gesturepwd_create_lockview",
"继续": "com.elc:id/right_btn",
}
unlock_text = self.driver.find_element_by_id(a["解锁提示"])
lock_pattern = self.driver.find_element_by_id(a["九宫格"])
x = lock_pattern.location.get('x')
y = lock_pattern.location.get('y')
width = lock_pattern.size.get('width')
height = lock_pattern.size.get('height')
print(unlock_text.text)
print(x, y, width, height)
offset = width / 6
p11 = int(x + width / 6), int(y + height / 6)
p12 = int(x + width / 2), int(y + height / 6)
p13 = int(x + width - offset), int(y + height / 6)
p21 = int(x + width / 6), int(y + height / 2)
p22 = int(x + width / 2), int(y + height / 2)
p23 = int(x + width - offset), int(y + height / 2)
p31 = int(x + width / 6), int(y + height - offset)
p32 = int(x + width / 2), int(y + height - offset)
p33 = int(x + width - offset), int(y + height - offset)
p3 = p13[0] - p11[0]
sleep(3)
TouchAction(self.driver).press(x=p11[0], y=p11[1]).move_to(x=p3, y=0).wait(1000).move_to(x=0, y=p3).wait(
1000).release().perform()
效果视频
Vimeo
https://v.youku.com/v_show/id_XMjk4NjY0MjQwMA==.html?spm=a2hzp.8244740.0.0
Appium 九宫格 手势解锁的更多相关文章
- Appium九宫格滑动解锁
1.适配各种机型,首先获取整个解锁元素的坐标 2.代码实现 WebElement lockPattern = driver.findElement(By.id("com.android.se ...
- appium 九宫格解锁招商银行手机客户端app
之前研究了一段时间的appium for native app 相应的总结如下: appium测试环境搭建 :ht ...
- iOS-高仿支付宝手势解锁(九宫格)
概述 高仿支付宝手势解锁, 通过手势枚举去实现手势密码相对应操作. 详细 代码下载:http://www.demodashi.com/demo/10706.html 基上篇[TouchID 指纹解锁] ...
- [iOS UI进阶 - 5.0] 手势解锁Demo
A.需求 1.九宫格手势解锁 2.使用了绘图和手势事件 code source: https://github.com/hellovoidworld/GestureUnlockDemo B ...
- 【Android - 自定义View】之自定义九宫格手势解锁控件
首先来介绍一下这个自定义View: (1)这个自定义View的名称叫做 LockView ,继承自View类: (2)这个自定义View实现了应用中常见的九宫格手势解锁功能,可以用于保证应用安全: ( ...
- Swift 简简单单实现手机九宫格手势密码解锁
原文:Swift 简简单单实现手机九宫格手势密码解锁 大家可以看到我之前的文章[HTML5 Canvas简简单单实现手机九宫格手势密码解锁] 本文是使用苹果语言对其进行了移植 颜色配色是拾取的支付宝的 ...
- HTML5 Canvas简简单单实现手机九宫格手势密码解锁
原文:HTML5 Canvas简简单单实现手机九宫格手势密码解锁 早上花了一个半小时写了一个基于HTML Canvas的手势解锁,主要是为了好玩,可能以后会用到. 思路:根据配置计算出九个点的位置,存 ...
- iOS--开发之手势解锁
本文主要介绍通过手势识别实现手势解锁功能,这个方法被广泛用于手机解锁,密码验证,快捷支付等功能实现.事例效果如下所示. 首先,我们先分析功能的实现过程,首先我们需要先看大致的实现过程: 1.加载九宫格 ...
- APP九宫格滑动解锁的处理
写手机自动化测试脚本关于APP九宫格滑动解锁方面采用了appium API 之 TouchAction 操作. 先是用uiautomatorviewer.bat查询APP元素坐标: 手工计算九宫格每个 ...
随机推荐
- python练习 之 实践出真知 中心扩展法求最大回文子串 (leetcode题目)
1 问题,给定一个字符串,求字符串中包含的最大回文子串,要求O复杂度小于n的平方. 首先需要解决奇数偶数的问题,办法是:插入’#‘,aba变成#a#b#a#,变成奇数个,aa变成#a#a#,变成奇数个 ...
- Houdini OpenCL
SOP: simple moveKernel #include "interpolate.h" float lerpConstant( constant float * in, i ...
- 【转】python 历险记(四)— python 中常用的 json 操作
[转]python 历险记(四)— python 中常用的 json 操作 目录 引言 基础知识 什么是 JSON? JSON 的语法 JSON 对象有哪些特点? JSON 数组有哪些特点? 什么是编 ...
- 【转】Vim速查表-帮你提高N倍效率
Vim速查表-帮你提高N倍效率 转自:https://www.jianshu.com/p/6aa2e0e39f99 去年上半年开始全面使用linux进行开发和娱乐了,现在已经回不去windows了. ...
- FAT文件系统规范v1.03学习笔记---1.保留区之 Fat32 FSInfo扇区结构和备份启动扇区
1.前言 本文主要是对Microsoft Extensible Firmware Initiative FAT32 File System Specification中文翻译版的学习笔记. 每个FAT ...
- React的Element的创建和render
React的Element是React应用程序的最小构建块,它是用来描述我们在屏幕上看到的浏览器页面上的内容. 在React中构建 Element 有两种方式: 1.JSX的方式,JSX不是React ...
- python的wrapt模块实现装饰器
wrapt是一个功能非常完善的包,用于实现各种你想到或者你没想到的装饰器.使用wrapt实现的装饰器你不需要担心之前inspect中遇到的所有问题,因为它都帮你处理了,甚至inspect.getsou ...
- C++类的继承中构造函数和析构函数调用顺序例子
/*当建立一个对象时,首先调用基类的构造函数,然后调用下一个派生类的构造函数,依次类推,直至到达派生类次数最多的派生次数最多的类的构造函数为止.简而言之,对象是由“底层向上”开始构造的.因为,构造函数 ...
- jQuery.extend()参数
非原创,转载仅供学习 在处理插件参数的接收上,通常使用jQuery的extend方法.extend方法传递单个对象的情况下,这个对象会合并到jQuery身上,而当用extend方法传递一个以上的参数时 ...
- Struts2框架下的文件上传文件类型、名称约定
Struts2框架下的文件上传机制:1.通过multipart/form-data form提交文件到服务器2.文件名是通过什么地方设置的?在strust2的FileUploadInterceptor ...