zoukankan      html  css  js  c++  java
  • 4.Appium模拟手势点击坐标函数tap

    tap

        def tap(self: T, positions: List[Tuple[int, int]], duration: Optional[int] = None) -> T:
            """Taps on an particular place with up to five fingers, holding for a
            certain time
    
            Args:
                positions: an array of tuples representing the x/y coordinates of
                    the fingers to tap. Length can be up to five.
                duration: length of time to tap, in ms
    
            Usage:
                driver.tap([(100, 20), (100, 60), (100, 100)], 500)
    
            Returns:
                Union['WebDriver', 'ActionHelpers']: Self instance
            """
    

    tap用法

    1、tap是模拟手指点击,一般页面上元素的语法有两个参数,第一个是positions,是list类型,list里面套tuple,duration是持续时间,单位毫秒

    2、tap方法的弊端也是不同手机屏幕的分辨率不一样导致定位不准确

    下面是点击boss直聘的一个按钮案例:

    #导包
    from appium import webdriver
    import time
    #准备自动化配置信息
    desired_caps={
        #移动设备平台
        'platformName':'Android',
        #平台OS版本号,写整数位即可
        'plathformVersion':'6',
        #设备的名称--值可以随便写
        'deviceName':'test0106',
        #提供被测app的信息-包名,入口信息:
        #1.打开被测app,2.命令行输入以下信息
        #adb shell dumpsys activity recents | findstr intent={
        'appPackage':'com.hpbr.bosszhipin',
        'appActivity':'.module.launcher.WelcomeActivity',
        #确保自动化之后不重置app
        'noReset':True,
        #设置session的超时时间,单位秒,默认60s
        'newCommandTimeout':6000,
        #设置底层测试驱动-1.15默认使用的底层驱动就是UiAutomator2
        'automationName':'UiAutomator1',#或者UiAutomator1
        #'skipServerInstallation':True#跳过UI2的安装,如果第一次运行程序,不要添加该配置
    }
    boss_caps = desired_caps
    #当驱动为ui1,输入中文需要指定输入法
    boss_caps['unicodeKeyboard']=True#修改手机的输入法,UI2不需要设置
    boss_caps['resetKeyboard']=True
    
    
    #初始化driver对象-用于控制手机-启动被测应用
    #IP-appium-server所在机器的网络ip,port-监听的端口号,path固定/wd/hub
    driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
    driver.implicitly_wait(10)#稳定元素
    #我的按钮
    driver.find_element_by_id("com.hpbr.bosszhipin:id/iv_tab_4").click()
    #driver.find_element_by_xpath('//*[@resource-id="com.hpbr.bosszhipin:id/cl_tab_4"]/*[1]').click()
    #设置
    #//*[@resource-id="com.hpbr.bosszhipin:id/rl_title"]/android.view.ViewGroup[1]
    
    driver.tap([(616,65)])
    
  • 相关阅读:
    年度开源盛会 ApacheCon 来临,Apache Pulsar 专场大咖齐聚
    开源流数据公司 StreamNative 正式加入 CNCF,积极推动云原生策略发展
    php摇杆Tiger摇奖
    php调试局部错误强制输出 display_errors
    php文件写入PHP_EOL与FILE_APPEND
    window自动任务实现数据库定时备份
    php 跨服务器ftp移动文件
    linux 关于session缓存丢失,自己掉坑里面了
    mysql 定时任务
    mysql 查询去重 distinct
  • 原文地址:https://www.cnblogs.com/venvive/p/13383040.html
Copyright © 2011-2022 走看看