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()

      

     

  • 相关阅读:
    UE4分支的Git Flow
    手机Soc芯片简介
    游戏性能指标
    UE3客户端加入DS过程
    stereoscopic 3D
    UDK脚本函数性能工具
    vs2015启动崩溃,wpfgfx_v0400.dll加载D3DCompiler_47.dll失败
    UDK命令
    三维图形渲染管线
    【SpringCloud】Spring Cloud Sleuth + Zipkin 服务调用链路追踪(二十五)
  • 原文地址:https://www.cnblogs.com/bright-carol/p/14244856.html
Copyright © 2011-2022 走看看