Use Chained Locator to Speed Up Selenium WebDriver Tests
My father’s article “Optimize Selenium WebDriver Automated Test Scripts: Speed” is a well-received one, featured on Geek Culture. It contains some practical tips to make your Selenium tests run faster.
Optimize Selenium WebDriver Automated Test Scripts: Speed
Simple techniques to improve the execution speed of some automated test steps, up to 50X.
In this article, I will share another speed optimization tip for Selenium WebDriver tests.
Task: Locate a “queue” link on W3C WebDriver page
There are three “queue” links (with that exact text) on the W3C WebDriver page. The reason I chose this page: it is quite large, 1.8MB in size. So, the time-saving difference is more noticeable.
Please note the purpose of this exercise to solely find out potential time-saving gains using chained-locators.
Let’s see the speed differences first.
Timing: 0.83 Seconds.
Timing: 0.02 Seconds, ~40 times faster that the version above. Wow!
The test design for the first version:
- Find all the links with exact text “queue”
- Choose the selected one, e.g. the second one
The test design for the optimized version:
- Find one of its parent node by id, in this case,
- From the parent node, locate the link