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
  • 相关阅读:
    5分钟造出好记又难猜的密码!
    拯救你的文档 – 【DevOps敏捷开发动手实验】开源文档发布
    VSALM 动手实验
    #VSTS日志# TFS 2015 Update 2 RC2新功能
    用户故事驱动的敏捷开发 – 1. 规划篇
    精益软件开发与精益管理:从一家关闭的汽车厂重焕青春说起
    创建用户故事地图(User Story Mapping)的8个步骤
    用户故事地图(User Story Mapping)之初体验
    (视频) 基于HTML5的服务器远程访问工具
    比较php字符串连接的效率
  • 原文地址:https://www.cnblogs.com/cnblogsadmin/p/8384975.html
Copyright © 2011-2022 走看看