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

相关文章
相关标签/搜索