当前位置:网站首页>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.
边栏推荐
- LeetCode226. Flip binary tree
- 【电子实验2】简单电子门铃
- Rosdep update using fishros to solve ros1/ros2 problems 2022
- 華為雲的AI深潜之旅
- Real time transformer: meituan's research on single image depth estimation
- Lumiprobe lumizol RNA extraction reagent solution
- Google search is dying | DKB
- 视觉弱监督学习研究进展
- 城市大脑知识图谱构建及应用研究
- wrk压力测试工具介绍
猜你喜欢

Lumiprobe lumizol RNA extraction reagent solution
![Sword finger offer:[day 2 linked list (simple)] --- > print the linked list from end to end](/img/d6/824985b74b27a1bee456c2cebbac26.jpg)
Sword finger offer:[day 2 linked list (simple)] --- > print the linked list from end to end

Progress in visual weakly supervised learning

Interface test process

别再问我,UI自动化测试怎么做了……

An artifact extracted from a well-known software and paid by a group of people

Adding a markdown editor to lavel
![[golang] leetcode intermediate subset & Word Search](/img/3a/f63892160c25196335a633424c6d99.jpg)
[golang] leetcode intermediate subset & Word Search

17 `bs object Node name h3 Parent ` parents get parent node ancestor node

Anti rabbit dylight 488 abbkine universal immunofluorescence (if) toolbox
随机推荐
What is an interface? What is interface testing?
LeetCode877. Stone game
Lumiprobe lumizol RNA extraction reagent solution
Rust language survey results in 2021
After easycvr creates a new user, the video access page cannot be clicked. Fix the problem
杆会睡不着觉
LxC shared USB device
Study on bifunctional crosslinker lumiprobe sulfoacyanine 7 dicarboxylic acid
视觉弱监督学习研究进展
Building web automation environment
Anti rabbit dylight 488 abbkine universal immunofluorescence (if) toolbox
城市大脑知识图谱构建及应用研究
16 `bs object Node name Div. attribute contents ` children descendants get child nodes and descendants
PAT 1021. Traversal of the deep root (25 points) graph, DFS, calculating the number of connected components
Is it safe to open a stock trading account? Is it reliable?
Hardware development notes (VII): basic process of hardware development, making a USB to RS232 module (VI): creating 0603 package and associating principle graphic devices
If you are a C developer, look at these three explicit programming techniques
LeetCode117. Populate the next right node pointer for each node_ II
电商秒杀系统架构设计
Understanding web automated testing
