current position:Home>Practical series 1 ️⃣ Wechat applet automatic testing practice (with Python source code)

Practical series 1 ️⃣ Wechat applet automatic testing practice (with Python source code)

2022-01-29 11:16:03 Software test automation test


origin , Why do you want to do applet automation testing

With the function and ecology of wechat app becoming more and more perfect , The product business form of many companies has gradually changed from App Upgrade to wechat app 、 The official account of WeChat . More and more applet project pages , Business logic is becoming more and more complex , Manual testing has been unable to meet the rapidly growing business needs .

However , Due to some characteristics of the applet itself , This leads to the lack of mature and perfect solutions in the industry , There are always problems ( Including the automation tools officially provided by Tencent wechat ). How to do a good job in the automatic testing of small programs It has become a common problem faced by test students .

What we're going to bring today is : Some best practices and experiences of wechat applet automatic testing , Including the basic test technology and operation method of wechat applet , And how to use Appium Of WebView Testing Technology + adb proxy Complete the automatic test of wechat applet ( It may be the most practical small program automatic testing technology at present ), And attach Python Version source code .

What information software do you need? Don't spend money to come here and have a look

Supporting video materials :《 Wechat applet automatic test 》 The content includes : Applet search test script writing 、 Technology selection 、 Frequently asked questions about applet testing , There is a link extraction code in the group to find the Administrator !

Applet running environment

 screenshots 2021-10-11  Afternoon 3.31.28.png

Platform differences : Although the operating environments are very similar , But there are some differences :

JavaScript Grammar and API Inconsistent support : Grammatically, developers can open ES6 turn ES5 To avoid ( details ); Besides , The applet base library has the necessary Polyfill, To make up for API The difference of .

WXSS Rendering performance is inconsistent : Although you can avoid most of the problems by turning on style completion , Or suggest that developers need to be in iOS and Android Check the real performance of the applet on the .

Wechat applet technology architecture

The technical architecture of wechat applet is shown in the figure below :

 screenshots 2021-10-11  Afternoon 3.32.38.png

Use Chrome Debugging applets

use Chrome Browser provided inspect Analysis tools , Enter the following address in the browser :

 Copy code 

Use Chrome View the open on your phone with a browser WebView Process and basic information :

 screenshots 2021-10-11  Afternoon 3.33.44.png

have access to chrome inspect Analyze the control structure and layout of wechat applet :

 screenshots 2021-10-11  Afternoon 3.34.22.png

Use console Carry out your own JavaScript Code :

 screenshots 2021-10-11  Afternoon 3.34.52.png

Performance test of applet

Here is a small program performance test chart :

1597735931958044771 (1).jpg

Automated testing of wechat applet

 screenshots 2021-10-11  Afternoon 3.40.09.png

The key steps of wechat applet automatic testing

1.Native Native Automation .

  • Use Appium Can finish , The disadvantage is that the control positioning is not accurate enough , Unable to go deep inside the applet ;

2.Webview Automation : More applet internal quality data can be obtained .

  • Set up chromedriver Correct version
  • Set up chrome option Pass to chromedriver
  • Use adb proxy solve fix chromedriver Of bug

Why are many people still uncertain ?

  • Low version of the chromedriver On higher versions of mobile phones bug
  • chromedriver Customized with wechat chrome There is a problem with the implementation of kernel docking

Solution : how fix it?

  • chromedriver Not used adb command , It USES adb agreement
  • Reference resources adb proxy Source code

Source code - Wechat applet automatic test Python Version code example

class TestWXMicroWebView:
    #  For demonstration purposes , not used page object Pattern 
    def setup(self):
        caps = {}
        caps["platformName"] = "android"
        caps["deviceName"] = " Programmer Yifan"
        caps["appPackage"] = ""
        caps["appActivity"] = ""
        caps["noReset"] = True
        caps['unicodeKeyboard'] = True
        caps['resetKeyboard'] = True

        caps['chromedriverExecutable'] = \

        # options = ChromeOptions()
        # options.add_experimental_option('androidProcess', '')
        caps['chromeOptions'] = {
            'androidProcess': ''

        caps['adbPort'] = 5038

        self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

        self.driver.find_element(By.XPATH, "//*[@text=' Mail list ']")


    def enter_micro_program(self):
        #  Native automated testing 
        size = self.driver.get_window_size()
        self.driver.swipe(size['width'] * 0.5, size['height'] * 0.4, size['width'] * 0.5, size['height'] * 0.9)
        self.driver.find_element(By.CLASS_NAME, 'android.widget.EditText').click()
        self.driver.find_element(By.XPATH, "//*[@text=' Cancel ']")
        self.driver.find_element(By.CLASS_NAME, "android.widget.EditText").send_keys(" Snowball ")
        self.driver.find_element(By.CLASS_NAME, 'android.widget.Button')
        self.driver.find_element(By.CLASS_NAME, 'android.widget.Button').click()
        self.driver.find_element(By.XPATH, "//*[@text=' Optional ']")

    def find_top_window(self):
        for window in self.driver.window_handles:
            if ":VISIBLE" in self.driver.title:

    def test_search_webview(self):
        #  Get into webview

        # css location 
        self.driver.find_element(By.CSS_SELECTOR, "[src*=stock_add]").click()
        #  Wait for a new window 
        WebDriverWait(self.driver, 30).until(lambda x: len(self.driver.window_handles) > 2)
        self.driver.find_element(By.CSS_SELECTOR, "._input").click()
        #  Input 
        #  Click on 
        self.driver.find_element(By.CSS_SELECTOR, ".stock__item")
        self.driver.find_element(By.CSS_SELECTOR, ".stock__item").click()
 Copy code 

Several hurdles that need to be crossed in the automated testing of small programs

  • WebView switch  /x5  Kernel debug switch
  • ChromeOption Options need to be filled in
  • WebView Version and ChromeDriver Version correspondence
  • Low version ChromeDriver Need repair ps Ordered bug
  • Context API There is a certain delay to wait


above , More (ChromeDriver Information and WebView Automate critical code ,Appium To configure ,mapping.json, Common errors, etc ), Please click here to join the group for .

  • ️ I made a official account.   Programmer Yifan  , Share and learn dry goods from time to time
  • ️ If this article is useful to you , Remember A little praise and attention , Every praise you give me is taken seriously as like ~
  • ️ See you next time !

copyright notice
author[Software test automation test],Please bring the original link to reprint, thank you.