Appium + python - screen sliding operation example of swipe

method one:

from appium import webdriver
from time import sleep

descred_caps = {
"platformName":"Android",
"platformVersion":"5.1.1",
"deviceName":"127.0.0.1:62001",
"appPackage":"com.baidu.yuedu",
"appActivity":"com.baidu.yuedu.splash.SplashActivity",
"noRset":"true",
"unicodeKeyboard":"true",
"resetKeyboard":"true"
}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",descred_caps)

#获取屏幕size
size = driver.get_window_size()
print(size)

#屏幕的宽度 width
print(size[""]) width " "" upward swipe "" "DEF swipeUp (Driver, T = 500, n-=. 1):Print (size [" height "])

height height # screen




x1 = size [ "width"] * 0.5 # x -coordinate
y1 = size [ "height"] * 0.75 # starting y-coordinate
y2 = size [ "height"] * 0.25 # end y coordinate
for I in Range (n-):
Driver .swipe (X1, Y1, X1, Y2, T)

DEF swipeDown (Driver, T = 500, n-=. 1):
"" "downward swipe" ""
X1 = size [ "width"] coordinates X1 * 0.5 #
y1 = size [ "height"] * 0.25 # starting coordinate y1
y2 = size [ "height"] * 0.75 # y2 of the end point
for I in Range (n-):
driver.swipe (X1, y1, X1, y2, T)

swipeLeft DEF (Driver, T = 500, n-=. 1):
"" "left swipe" ""
x1 size = [ "width"] * 0.75 # starting coordinates x1
y1 = size [ "height"] * 0.5 # y1 coordinate
x2 = size [ "width"] * 0.25 # x2 coordinate of the end point
for I in Range (n-):
driver.swipe (X1, Y1, x2, Y1, T)

swipeRight DEF (Driver, T = 500, n-=. 1):
"" "right swipe" ""
x1 size = [ "width"] * 0.25 # starting coordinates x1
y1 = size [ "height"] * 0.5 # y1 coordinate
x2 = size [ "width"] * 0.75 # x2 coordinate of the end point
for I in Range (n-):
driver.swipe (X1, Y1, x2, Y1, T)

IF the __name__ == "__main__":
Print (driver.get_window_size ())
SLEEP (. 5)
swipeLeft (Driver, = n-2)
SLEEP (2)
swipeRight (Driver, = n-2)
driver.quit ()

method II:
#!usr/bin/env python
#!coding:utf-8

from appium import webdriver
import time as t


class Swipe(object):
def __init__(self,driver):
self.driver=driver

@property
def width(self):
return self.driver.get_window_size()['width']

@property
def height(self):
return self.driver.get_window_size()['height']

@property
def getResolution(self):
return str(self.width)+"*"+str(self.height)

@property
def set_Left_Right(self):
'''
:return: 实现从左到右滑动,滑动时X轴起点大于终点
'''
t.sleep(2)
self.driver.swipe (self.width *. 9/10, self.height / 2, self.width / 20 is, self.height / 2,0)

@Property
DEF set_Right_Left (Self):
'' '
: return: realized from slide right to left, the slide is smaller than the end of the X-axis origin
'' '
t.sleep (2)
self.driver.swipe (self.width / 10, self.height / 2, self.width *. 9/10, self.height / 2,0)

@Property
DEF set_Up_Down (Self):
'' '
: return: realized from the slide down, the slide end is greater than the Y-axis origin origin
' ''
t.sleep (2)
self.driver.swipe (Self .width / 2, self.height *. 9/10, self.width / 2, self.height / 20,0)

@Property
DEF set_Down_Up (Self):
'' '
: return: realized slide up from the bottom, slides Y-axis is smaller than the starting end
'' '
t.sleep(2)
self.driver.swipe(self.width/2,self.height/20,self.width/2,self.height*9/10,0)


Guess you like

Origin www.cnblogs.com/Teachertao/p/10990958.html