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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值