WeChat Mini Program Automation Testing Framework Minium—— Advanced Testing

The previous article WeChat Mini Program Automated Testing Framework Minium - Quick Start mainly introduces the installation and use of Minium, as well as possible problems and solutions. This article mainly introduces advanced testing using the Minium framework, configuration and execution of test plans, and real machine debugging. For the mini program demo, refer to miniprogram-demo

Test Plan

Configure Test Plan

The test plan case name and package name need to be configured suit.jsonin

{
  "pkg_list": [
    {
      "case_list": [
        "test_*"
      ],
      "pkg": "test.*_test"
    }
  ]
}

basic configuration

config.json configures some basic information, such as the platform on which the applet runs, the project path of the applet code, and the installation path of WeChat developer tools

{
    
    
  "project_path":"xxx",     // 小程序项目路径
  "dev_tool_path":"xxx",  // 微信开发者工具安装路径
  "platform": "ide"
}

test case

# `first_test.py`
class FirstTest(minium.MiniTest):
    def test_get_system_info(self):
        sys_info = self.mini.get_system_info()
        self.assertIn("SDKVersion", sys_info)

    def test_ui_op(self):
        # 页面跳转
        self.app.switch_tab("/pages/index/index")
        # 元素定位
        ele = self.page.get_element("/page/view/navigator[3]/button")
        # 元素点击
        ele.click()
        time.sleep(3)
        # 判断元素是否存在
        self.assertTrue(self.page.element_is_exists("/page/view[9]/mytest//view", max_timeout=5))
        # 打印元素文本
        inner = self.page.get_element("/page/view[9]/mytest//view").inner_text
        self.logger.info("UI Case %s", inner)


# `second_test.py`
class SecondTest(minium.MiniTest):
    def test_log(self):
        self.logger.info("【info级别日志】")
        self.logger.debug("【debug级别日志】")
        self.logger.warn("【warn级别日志】")

Execute the test plan

Execute the following command in the project path

minitest -s suite.json -c config.json -g

Run the command in the project directory python3 -m http.server 12345 -d outputs, access it on the browser http://localhost:12345, and view the test report

insert image description here

common problem
  • There is a problem that the newly executed test results are not updated.
    Due to the cache problem of the local browser, the Chrome browser opens the console F12, clicks 设置, and 偏好设置ticks 网络in .停用缓存(在开发者工具已打开时)

insert image description here

Real machine debugging

Real-device debugging requires IDE dependencies, and USB real-device debugging is supported. Android debugging first needs to install the ADB tool (Android debugging bridge) to obtain Android device information. iOS needs to install libmobiledevice, configure WebDriverAgent, and obtain device information.

Android real machine debugging, ADB tool (Android debugging bridge) can directly operate and manage the android emulator or real android device
execution adb devices, and obtain the device serial number

insert image description here

config.jsonConfigure device information. If only one mobile phone is online, you only need to platformconfigure Androidas . If multiple devices are connected to the mobile phone, the configuration file needs to specify the serial number of the device , such as:

{
    
    
  "project_path":"xxx",     // 小程序项目路径
  "dev_tool_path":"xxx",  // 微信开发者工具安装路径
  "platform": "android",
  "device_desire": {
    
    
    "serial": "xxx"
   }

For iOS device information configuration details, please refer to Real Device Test Configuration

common problem

  1. The real device environment is configured but the applet on the real device cannot be launched, please check whether the real device debugging 2.0 is used (automation is not supported for now), if yes, switch back to the real device debugging 1.0

Can’t wait until App.initialized

  • Minium initiates remote debugging, but the phone does not start the applet normally/white screen
    • You can try to manually switch to and 二维码真机调试then switch自动真机调试
    • If it still doesn't work, please confirm that 远程调试the function is normal
  • Minium initiates remote debugging, and the remote debugging window has popped up, but the applet is not opened on the mobile phone
    • Please manually confirm whether the real device debugging 2.0 is used

insert image description here

Test Results

Run the command in the project directory python3 -m http.server 12345 -d outputsand access it on the browserhttp://localhost:12345

insert image description here

suggestion

It is recommended that developers execute use cases on Cloud Test. You can upload locally debugged use cases to Cloud Test, create a new test plan, and create a Minium task. You can choose a multi-platform real machine, and support multiple platforms to run at the same time, without the need for users to deploy and maintain real machines . machine environment .

After the test, the cloud test service provides a detailed test report, including running screenshots, log information, network request analysis, performance analysis, etc. When the execution of the use case fails, the error log and the error line code will be provided to facilitate the user to troubleshoot the cause of the error. For specific operations, please refer to the official cloud test documentation Custom Test

Comparison of local execution and cloud test service execution use cases
ability local execution Cloud test service execution
test account You can use your own WeChat account Only support the use of virtual accounts for testing
Real machine deployment You need to deploy the real machine yourself, install wda or adb environment No need to prepare the real machine environment, directly test
Environmental maintenance You need to maintain the developer tools login status by yourself Does not rely on developer tools and requires no user maintenance
view report You need to build your own report viewing environment Provide detailed test reports and support sharing report https links
performance data You need to manually call the interface to obtain Support viewing use case performance data, such as CPU, memory usage, etc., you can enable experience scoring to further view runtime performance data
Devops Need to implement it yourself Provide a third-party https interface to submit tasks and obtain results. For details, refer to Get through the devops process

need help

Guess you like

Origin blog.csdn.net/WXMiniTest/article/details/128209400