zoukankan      html  css  js  c++  java
  • appium滑动操作(向上、向下、向左、向右)

    appium滑动操作(向上滑动、向下滑动、向左滑动、向右滑动)

    测试app:今日头条apk

    测试设备:夜游神模拟器

    代码如下:

    先用x、y获取当前的width和height

    def getSize():                               #获取当前的width和height的x、y的值
        x = driver.get_window_size()['width']   #width为x坐标
        y = driver.get_window_size()['height']  #height为y坐标
        return (x, y)
    View Code

    屏幕向上滑动

    def swipeUp(t):  #当前向上滑动swipeup
        l = getSize()
        x1 = int(l[0] * 0.5)  
        y1 = int(l[1] * 0.75)   
        y2 = int(l[1] * 0.25)   
        driver.swipe(x1, y1, x1, y2,500)  #设置时间为500
    swipeUp(9000)     #向上滑动9000
    View Code

    屏幕向左滑动

    def swipLeft(t):      #当前向左进行滑动swipleft
        l=getSize()
        x1=int(l[0]*0.75)
        y1=int(l[1]*0.5)
        x2=int(l[0]*0.05)
        driver.swipe(x1,y1,x2,y1,500)
    swipLeft(3000)        #向左滑行3000
    View Code

    屏幕向右滑动

    def swipRight(t): #向右滑行swipright
        l=getSize()
        x1=int(l[0]*0.05)
        y1=int(l[1]*0.5)
        x2=int(l[0]*0.75)
        driver.swipe(x1,y1,x2,y1,500)
    swipRight(3000)    #向右滑行3000,回到初始位置
    View Code

    屏幕向下滑动

    def swipeDown(t):    #向下滑动swipedown
        l = getSize()
        x1 = int(l[0] * 0.5)
        y1 = int(l[1] * 0.25)
        y2 = int(l[1] * 0.75)
        driver.swipe(x1, y1, x1, y2,500)
    swipeDown(10000)   #向下滑动10000
    View Code

    测试今日头条向上、向下、向左、向右滑动操作完整代码

    #coding=utf-8
    from appium import webdriver
    import time
    desired_caps={
        'platformName':'Android',
        'deviceName':'127.0.0.1:62001',    #模拟器名称
        'platformVersion':'4.4.2',         #安卓版本
        'appPackage':'com.ss.android.article.news',      #当前apk的包名
        'appActivity':'com.ss.android.article.news.activity.SplashBadgeActivity'  #当前apk的appActivity
    }
    driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
    time.sleep(10)
    
    
    def getSize():                               #获取当前的width和height的x、y的值
        x = driver.get_window_size()['width']   #width为x坐标
        y = driver.get_window_size()['height']  #height为y坐标
        return (x, y)
    
    def swipeUp(t):  #当前向上滑动swipeup
        l = getSize()
        x1 = int(l[0] * 0.5)  
        y1 = int(l[1] * 0.75)   
        y2 = int(l[1] * 0.25)   
        driver.swipe(x1, y1, x1, y2,500)  #设置时间为500
    swipeUp(9000)     #向上滑动9000
    
    def swipLeft(t):      #当前向左进行滑动swipleft
        l=getSize()
        x1=int(l[0]*0.75)
        y1=int(l[1]*0.5)
        x2=int(l[0]*0.05)
        driver.swipe(x1,y1,x2,y1,500)
    swipLeft(3000)        #向左滑行3000
    
    def swipeDown(t):    #向下滑动swipedown
        l = getSize()
        x1 = int(l[0] * 0.5)
        y1 = int(l[1] * 0.25)
        y2 = int(l[1] * 0.75)
        driver.swipe(x1, y1, x1, y2,500)
    swipeDown(10000)   #向下滑动10000
    
    def swipRight(t): #向右滑行swipright
        l=getSize()
        x1=int(l[0]*0.05)
        y1=int(l[1]*0.5)
        x2=int(l[0]*0.75)
        driver.swipe(x1,y1,x2,y1,500)
    swipRight(3000)    #向右滑行3000,回到初始位置
    time.sleep(20)      
    driver.quit()       #退出当前的app
  • 相关阅读:
    vue中局部过滤器的使用
    elementui中switch开关的回调的使用
    css居中的一些方法
    elementui默认样式修改的几种方法
    git查看远程分支,并且切换到远程的分支
    elementui form resetFields方法 无法重置表单
    vue组件使用vuex中的方法报错,报unknown mutation type的错误
    offSet和client和scroll
    842. Split Array into Fibonacci Sequence能否把数列返回成斐波那契数列
    662. Maximum Width of Binary Tree二叉树的最大宽度
  • 原文地址:https://www.cnblogs.com/cnblogsadmin/p/8384975.html
Copyright © 2011-2022 走看看