Hybrid App(混合模式移动应用)
是指介于 web-appnative-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 模式!
来源: http://www.bubuko.com/infodetail-2521868.html