• 浏览器测试app-H5页面使用appium实现自动化


    测试环境准备

    1.PC端安装chrome,手机端安装谷歌浏览器(部分品牌应用商店可能会没有,可以安装应用宝,再到应用宝上安装google浏览器,或者PC端应用宝内下载。不太清楚这个有什么用途,我不按安装也是可以运行的。)

    2.打开手机的webview调试模式

    3.浏览器输入 chrome://inspect/devices#devices,可以看到当前webview页面,如果获取不到可以刷新下,或者调试模式未打开

     

    配置:预期功能 Desired Capabilities

    {
      "platformName": "Android",
      "platformVersion": "10",
      "deviceName": "红米note7",
      "udid": "xxxxx",
      "clearSystemFiles": true,
      "newCommandTimeout": "360",
      "automationName": "uiautomator2",
      "resetKeyboard": true,
      "unicodeKeyboard": true,
      "skipServerInstallation": false,
      "skipDeviceInitialization": false,
      "noReset": true,
      "browserName": "Chrome",
      "unlockType": "pattern",
      "unlockKey": ""
    }

     

    import time
    from appium import webdriver
    from appium.webdriver.mobilecommand import MobileCommand

    desired_caps_a = {'platformName': "Android", 'platFormVersion': "10", 'deviceName': "红米note7", 'udid': "xxxxxx", 'automationName': "UiAutomator2", 'noReset': True, 'unicodeKeyboard': True, 'resetKeyboard': True, 'skipServerInstallation': True, 'skipDeviceInitialization': True, 'newCommandTimeout': '360', 'browserName': 'Chrome' } device_a = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps_a) time.sleep(2) # 测试获取H5元素 device_a.get("http://url") # 要浏览器访问的url地址 print(device_a.contexts) # 打印出来的是['NATIVE_APP', 'CHROMIUM'] device_a.implicitly_wait(30) device_a.switch_to.context('CHROMIUM') # H5元素操作,切换到H5页面定位操作 device_a.find_element_by_xpath(".//div[text()='请假']").click() device_a.find_element_by_xpath(".//div[text()='假别']").click() device_a.switch_to.context('NATIVE_APP') # android原生控件操作,切换回app操作 device_a.get_window_size() device_a.swipe(int(0.5*1080), int(0.95*2217), int(0.5*1080), int(0.93*2217), 1000) device_a.find_element_by_xpath(".//android.view.View[@text='确定']").click()

      

     

  • 相关阅读:
    读胶料温度代码
    干掉win10自带的不给力的应用(转自https://jingyan.baidu.com/article/08b6a591b7398514a8092238.html)
    安装SQL提示重启电脑失败,解决办法
    几种加解密方法:AES、DES、SHA数据加密
    SQL数据库添加新账号,只操作指定数据库
    jQuery中attr()、prop()、data()用法及区别
    jquery.cookie() 的使用(原)
    功能强大的web打印控件lodop的使用
    Win+R命令大全
    Vue
  • 原文地址:https://www.cnblogs.com/bright-carol/p/14244856.html
Copyright © 2020-2023  润新知