How to Optimize a Test and Make It 560% Faster
Sauce AI for Test Authoring: Move from intent to execution in minutes.|xBack to ResourcesBlogPosted
Sauce AI for Test Authoring: Move from intent to execution in minutes.
|
x
Blog
How to Optimize a Test and Make It 560 % Faster
Deep in the effectuation of every automated UI test endure the potential to turn something simple into something dim and unreliable—simply by adding extra Selenium commands. The data clearly show that long tests are less likely to pass. In this example report, I will exhibit you how to optimize a test and make it 560 % faster. We will do this by tackling inefficient use of Selenium commands.
Before optimizations
Too many Selenium command in a test can lead to tests that are dramatically slower and less reliable. Every Selenium command carries the potential for an invalid element locator or a synchronization issue.
Below we have a table that shows an automated test that was designed to click two radio button. V1 test is making 157 Selenium commands and take 95 seconds to execute. After optimizations, the like exact test execute 9 Selenium bid and runs in 17 seconds (5X faster).


Total examination run time V1

Number of web requests before optimization (V1)
What was the determination of this tryout?
The purpose of this trial was to simply snap two radio buttons on thisURL.

Identifying the inefficiencies
The major subscriber to the dim test time of such a simple test was the large number of unnecessary web requests.
Attempting to click first radio button
After load the URL, the trial takes ~60 seconds searching for random elements without taking a single action.

Unneeded bidding start at the 15-second mark and uphold until 1:19, at which point the factor is finally located and clicked.
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

Possible Waste: 60 sec on 1 element
Attempting to click 2d radio button
At 1:23, the trial starts looking for the Female radio push.

And finally clicks it at 1:28:

... but not before get 16 more Selenium commands to check whether the element is expose or choose.

Potential wastefulness: 3 seconds for every element.click ()
Post-click () Selenium commands
Finally, there is an interesting pattern of wasted web asking that happens after every element clink (). We can see that below:

It ’ s understandable that these are being performed to validate that the element is in the correct state after the performance of a click (). However, these actions are wasteful because Selenium would throw an error if the action wasn ’ t successful. Furthermore, the next activity would fail with an exception if it depended on the province of the premature element.
Possible waste: 2 seconds per element.click ()
The refactor use light exercise
The refactoring of this examination was exceedingly bare and required only a few minutes after realize the root cause of the problem. Furthermore, we saw that the final result of the refactoring make a examination that was 560 % faster and drastically more stable because it had fewer Selenium command.
Here ’ s the codification after we finished refactoring:

This is the and below is the screenshot.

Lessons learned
Bloated tests in the industry are infamously mutual and it ’ s something that I tackle on a weekly foundation. They typically get with a framework that we use for our automation. I ’ ve seen this with both OSS frameworks and especially homegrown ones. The key is to consider the impingement of extra Selenium commands on the overall automation program. In this use case, the tryout entourage execution time will be five times longer for the total organization. This obviously decreases the feedback cycle time and alsodo the automation less honest.
Principal Developer Advocate at Sauce Labs
Share this post
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free