zoukankan      html  css  js  c++  java
  • Appium + python

    方法一:

    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"])

    #屏幕的高度 height
    print(size["height"])

    def swipeUp(driver,t=500,n=1):
    """向上屏幕滑动"""
    x1 = size["width"] * 0.5 # x坐标
    y1 = size["height"] * 0.75 # 起点 y坐标
    y2 = size["height"] * 0.25 # 终点 y 坐标
    for i in range(n):
    driver.swipe(x1,y1,x1,y2,t)

    def swipeDown(driver,t=500,n=1):
    """向下屏幕滑动"""
    x1 = size["width"] * 0.5 # x1 坐标
    y1 = size["height"] * 0.25 # 起点y1坐标
    y2 = size["height"] * 0.75 # 终点y2坐标
    for i in range(n):
    driver.swipe(x1,y1,x1,y2,t)

    def swipeLeft(driver,t=500,n=1):
    """向左屏幕滑动"""
    x1 = size["width"] * 0.75 # 起点x1坐标
    y1 = size["height"] * 0.5 # y1 坐标
    x2 = size["width"] * 0.25 # 终点x2坐标
    for i in range(n):
    driver.swipe(x1,y1,x2,y1,t)

    def swipeRight(driver,t=500,n=1):
    """向右屏幕滑动"""
    x1 = size["width"] * 0.25 #起点x1坐标
    y1 = size["height"] * 0.5 # y1坐标
    x2 = size["width"] * 0.75 #终点x2坐标
    for i in range(n):
    driver.swipe(x1,y1,x2,y1,t)

    if __name__ == "__main__":
    print(driver.get_window_size())
    sleep(5)
    swipeLeft(driver, n=2)
    sleep(2)
    swipeRight(driver, n=2)
    driver.quit()

    方法二:
    #!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,self.height/2,0)

    @property
    def set_Right_Left(self):
    '''
    :return:实现从右到左滑动,滑动时X轴起点小于终点
    '''
    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: 实现从上往下滑动,滑动时Y轴起点起点大于终点
    '''
    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: 实现从下往上滑动,滑动时Y轴起点小于终点
    '''
    t.sleep(2)
    self.driver.swipe(self.width/2,self.height/20,self.width/2,self.height*9/10,0)


  • 相关阅读:
    yarn的学习之1-架构
    HDFS的存储策略
    搭建简单的hadoop集群(译文)
    构建高可靠hadoop集群之5-服务级别授权
    构建高可靠hadoop集群之4-保全模式
    构建高可靠hadoop集群之4-权限指引
    构建高可靠hadoop集群之3- Quorum Journal Manager
    构建高可靠hadoop集群之0-hadoop用户向导
    构建高可靠hadoop集群之2-机栈
    构建高可靠hadoop集群之1-理解hdfs架构
  • 原文地址:https://www.cnblogs.com/Teachertao/p/10990958.html
Copyright © 2011-2022 走看看