WeChat Mini Program Automated Testing Framework Minium - Frequently Asked Questions about Page Loading

The previous article mainly summarizes the common problems you encounter when using the Minium automation framework , that is, the common problems of installing Minium, and the problems and solutions that are often encountered in the process of using Minium, including initialization and running use cases.

Incomplete page loading is one of the most common reasons for Minium test cases to fail on real devices .

The main reason is that writing Cases is generally done on developer tools (Windows or Mac machines). Generally speaking, the Internet speed and response speed of the real machine will be much slower than that of the developer tool .
If the code sleepuses the method of waiting for a few seconds before operating, it is likely that the waiting time on the developer tool is enough to execute successfully, but the real device needs a longer waiting time to load and the use case fails.

The following figure is an example of a use case running test failure due to incomplete page loading when the cloud test service executes a case on a real machine

insert image description here

When the running test fails due to the incomplete loading of the page , you can troubleshoot according to the following methods

1. Check the network log first to find out why the page is not loaded

In the cloud measurement service, first click on the network request details to view the network request log. You can pay attention to the following aspects:

  • Whether the request status code is 200. Generally speaking, the status codes of 4xx and 5xx may be a client problem or a server connection problem. For example, it may be caused by the need to configure the proxy to access the server, etc.
  • Pay attention to the time consumption of the request to see if it is a network problem or the network speed is relatively slow
  • Pay attention to the returned Response. Sometimes the network status code is normal, and the time-consuming request is normal, but the Response returns a null value, and there should be corresponding data under normal circumstances, which may also cause a white screen on the page. At this time, you can check why the return is empty from the background server, or use the Mock request method to return the correct return value through the Mock method

insert image description here

2. Use case delay code optimization

When it is found that the real machine sleepdoes not have enough time and the page is not loaded, it is recommended not to use sleep to wait. You can choose the following waiting methods according to your needs:

ret = self.app.wait_for_page("/pages/testpage/testpage")
self.assertTrue(ret, "wait success")
  • wait_util()
    waits for the page to load asynchronously
ret = self.app.wait_util(0, 5)  # 5s内, 页面没有任何未完成的异步请求
self.assertTrue(ret, "wait success")
  • wait_for()
    waits until the specified condition is met, the condition can be a page element, a custom function or the time to wait (in seconds)
ret = self.page.wait_for(".waitfor", max_timeout=2)
self.assertTrue(ret, "wait success")
keys = ("testwait", "waitkeys.b")
ret = self.page.wait_data_contains(*keys, max_timeout=3)
# 2s后,page.data={testwait: 1, waitkeys: {a: 1, b: false}}
# 4s后 page.data = {}
self.assertTrue(ret, "wait success")

need help

Guess you like

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