About appium automation swipe analog slide operation

swipe can simulate, sliding up and down function when we usually play phone, first look swepi received parameters,

start_x, start_y, end_x, end_y, duration=None

swipe five parameters may be received, of which four are required, one optional. 4 required parameters are: X-axis start, beginning Y-axis, the end of the X-axis, Y-axis end. Duration parameter is optional, i.e. the slip speed, the faster the smaller the value, the slip speed, the greater the value of sliding

The slower speed. Usually fill duration 500, sliding effect can be seen.

See Source parameter:

and a duration smaller the value function can be modeled as click buttons. Different for each phone resolution, so the screen size is different, you can use size = driver.get_window_size (), to get the size of the screen. Then print out the screen size

Print out a dictionary as:

Then each get their value, width = size [ "width"], height = size [ "height"]

Up from the slide, it is larger than the end of the initial coordinate y1 y2, the greater the gap, the greater the sliding distance,

 , From sliding down the larger, less than the starting end coordinates y1 y2, the greater the gap between the sliding distance,

Sliding from left to right, starting global coordinate x1 x2 than the end, the larger the gap, the greater the sliding distance

Sliding from right to left, the end of the initial coordinate x1 is smaller than x2, the greater the gap, the greater the sliding distance


Then were assigned

x1 = width*0.2

y1 = height*0.9

x2 = width*0.2

y2 = height*0.1

demo is as follows:

# todo 滑动模拟
from appium import webdriver
import time

desired_caps = {
    "platformName":"Android",
    "platformVersion":"5.1",
    "deviceName":"127.0.0.1:62001",
    "appPackage":"com.android.settings",
    "appActivity":".Settings " ,
     " NORESET " : " True " 
               } 

# declared objects driver 
driver webdriver.Remote = ( ' http://127.0.0.1:4723/wd/hub ' , desired_caps) 
size = driver.get_window_size ()
 Print (size ) 
width = size [ " width " ] 
height = size [ " height " ]
 Print (width, height) 

# TODO slide up from the bottom, the end of the initial coordinate y1 is greater than y2, the greater the gap, the greater the sliding distance, 
# TODO slides from the starting end smaller than the coordinate y1 y2, the greater the gap, the greater the sliding distance
# TODO sliding from left to right, starting end coordinates x1 is greater than x2, the greater the gap, the greater the distance of the sliding 
# the TODO slide from right to left, the end of the initial coordinate x1 is smaller than x2, the greater the gap, the greater the sliding distance 


X1 = width * 0.2 
Y1 = 0.9 * height 
X2 = width * 0.2 
Y2 = 0.1 * height 

driver.swipe (X1, Y1, X2, Y2, 500 ) 
the time.sleep ( 10 ) 
driver.quit ()

 

Guess you like

Origin www.cnblogs.com/xiamaojjie/p/11421089.html