Appium學習筆記||10、Webview測試

(讓開發加上myWebView.setWebContentsDebuggingEnabled(true),才能夠測試)

第一種,能夠使用Chrome瀏覽器,這種webview不依賴app。能夠經過Selenium解決。

 

第二種,webview依賴app。也須要chrome瀏覽器,經過chrome瀏覽器的遠程調試功能。

1. app在手機上打開,鏈接電腦。html

2. 在chrome瀏覽器中輸入chrome://inspectweb

3. 在Remote Target中 出現app的webview內容,說明鏈接成功chrome

4. 點擊Inspect能夠遠程調試瀏覽器

=========================================================================================app

 

 代碼中使用webview

 1. 這會使用到chromedriver,因此首先要下載chromedriver。(能夠參考:http://www.javashuo.com/article/p-faipnerj-ks.html

  記住是webview須要,因此要下webview須要的chromedriver的版本,不要下pc端的chrome瀏覽器對應的chromedriver版本。ide

  不然會報錯:selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: No Chromedrivers found in 'D:\ChromeDriver\chromedriver_75.exe'測試

  

 

 

2. 配置chromedriver能夠在代碼裏或者在appium中。

  1. 代碼中,只要加上一條:spa

    desired_caps['chromedriverExecutableDir'] = r'D:\ChromeDriver\chromedriver_win32_2.34\chromedriver.exe'

   2. Appium中:調試

    

  無論哪一種方法,路徑後都須要到xxx.exe才能夠,不然報錯會報找不到。code

  selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Trying to use a chromedriver binary at the path D:\ChromeDriver\chromedriver_win32_2.34\chromedriver, but it doesn't exist!

  

 

   3. 代碼

 1 #切換到webview
 2 print(driver.contexts)
 3 print(driver.current_context)
 4 driver.switch_to.context("WEBVIEW_com.example.jcy.wvtest")
 5 #輸入你好,點擊搜索
 6 driver.find_element_by_id("index-kw").send_keys("你好")
 7 time.sleep(2)
 8 driver.find_element_by_id("index-bn").click()
 9 #切換到app
10 driver.switch_to.context("NATIVE_APP")
11 #點擊通知
12 driver.find_element_by_xpath("//*[@content-desc='通知']").click()

相關文章
相關標籤/搜索