This article is excerpted from the internal textbook of Hogwarts Testing Institute
With the increasing improvement of the function and ecology of wechat applet, many companies have more and more applet project page structures and more complex business logic. How to do a good job in the automatic test of small programs has become a major pain problem faced by test students.
Wechat applet
The applet is embedded in wechat. The page contains Native elements and Web elements, which is equivalent to a hybrid application. Moreover, the Web part of the applet is developed based on Tencent's X5 kernel, which is also special
WebView. Then, conduct automated testing on wechat applets, including operating native applications, WebView, and official automation SDK based on wechat.
WebView page element get
Use the element positioning tool:
- weditor
Webitor installation method
pip install weditor
Reference documents: https://github.com/alibaba/web-editor
When using chrome inspect to locate, the parsing element parses the page into an html page. When using webitor, the page will be parsed into a native page, while Appium
When operating elements, the page is also parsed into a native operation (except switching webview)
Get applet number (open applet)
Mac:
adb shell dumpsys activity top| grep ACTIVITY
Windows:
adb shell dumpsys activity top| findstr ACTIVITY
Get Android process
Actual combat source code
from time import sleepfrom appium import webdriver class TestDemo: def setup(self): self.desire_cap= { 'automationName': "uiautomator2", "platformName": "Android", "deviceName": "wechat", "appPackage": "com.tencent.mm", "appActivity": ".ui.LauncherUI", "noReset": "true", 'chromeOptions': {'androidProcess': 'com.tencent.mm:appbrand0'} } # Android process: webview is an independent process, so it cannot be obtained. You need to add Android process in chromeOptions to self driver=webdriver. Remote(" http://127.0.0.1:4723/wd/hub ",self.desire_cap) self.driver.implicitly_wait(20) def teardown(self): self.driver.quit() def test_demo(self): # When wechat was first opened, the page loading time was unknown, # Need to pass find_element Trigger implicit wait to prevent subsequent operation failure self.driver.find_element_by_xpath("//*[@ text = 'address book'] ") size = self.driver.get_window_size() # get the width and height of the current screen width = size.get (" width ") height = size.get (" height ") # slide to open the applet page self.driver.swipe ((width / 2), int ((height * 0.2)), (width / 2), (height * 0.8), 2000) self.driver.find_element_by_xpath (" //*[@ resource id ='com. Tencent. Mm: ID / gam 'and @ text =' snowball '] "). Click() sleep (5) print (self.driver.contexts,' first print ') self.driver.find_element_by_xpath (" / / * [@ content desc =' search stock information / code '] /..). Click() self.driver.find_element_by_xpath (' / / * [@ text = "please enter stock name / code"]). send_keys(" Alibaba text = self.driver.find_element_by_xpath ('/ / * [@ content desc = "Alibaba"]') assert text
Software version
-
Simulator: Genymotion
-
System version: 8.1
-
Wechat version: 7.0.15
-
Applet: Snowball
Reference link
-
https://sites.google.com/a/chromium.org/chromedriver/capabilities
-
https://sites.google.com/a/chromium.org/chromedriver/getting-started/getting-started---android
extend
There are many test methods for applets. Because wechat versions are often upgraded and webview settings will change, the available test methods may be different for each version. For more available test methods, please refer to the tester Forum: https://ceshiren.com/t/topic/12403
** _
Come to Hogwarts test and development society to learn more advanced technologies of software testing and test development. The knowledge points include web automated testing, app automated testing, interface automated testing, test framework, performance testing, security testing, continuous integration / continuous delivery / DevOps, test left, test right, precision testing, test platform development, test management, etc, The course technology covers bash, pytest, junit, selenium, appium, postman, requests, httprunner, jmeter, jenkins, docker, k8s, elk, sonarqube, Jacobo, JVM sandbox and other related technologies, so as to comprehensively improve the technical strength of test and development engineers
QQ communication group: 484590337
The official account TestingStudio
Click for more information