appium app自动化测试---移动端web网页测试

两种方案:

1.通过selenium测试移动端web网页

   (1)需要添加配置项,让浏览器识别到我是通过移动端来访问的,区别是UA的不同

   (2)其他方面跟selenium测试PC端浏览器网页没有区别

from selenium import webdriver

# 添加配置项,让浏览器的UA信息为手机端信息
chromeOption = webdriver.ChromeOptions()
chromeOption.add_experimental_option("mobileEmulation", {"deviceName": "iPhone X"})

# 实例化Chrome驱动对象,参加添加配置项
driver = webdriver.Chrome(r"chromedriver.exe",
                          desired_capabilities=chromeOption.to_capabilities())

# 访问百度首页
driver.get("https://www.baidu.com/")

2.通过appium测试移动端web网页

  (1) 配置信息需要添加:

       'browserName': 'Chrome'
       "chromedriverExecutableDir":浏览器驱动路径

(2)配置信息移除app相关信息

(3)其他无差异

from appium import webdriver

desired_caps = {
    # 平台
    "platformName": "Android",
    "platformVersion": "8",
    "deviceName": "293696c77d22",
    # 被测app的信息
    'browserName': 'Chrome',
    # 浏览器对应驱动路径
    "chromedriverExecutableDir": "D:\personal\project\selenium\chromedriver_74",
    # 设置命令超时时间
    'newCommandTimeout': 6000,
    # 确保自动化之后不重置app
    'noReset': True,
    # 底层驱动
    'automationName': 'UiAutomator2',
    # 如果不想每次都安装UI2驱动,可以这么设置
    'skipServerInstallation': True,

}

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

# 访问百度首页
driver.get("https://www.baidu.com/")

猜你喜欢

转载自blog.csdn.net/qq_19982677/article/details/107699441
今日推荐