首页 > 移动平台 > 详细

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

时间:2021-01-07 10:52:02      阅读:37      评论:0      收藏:0      [点我收藏+]

测试环境准备

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

  

 

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

原文:https://www.cnblogs.com/bright-carol/p/14244856.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!