Appium_Debug the key code of the X5 version of the webview customized by Tencent and the places that are different from the normal webview settings

=

Debugging the webview of x5 reports an error.

Thanks to the author for sharing: Automation technology of Appium  WeChat webview .

The testerhome community is good .

=

WeChat settings

Open debugx5.qq.com with WeChat, this is the x5 kernel debugging page of WeChat. You can enter this URL in any chat window. And open it. 
Check "Whether to enable TBS kernel Inspector debugging function"

 

 

Writing test cases with ChromeDriver

First install ChromeDriver
from the official download or find chromedriver from the installation path of your appium. In fact, the path of chromedriver will also be printed in the execution log of appium,
then start it on the computer, and set the port

chromedriver --url-base=wd/hub --port=8000

You can use the client of selenium or appium to write test cases.
The following is the test case of my scalatest. You can implement it yourself in other languages

test("test chromedriver weixin") {
  val options = new ChromeOptions()
  options.setExperimentalOption("androidPackage", "com.tencent.mm")
  options.setExperimentalOption("androidUseRunningApp", true)
  options.setExperimentalOption("androidActivity", ".plugin.webview.ui.tools.WebViewUI")
  options.setExperimentalOption("androidProcess", "com.tencent.mm:tools")
  val capability = DesiredCapabilities.chrome()
  capability.setCapability(ChromeOptions.CAPABILITY, options)
  val url = "http://127.0.0.1:8000/wd/hub"
  val driver = new AndroidDriver[WebElement](new URL(url), capability)
  driver.get("https://testerhome.com/topics/6954")
  println(driver.getPageSource)
  driver.quit()
}

Writing test cases with appium

Some people often ask why appium on android can't automate WeChat webview, in fact it is possible. It is mainly caused by a bug in the current appium. 
When the context in appium is switched, a key androidProcess configuration is not brought. 
He will When appium recognizes the webview, it recognizes the webview of com.tencent.mm:tools as the webview of com.tencent.mm. As a result, the context switch fails.

The correct way to test WeChat H5 with appium is as follows

test("test weixin h5") {
  val capability = new DesiredCapabilities()
  capability.setCapability("app", "")
  capability.setCapability("appPackage", "com.tencent.mm")
  capability.setCapability("appActivity", ".ui.LauncherUI")
  capability.setCapability("deviceName", "emulator-5554")
  capability.setCapability("fastReset", "false")
  capability.setCapability("fullReset", "false")
  capability.setCapability("noReset", "true")
  //capability.setCapability("unicodeKeyboard", "true")
  //capability.setCapability("resetKeyboard", "true")

  //关键是加上这段
  val options = new ChromeOptions()
  options.setExperimentalOption("androidProcess", "com.tencent.mm:tools")
  capability.setCapability(ChromeOptions.CAPABILITY, options)

  val url = "http://127.0.0.1:4723/wd/hub"
  val driver = new AndroidDriver[WebElement](new URL(url), capability)
  println(driver.getPageSource)
  driver.findElementByXPath("//*[@text='我']").click
  driver.findElementByXPath("//*[@text='收藏']").click
  driver.findElementByXPath("//*[contains(@text, '美团外卖')]").click
  println(driver.getPageSource)
  println(driver.getContextHandles)
  driver.context("WEBVIEW_com.tencent.mm:tools")
  println(driver.getPageSource)
}

The most important thing is this

val options = new ChromeOptions()
options.setExperimentalOption("androidProcess", "com.tencent.mm:tools")
capability.setCapability(ChromeOptions.CAPABILITY, options)

postscript

之前测试加上ChromeOptions配置的时候没有成功, 我以为是appium不支持ChromeOptions, 就给appium-android-driver提交了一个PR
后来jlipps提醒了我一下

 

 

我就又追查了几遍, 最后发现是我本地安装appium时候加上的http_proxy环境变量干扰了ChromeDriver的执行.
Appium其实是支持ChromeOptions的

结论也就是现在的Appium其实是可以完美的做微信自动化的

我在想我是不是国内第一个提供微信webview自动化方法的人  
借鉴此思路的同学转发请注明原链. https://testerhome.com/topics/6954

 

 

=

=

=

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326228007&siteId=291194637