appium手机混合应用,web界面h5

混合应用测试准备

# -*- coding:utf-8 -*-

from appium import webdriver

desired_caps = {
    "platformName": "Android",
    "platformVersion": "10",
    "deviceName": "X4UOCQOF79AUZX79",
    "appPackage": "com.example.haiwen.myhybirdapp",
    "appActivity": ".MainActivity",
    "noReset": "True",
    "newCommandTimeout": 6000,
    "automationName": "UiAutomator2"
}

# 启动混合应用
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
driver.implicitly_wait(10)

# 控制原生的控件
driver.find_element_by_id("com.example.haiwen.myhybirdapp:id/editText").send_keys("https://www.baidu.com")
driver.find_element_by_id("com.example.haiwen.myhybirdapp:id/button").click()

# 查看当前手机上 APP的 contexts
print(driver.contexts)
# 切换到 webview contexts
driver.switch_to.context("WEBVIEW_com.example.haiwen.myhybirdapp")


# 当我们在操作 webview的部分,是可以使用一切selenium的定位语法的
driver.find_element_by_id("kw").send_keys("123456")

手机h5界面测试

# -*- coding:utf-8 -*-

from selenium import webdriver

# 以开发者模式打开
options = webdriver.ChromeOptions()
options.add_experimental_option("mobileEmulation", {"deviceName": "iPhone X"})
driver = webdriver.Chrome(options=options)


driver.implicitly_wait(5)
driver.get("http://120.55.190.222:38080/#/pages/index/user")

driver.execute_script("window.scrollBy(0, 500)")

from selenium import webdriver
#以开发者模式打开手机页面
#进行定位部分代码编写时,浏览器的网页切换为h5页面格式,选择对应的手机型号
op = webdriver.ChromeOptions()
op.add_experimental_option("mobileEmulation", {"deviceName": "iPhone x"})
driver = webdriver.Chrome(options=op)
driver.implicitly_wait(5)
driver.get("http://127.0.0.1/#/")
driver.execute_script("window.scrollBy(0, 500)")

appium测试手机浏览器

# -*- coding:utf-8 -*-


from appium import webdriver

caps = {
    "platformName": "Android",
    "plathformVersion": "10",
    "deviceName": "X4UOCQOF79AUZX79",
    "browserName": "Chrome",
    # 要在电脑上装一个与手机里边的浏览器版本相对应的驱动
    # 要注意一下,名字重命名,防止和电脑上的浏览器驱动冲突
    # 驱动的安装方式和selenium是一样的
    "chromedriverExecutable": "D:/tool/selenium/python/chromedriver_81.exe",
    "noReset": "True",
    "newCommandTimeout": 6000,
    "automationName": "UiAutomator2"
}

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

driver.get("http://120.55.190.222:38080/#/")


driver.find_element_by_css_selector(".uni-input-input").click()
driver.find_element_by_css_selector(".uni-input-input").send_keys("123456")

上一篇:Workshop 深圳站|实战+源码架构剖析带你揭开Appium的神秘面纱


下一篇:appium+python环境安装遇到问题