WeChat applet automated testing framework Minium - native control pop-up window processing (1)

The previous article Minium, an automated testing framework for WeChat applets——Advanced testing mainly introduces the configuration and execution of test plans using the Minium framework, and real machine debugging.

Native control pop-up windows are common functions in applets, and are generally caused by the applet API or the applet Page event interface (such as authorization pop-up windows, pop-up windows, maps, forwarding applets, etc.).

The series of articles on native control pop-up processing mainly introduces how to use the Minium framework to automatically click various pop-up window operations .

Minium supports multi-terminal execution of automated scripts on developer tools and real devices. The basic way to handle pop-up windows is to call the Native interface , but it is slightly different when running on different terminals:

  • Real machine operation: the use case script can directly call the Native instance interface for processing
  • Developer tool running: The pop-up window cannot be directly processed when the tool is running. It needs to be config.jsonconfigured mock_native_modal, and then the use case script calls the Native instance interface. The principle is that the pop-up window is pre-Mocked.

Specifically, the main native control pop-up windows in the current applet mainly include:

  • Modal popup (wx.showModal)
  • User information authorization pop-up window (wx.getUserProfile)
  • Show action menu popup (wx.showActionSheet)
  • Geographical location authorization popup (wx.getLocation)
  • map selection (wx.chooseLocation)
  • Subscribe message authorization popup (wx.requestSubscribeMessage)
  • Forward applet popup (Page.onShareAppMessage event interface)

This article mainly introduces how to deal with modal pop-ups, user information authorization pop-ups, and display operation menu pop-ups.
Subsequent article on native control pop-up processing (2), mainly introduces how to handle geographical location authorization pop-up windows, map selection, subscription information authorization pop-ups
Native control pop-up processing article (3), mainly introduces how to handle forwarding applet pop-up windows

The mini program demo can refer to miniprogram-demo

Modal dialogs (wx.showModal)

wx.showModalThe pop-up box caused by the modal dialog box , such as the applet JS code

testModal() {
    
     
    wx.showModal({
    
    
      title: "test modal",
      content: "modal content",
      success(res) {
    
    console.log("modal success", res)},
    })
  },

processing method

Call the handle_modal() interface in the Native instance of the minium framework . The key code is as follows, for a complete example, please refer to the usetest_handle_modal

	# 点击触发弹窗按钮
    self.page.get_element("#testModal").tap()
    time.sleep(2)
    # 点击弹窗 确定
    self.native.handle_modal("确定")

Note: The IDE platformconfig.json needs to be configured to run , mock_native_modalthe example is as follows:

{
    
    
  "project_path":"xxxx",
  "dev_tool_path":"xxxx",
  "platform": "ide",
  "mock_native_modal": {
    
    
      "showModal": {
    
    
          "title": "test modal",
          "content": "modal content"
      }
  }
}

operation result

The result of running the script is as follows:

insert image description here

User information authorization pop-up window (wx.getUserProfile)

The user information authorization pop-up window wx.getUserProfileis caused the pop-up window, such as the applet JS code

getUserProfile() {
    
    
    wx.getUserProfile({
    
    
      desc: "我要拿你的信息", 
      complete(res){
    
    console.log(res)} 
    })
  },

processing method

Call the allow_get_user_info() interface or allow_authorize() interface in the Native instance of the minium framework. The key code is as follows, for a complete example, please refer to the usetest_allow_get_user_info

	# 点击触发弹窗按钮
    self.page.get_element("#`getUserProfile`").tap()
    time.sleep(2)
    # 点击弹窗
    self.native.allow_get_user_info()

Note that the IDE platformconfig.json needs to be configured to run mock_native_modal, the example is as follows:

{
    
    
  "project_path":"xxxx",
  "dev_tool_path":"xxx",
  "platform": "ide",
   "mock_native_modal": {
    
    
        "userInfo": {
    
    
            "nickName": "mini_test",
            "gender": 0,
            "language": "zh_CN",
            "city": "",
            "province": "",
            "country": "",
            "avatarUrl": ""
        }
    }

}

operation result

The result of running the use case is as follows:

insert image description here

Show action menu popup (wx.showActionSheet)

Show the pop-up window wx.showActionSheetcaused by window, such as the applet JS code

testActionSheet() {
    
    
    wx.showActionSheet({
    
    
      itemList: ['A', "测试", "C"],
      success(res) {
    
    
        console.log(res)
      },
      fail(err) {
    
    
        console.error(err)
      }
    })
  },

processing method

Call the handle_action_sheet() interface in the Native instance of the minium framework . The key code is as follows, for a complete example, please refer to the usetest_handle_action_sheet

	self.page.get_element("#testActionSheet").tap()  # 触发选择器
    time.sleep(1)
    self.native.handle_action_sheet(item)  # 选择{item}

If the IDE platform is running , config.jsonit needs to be configured mock_native_modal. The example is as follows:

{
    
    
  "project_path":"xxxx",
  "dev_tool_path":"xxxx",
  "platform": "ide",
  "mock_native_modal": {
    
    
        "showActionSheet": {
    
    
        }
    }
}

operation result

The result of running the use case is as follows:

insert image description here

Cloud Test Execution

The above processing pop-up use cases can be executed directly on the cloud test service, upload the use cases to the cloud test, create a new test plan, create a new test task, select a test plan and execute it. For detailed tutorials, please refer to Custom
Test Cloud Test Service provides detailed test reports, including running screenshots, log information, network request analysis, performance analysis, etc.

The cloud testing service only supports real-device testing, and multi-platform real-device can be selected to support simultaneous operation of multiple platforms without configuration, deployment config.jsonand maintenance of the real-device environment

need help

Note: IDE operation and real device debugging initialization failed, please refer to the previous WeChat Mini Program Automated Testing Framework Minium - Advanced Testing Frequently Asked Questions, or refer to the official documentation FAQ

Guess you like

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