zoukankan      html  css  js  c++  java
  • 浏览器测试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()

      

     

  • 相关阅读:
    ubuntu 14.4 apache2 django
    github上的版本和本地版本冲突的解决方法
    Javascript能做什么 不能做什么。
    django 取model字段的verbose_name值
    Django在admin模块中显示auto_now_add=True或auto_now=True的时间类型列
    合并多个python list以及合并多个 django QuerySet 的方法
    摘抄
    Python 字符串拼接
    学习HTTP
    Django 自定义模板标签和过滤器
  • 原文地址:https://www.cnblogs.com/bright-carol/p/14244856.html
Copyright © 2011-2022 走看看