The page loading speed is too slow, how can the test efficiency be doubled?

The page loading speed is too slow, how can the test efficiency be doubled?

1. Encounter a problem

When doing web automation testing, we often encounter some pages that load very slowly. There are many reasons why these pages load slowly:

◆ The page has a lot of resources to load, usually the home page;

◆ The page uses some external dependencies that are not very stable, such as calling immature CSS style libraries and js libraries;

◆ The company's server processing capacity is limited;

◆ The developer's code is not well written, etc.

The page loading speed is too slow, how can the test efficiency be doubled?

 

2. Analyze the problem

If we want to perform automated testing, we first need to open the page through the get method of webdriver.

However, because the page loading time is too long, subsequent operations cannot be performed, and even errors are reported directly, which greatly affects the efficiency of automated testing.

The page loading speed is too slow, how can the test efficiency be doubled?

 

When getting the actual results, it took a lot of time to wait for the home page to load correctly, although the later test cases passed.

However, a lot of time was wasted, and it took 26.5 seconds to run a test case.

The page loading speed is too slow, how can the test efficiency be doubled?

 

3. Solve the problem

For some resources that load slowly, there is no need to wait until all the elements are loaded before performing element positioning during automated testing.

Set a timeout period. If the page is loaded for more than the specified time, the page is manually terminated, which is equivalent to clicking the X button of the browser by hand to stop the page from loading.

The page loading speed is too slow, how can the test efficiency be doubled?

 

The code has 3 points:

1. Set the timeout time to 5 seconds

2. When the driver.get(url) is executed, if the page is loaded for less than 5 seconds, no error will be reported. If the page is loaded for more than 5 seconds, a timeout exception will be thrown

3. Use TimeoutException to catch timeout exception. When the timeout expires, execute the js designation to terminate the page loading.

Next, encapsulate the page get method:

The page loading speed is too slow, how can the test efficiency be doubled?

 

Modify the original automation script:

The page loading speed is too slow, how can the test efficiency be doubled?

 

4. Summarize the problem

No other code needs to be changed.

You only need to add IndexPage(driver).get() to the time-consuming place to load the page according to the set timeout time.

The page loading speed is too slow, how can the test efficiency be doubled?

 

The new test time is 11.3 seconds, and the test efficiency has increased by nearly 60%.

Not to mention, I have to quickly integrate this solution into my resume.

Recommend a software testing learning exchange group: 785128166, there are shared videos, interview guidance, test materials, mind maps, and videos in the group. They are all dry goods, you can download and watch. Mainly share test foundation, interface test, performance test, automated test, TestOps architecture, Jmeter, LoadRunner, Fiddler, MySql, Linux, resume optimization, interview skills, and actual video data of large-scale test projects. Use every minute and every second of your time to learn to improve yourself, and don't use "no time" to conceal your mental laziness! Try hard while you are young, and give your future self an explanation!

Public number: Programmer Erhei, after paying attention, you can receive a large amount of learning materials for free.

Good things should be shared with friends
 

Guess you like

Origin blog.csdn.net/m0_52668874/article/details/114703151