1. Introduction
Usually, we use automation mainly for the App end and the Web end. In addition, there are two scenarios that are less used but also very important, respectively: browser and wechat applet.
Today we are going to talk about how to automate operations on wechat mini programs.
2. Wechat mini program
The small program is embedded in wechat, and the page contains Native elements and Web elements, which is equivalent to a mixed application.
And, the small program Web part is based on Tencent X5 kernel development, is also a special WebView.
So how do small programs automate?
Main methods include: UiAutomator native, based on WebView, based on wechat official automation SDK
Each of these approaches is described below
3. The native
Native automation is to use UiAutomator2 to capture the element UI tree, and then use element attributes and hierarchical relationships and coordinate values to locate elements and perform a series of automated operations.
However, there is a disadvantage of native, because the applet is based on WebView, so the element locator is missing, many attributes including: Content-desc, resource-ID does not exist.
Although it is difficult to use this method to locate elements, the hierarchy of elements can be used to compensate.
4. WebView
Most tutorials on the web are automated based on WebView.
First, you need to open the debugging function of wechat. Enter “debugx5.qq.com” in the file Transfer assistant and check “Open the TBS kernel Inspector debugging function”.
Next, enter the following command in Chrome to go to the device and page management page
chrome://inspect/#devices
Click the corresponding page item to display the complete HTML element information of the target page of the applet in the developer tools.
Automation is easy. With Appium, for example, the corresponding applets are sent directly to the file sending assistant as an entry point for automation to begin.
Switch to all the Context of the applet, and finally, use Css selectors to select web elements for a series of automated operations.
It should be noted that this method can not be automated based on WebView by default after wechat 7.x. This can reduce the ChromeDriver version to correspond to the wechat X5 kernel version.
5. The official SDK
Wechat officially provides the small program automation SDK, as a standard testing framework, supporting real computers and simulators.
If it is a small program developed by their own company, you can configure small program developer tools, using the official API to write a simple script, pointing to the project address, with the help of NPM command to complete automatic operation.
If it is a third-party applets, this approach is not suitable.
6. Compare
Each of the three ways to automate applets mentioned above has advantages and disadvantages.
If it is micro channel small program source, it is recommended to use the official SDK to complete the automation of small program, otherwise you can choose one of the native and WebView.
In addition, the automation of using WebView to make applets requires the ChromeDriver version and x5 kernel version to be consistent.
For more technical dry articles, follow the public account AirPython to unlock it.