How does Appium conduct automated testing of applets?

At this stage, small programs are becoming more and more popular, and wechat has also given a huge amount of traffic temptation. Many companies have small program development.
So can small programs be tested automatically? Of course!

01 preparation stage

Three inspect ion tools are optional:

chrome DevTools


UC DevTools

TBS Studio (Tencent's own applet debugging tool)

In fact, both Tencent's debugging tools and UC's debugging tools are similar in terms of secondary packaging and use of chrome devtools. You can choose one of the above three tools. Tencent has sorted out the relevant documents in a friendly manner:

02 enable applet debug mode

Tencent's browser driver is an exclusive customized X5 kernel. I found that Tencent also had a very detailed article, so I directly moved the link:

Use steps:

1. Open with wechat , click "view kernel version" to display: "kernel version information: 43xxx". If the version number is less than 439xx, you need to upgrade the kernel in the next step.

2. Open , click "install online TBS kernel". Restart wechat and check the kernel version number.

3. Open , select the information - > open x5jscore inspector check box. Restart wechat.

4. Open wechat, "discovery" - applet, and select another applet, such as "JD"

5. Start debugging in TBS Studio, and you can see the following interface:

03 setting initialization environment

1. Configure desired_capabilities (the X5 kernel cannot use chromedriver)

# Compared with the previous startup parameters, the startup parameters of the applet need several more items
"chromedriverExecutable": chromedriverfilepath, "recreateChromeDriverSessions": True, "chromeOptions": {"androidProcess": ""}
# The version of chromedriver filepath needs to be the version seen in inspect
# recreateChromeDriverSessions is used to automate the configuration of X5 kernel drivers
# chromeOptions specifies the context of the applet webview in advance

2. Open wechat

# apppackage appActivity of wechat

{"appPackage": "", "appActivity": ""}

3. Enter applet

All those who want to enter the debug state of the applet should go through the search entry;

Some people's wechat cannot accurately locate specific elements in the process of positioning. At this time, we recommend using xpath for positioning;

Some people's wechat can locate specific elements in any way

When you enter the search page, the search box cannot be accurately located, but it can

xpath locates the word "search"

You can only use XPATH for positioning here

tips: this search box must be clicked before entering text. Otherwise, there will be a bug

Enter the search page, where some people can accurately locate, and some can't

caps = {"appPackage": "", "appActivity": "", "chromedriverExecutable": file,

        "recreateChromeDriverSessions": True, "chromeOptions": {"androidProcess": ""}}

driver = startup_param(**caps)

wait = WebDriverWait(driver, 20)

loc = (MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("find")')



loc = (MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Search")')



loc = (MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Wechat hotspot")')


loc = (MobileBy.XPATH, "//*[@ text = 'search'] ")

ele = driver.find_element(*loc)


loc = (MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("JD.COM")')



loc = (MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("E-commerce platform")')



4. Find the context where the applet runs

As shown in the figure, we can use the first command to get the active process of the mobile phone app

Find the pid with the word plugin

Take the pid and execute the second command to get the name of the pid process

Generally, the applet name is: \ \

adb shell dumpsys activity top| findstr ACTIVITY

adb shell ps pid

5. Switch to this context

context = driver.contexts  # There will be two webview context s

driver.switch_to.context(context[-1]) # Select the last context to switch

# ['NATIVE_APP', '']

6. Because of the characteristics of the applet, each page is a separate handle, so we need to switch

handle = driver.window_handles  # Gets all the handles of the current page

for i in handle:  # Traverse all handles

    driver.switch_to.window(i)  # Cut to each handle

    if keyword in driver.page_source:  # When there is a keyword we want in a handle, we jump out of traversal


7. Conduct relevant use case tests

For the operation here, please refer to the operation of H5 page in our series

But now the new version of students may see that the H5 page is no longer the webview class, and can be accurately located

The following is the supporting information. For the friends doing [software testing], it should be the most comprehensive and complete war preparation warehouse. This warehouse has also accompanied me through the most difficult journey. I hope it can also help you!

Finally, you can get a free 216 page Software Test Engineer Interview treasure file and free information sharing in official account: sad hot strip! And free video sharing course, including basic knowledge, Linux essential, Shell, Internet program principle, Mysql database, grab tool topics, interface test tools, test advanced -Python programming, Web self. Automation test, APP automation test, interface automation test, test advanced continuous integration, test architecture development test framework, performance test, security test, etc.

Don't fight alone in learning. It's best to keep warm together, achieve each other and grow together. The effect of mass effect is very powerful. If we learn together and punch in together, we will have more motivation to learn and stick to it. You can join our testing technology exchange group: 914172719 (there are various software testing resources and technical discussions)

Friends who like software testing, if my blog is helpful to you and if you like my blog content, please click "like", "comment" and "collect" for three times!

Haowen recommendation

Job transfer interview, job hopping interview, these interview skills that software testers must know!

Interview experience: move bricks in first tier cities! Face software testing post again, 5000 will be satisfied

Interviewer: I've worked for three years and have a preliminary test? I'm afraid your title of software test engineer needs double quotation marks

What kind of person is suitable for software testing?

The man who left work on time was promoted before me

The test post changed jobs repeatedly and disappeared

Tags: Python Programmer software testing IT

Posted on Tue, 16 Nov 2021 07:24:44 -0500 by zubinkasad