Hybrid App(混合模式移动应用)
是指介于web-app、native-app这两者之间的app
兼具Native App良好用户交互体验的优势
和
Web App跨平台开发的优势
HybridAppTest.py:
import unittest
from time import sleep
from appium import webdriver
class MyTestCase(unittest.TestCase):
def setUp(self):
capabilities = {
"platformName": "Android",
"platformVersion": "7.1.1",
"deviceName": "3216e430",
"browserName": "Chrome",
# Chrome浏览器
"appPackage": "com.android.browser",
# Chrome的包名
"appActivity": ".BrowserActivity",
# Chrome的启动页
"unicodeKeyboard": True,
"resetKeyboard": True,
"noReset": True,
"noSign": True
}
self.driver = webdriver.Remote("http://localhost:4723/wd/hub", capabilities)
sleep(2)
def test_hybridApp(self):
driver = self.driver
driver.get("http://www.cnblogs.com/yjlch1016/")
sleep(2)
driver.switch_to.context("NATIVE_APP")
# 切换到原生
sleep(1)
driver.find_element_by_id("com.android.chrome:id/menu_button").click()
# 点击右上角的菜单
sleep(2)
driver.find_element_by_accessibility_id("历史记录").click()
# 点击历史纪录
sleep(2)
driver.keyevent(4)
# 手机返回键
sleep(2)
driver.switch_to.context("CHROMIUM")
# 切换到H5
sleep(1)
driver.find_element_by_xpath(".//*[@id=‘homepage1_HomePageDays_ctl00_DayList_TitleUrl_0‘]").click()
# 点击第1篇博客
sleep(2)
assert driver.find_element_by_xpath(".//*[@id=‘cb_post_title_url‘]"), "Appium(Python)驱动手机淘宝App"
def tearDown(self):
self.driver.close_app()
self.driver.quit()
if __name__ == ‘__main__‘:
unittest.main()
如果是自己公司的App,
请记得麻烦开发工程师开启WebView的debug模式!