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
  • 相关阅读:
    为什么我会被淘汰?
    2017-3-27日碎碎念
    (原创)我对未来的人类的发展,以及AI技术发展的一些思考。
    八大排序算法图文讲解
    PE病毒初探——向exe注入代码
    [转]Patch文件结构详解
    芝麻信用商家接入指南
    如何成为一名好的程序员的一些个人经验
    .NET CoreCLR开发人员指南(上)
    七牛云:ckeditor JS SDK 结合 C#实现多图片上传。
  • 原文地址:https://www.cnblogs.com/cnblogsadmin/p/8384975.html
Copyright © 2011-2022 走看看