Appium(Python)測試混血App
阿新 • • 發佈:2018-03-10
host blog eve res python 記得 之間 oid -a
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模式!
Appium(Python)測試混血App