当前位置:网站首页>Appium automated test Jiugongge unlock
Appium automated test Jiugongge unlock
2022-06-28 22:09:00 【The way of testing】
background
We are operating APP Inside the password unlocking, there is a nine palace sliding unlocking , At this time, we need to manually slide continuously , aforementioned swipe、scroll、drag_and_drop These do not allow unlocking , We need to learn to use Advanced gesture operation .
Advanced gestures
Advanced gestures TouchAction It can realize some operations for gestures , Like sliding 、 Long press 、 Drag, etc . We can combine these basic gestures into a relatively complex gesture .
Want to use TouchAction, You have to create TouchAction object , Call the gesture you want to execute through the object , adopt perform() Executive action .
Using gestures , Import required TouchAction package from appium.webdriver.common.touch_action import TouchAction
Tap (tap)
Simulate a finger pressing on an element or coordinate and quickly lifting it . For example, click on (200, 200) The location of .
Method :
TouchAction(driver).tap(element=None, x=None, y=None)
Parameters can be elements , It can also be x,y coordinate .
Short press (press)
The analog finger keeps pressing .
Method :
TouchAction(driver).press(el=None, x=None, y=None)
Parameters can be elements , It can also be x,y coordinate .
Long press (long_press)
Simulate a long press of a finger for a few seconds .
Method :
TouchAction(driver).long_press(el=None, x=None, y=None,duration: int = 1000)
Parameters can be elements , It can also be x,y coordinate , Default long press 1 second , Unit millisecond
wait for (wait)
Simulate finger waiting , For example, press and wait 5 Then lift it in seconds .
Method :
TouchAction(driver).wait(ms=0)
The parameter is the number of milliseconds to pause .
Move to (moveTo)
Simulate finger movement operation , such as , To unlock the gesture, you need to press , Move again .
Method :
TouchAction(driver).move_to(el=None, x=None, y=None)
Parameters can be elements , It can also be x,y coordinate .
Release (release)
Simulate finger lifting
Method :
TouchAction(driver).release()
Simulate the lifting operation of fingers on elements or coordinates .
perform (perform)
Perform gesture operation , It is equivalent to sending gesture operation commands to the mobile phone for execution
Method :
TouchAction(driver).perform()
Nine palace grid unlock
Now most of the nine palaces are a whole element , Therefore, it is impossible to operate through the element coordinates of each point , You can only get the element coordinate position first , Then get the element size , Then cut the picture , Calculate the coordinates of each point separately
The figure below

Implementation code
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.appiumby import AppiumBy
from appium import webdriver
import time
desc = {
"platformName": "Android",
"platformVersion": "7.1.2",
"deviceName": "127.0.0.1:62001",
"appPackage": "com.android.settings",
"appActivity": "com.android.settings.ChooseLockPattern",
"noReset": True,
"unicodeKeyboard": True,
"resetKeyboard": True
}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desc)
driver.implicitly_wait(5)
# Get the starting coordinates - The top left vertex of the nine palaces grid
loc = driver.find_element(AppiumBy.ID, "com.android.settings:id/lockPattern").location
# Get the element size of Jiugong grid
loc_size = driver.find_element(AppiumBy.ID, "com.android.settings:id/lockPattern").size
# Get the mean value after segmentation , That is, the step size of the nine squares to be used below
step = loc_size["width"] / 6
step_x = loc_size["width"] / 6
step_y = loc_size["height"] / 6
# Calculate the coordinates of each point
point1 = (loc["x"] + step, loc["y"] + step)
point2 = (point1[0] + step * 2, point1[1])
point3 = (point2[0], point2[1] + step * 2)
point4 = (point3[0] + step * 2, point3[1])
# Carry out sliding operation
TouchAction(driver).press(x=point1[0], y=point1[1]).wait(500). \
move_to(x=point2[0], y=point2[1]). \
move_to(x=point3[0], y=point3[1]). \
move_to(x=point4[0], y=point4[1]). \
release().perform()
time.sleep(10)
driver.quit()
explain
When calculating the coordinates of each point , Why 6 Equal division , We can roughly draw a line and estimate it , Or find UI Design drawings can be calculated 
The above content is purely personal understanding , If there is any deficiency , Welcome to correct !
If you think the article is good , Welcome to WeChat official account. , The official account of WeChat is regularly pushing the relevant test technology articles.
边栏推荐
- Sword finger offer:[day 2 linked list (simple)] --- > reverse linked list
- Constructing the three-dimensional anti penetration of the actual combat defense system
- 电商秒杀系统架构设计
- User network model and QoE
- LeetCode1114. 按序打印
- Openfire user and group relationship migration
- [width first search note] BFS output shortest path
- 加刚干的前提
- CORBA Architecture Guide (Common Object Request Broker Architecture)
- 16 `bs object Node name Div. attribute contents ` children descendants get child nodes and descendants
猜你喜欢

Progress in visual weakly supervised learning

Lumiprobe proteorange protein gel dye instructions

Interface test process

华为云的AI深潜之旅

Webrtc audio and video development - experience

Recommend two high-quality Wallpaper software

How to analyze the relationship between enterprise digital transformation and data asset management?

17 `bs对象.节点名h3.parent` parents 获取父节点 祖先节点
![[width first search note] BFS output shortest path](/img/b5/553ca241ae571daecabd282f33f20a.jpg)
[width first search note] BFS output shortest path

10、标准I/O输入输出重定向及管道
随机推荐
犹豫的根音
Study on bifunctional crosslinker lumiprobe sulfoacyanine 7 dicarboxylic acid
LeetCode213. 打家劫舍II
Biovendor free light chain( κ and λ) Test steps of ELISA Kit
Hardware development notes (VII): basic process of hardware development, making a USB to RS232 module (VI): creating 0603 package and associating principle graphic devices
Leetcode56. consolidation interval
Is the VIP securities account of qiniu school really safe and regular? How do I say this?
User network model and QoE
Constructing the three-dimensional anti penetration of the actual combat defense system
Ctrip will push the "3+2" working mode: 3 days a week on duty and 2 days of free choice of office space. Do you envy it?
Hashicorp/raft introduction and source code analysis (III): introduction to cluster node recovery
YAYA LIVE CTO 唐鸿斌:真正本地化,要让产品没有「产地」属性
关于杠杆的思考
LeetCode188. The best time to buy and sell stocks IV
LeetCode1114. Print in sequence
17 `bs object Node name h3 Parent ` parents get parent node ancestor node
QStringLiteral(str)
Lua源码剖析:一. lua变量类型可变特性在C代码中实现。
Pat 1024 palindromic number (25 points) sum of large integers
LeetCode986. Intersection of interval lists
