appium-Implement gesture Password login

Source: Internet
Author: User
Tags appium

Objective:

A few days ago, I was asked, how do I sign in? So I found an app to try, so this article to summarize the use of python+appium to implement gesture password login app.

Environment:

macos:10.13.4
appium-desktop:1.6.1
xcode:9.3.1
APP: Public Security Insurance-ios Edition
----

First, Appium API--touchaction

Appium auxiliary classes, mainly for gesture manipulation, such as sliding, long-press, drag and so on.

1. Press the control
Method:press()
Start pressing an element or sitting punctuation (x, y). Press a position on your phone's screen with your finger.
Example:

TouchAction(driver).press(x=0,y=308).release().perform()release() 结束的行动取消屏幕上的指针。Perform() 执行的操作发送到服务器的命令操作。

2, long press the control
Method:longPress()
Start pressing an element or sitting punctuation (x, y). Compared to the press () method, longpress () more than one entry, since the long press, you have to have the time bar. The duration is measured in milliseconds. 1000 means press one second. The usage is the same as the press () method.
Example:

TouchAction(driver).longPress(x=1 ,y=302,duration=1000).perform().release();

3. Mobile
Method:moveTo()
Points the pointer (cursor) from the past to the specified element or point.
Example:

TouchAction(driver).moveTo(x=0,y=308).perform().release();

4. Suspension
Method:wait()
Pauses the execution of the script in milliseconds.
Example:

TouchAction(driver).wait(1000);
Second, by touching multipoint coordinates to unlock

According to the above API explanation, we can draw the pressure and movement to achieve gesture interpretation, the approximate idea is as follows:

TouchAction.press(beginX,beginY).moveTo(xStep,yStep).moveTo(xStep,yStep).release().perform();

Open Appium-inspector to see the coordinates of each point that the gesture corresponds to.
Select [Swipe by coordinates] to see the coordinates of any point. You can select the center position of the gesture touch point. As shown: The author selects 4 points in the upper-left corner to simulate gestures to perform a login operation.
The code is as follows:

# -*- coding: utf-8 -*-# @Time    : 2018/5/22 下午10:33# @Author  : WangJuan# @File    : appium-ios.pyfrom time import sleepfrom appium import webdriverfrom appium.webdriver.common.touch_action import TouchActioncap = {  "platformName": "iOS",  "platformVersion": "11.4",  "bundleId": "com.zhongan.insurance",  "automationName": "XCUITest",  "udid": "3e8325a7c0d*******************a7e",  "deviceName": "****Iphone"}host = "http://0.0.0.0:4728/wd/hub"driver = webdriver.Remote(host, cap)sleep(3)action = TouchAction(driver)action.press(x=98, y=321).wait(100).move_to(x=208, y=321).wait(100).move_to(x=206, y=432).wait(100).move_to(x=98, y=432).perform().release()
Three, compatible with different resolutions

Directly with coordinates point to find there will be some problems, such as mobile phone screen size is different, the location of the point may be biased, how to solve it? The
is visible by first obtaining the coordinates location and size of the first touch point. Defined as start_height, Start_width, start_x, Start_y (where start_x, start_y are the coordinates of the upper-left corner of the touch point);
You can calculate the center point coordinates of the first touch point, respectively:
start_x + start_width/2 , start_y + start_height/2
The approximate coordinates of the center point of the second touch point are then computed:
start_x+start_width*2 , y=start_y+start_height*2
Other coordinates can be calculated in this way, for details see specific examples.

#-*-Coding:utf-8-*-# @Time: 2018/5/22 pm 10:33# @Author: wangjuan# @File: Appium-ios.pyfrom Time Import sleep From Appium import webdriverfrom appium.webdriver.common.touch_action Import touchactioncap = {"PlatformName": "IOS", " Platformversion ":" 11.4 "," Bundleid ":" Com.zhongan.insurance "," Automationname ":" Xcuitest "," Udid ":" 3e8325a7c0***** 62bd4a7e "," DeviceName ":" [email protected] "}host =" Http://0.0.0.0:4728/wd/hub "Driver = webdriver. Remote (host, CAP) sleep (3) action = Touchaction (Driver) # action.press (x=98, y=321). Wait (+). Move_to (x=208, y=321). Wait (+). Move_to (x=206, y=432). Wait (+). Move_to (x=98, y=432). Perform (). Release () start = Driver.find_element_by_ XPath ('//xcuielementtypeapplication[@name = "Public Safety Insurance"]/xcuielementtypewindow[1]/xcuielementtypeother/xcuiel ementtypeother/xcuielementtypeother/xcuielementtypeother/xcuielementtypeother/xcuielementtypeother/ XCUIELEMENTTYPEOTHER[1] ') start_height = start.size[' height ']start_width =start.size[' width ']start_x = start.location[' x ']start_y = start.location[' y ']begin_x = start_x + start_width/2begin_y = Start_y + start_height/2action.press (x=start_x, y=start_y). Wait (+). Move_to (X=start_x+start_width*2, y=begin_y). Wait (+). Move_to (X=start_x+start_width*2, y=start_y+start_height*2). Wait (+). Move_to (X=begin_x,y=start _y+start_height*2). Perform (). Release ()

Above, for your help, please praise it?? ~ ~

appium-Implement gesture Password login

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.