How To Make Your Selenium Scripts Faster
Many companies use today Selenium WebDriver for automating their web test cases.
This is not a surprise because the Selenium WebDriver framework is
? Free
? Open source
? Language independent
? Operating System independent
But the Selenium WebDriver scripts are typically slow.
What follows is a list of suggestions for making your Selenium WebDriver scripts faster.
Much faster...
Most of the suggestions work all the time.
Some of them work only in specific situations.
These suggestions can be used independently or together.
This list is probably incomplete so if you have other ideas for improving the Selenium scripts speed, please let me know.
One more thing.
If you want to learn more about Selenium in general or Selenium scripts performance in particular, please contact me.
Lets get started.
The Selenium WebDriver scripts are very slow because they interact with a site through the browser.
The scripts goes usually through the following phases
? Create the WebDriver object
? Open the browser
? Load the site in the browser
? Interact with the site’s elements
? Close the browser
? Close the driver object.
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
(new WebDriverWait(driver, 10)).until(new
ExpectedCondition<Boolean>()
{ public Boolean apply(WebDriver d)
{ return d.getTitle().toLowerCase().startsWith("cheese!"); } });
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
Any of these phases can make the Selenium script slow.
If the site is slow, the Selenium script is slow.
If the performance of the internet connection is not good, the Selenium script is slow.
If the computer running the script is not performing well, the Selenium script is slow.
The Selenium scripts can be faster with the help of the following changes:
- Use fast selectors
- Use fewer locators
- Create atomic tests
- Don’t test the same functionality twice
- Write good tests
- Use only explicit waits
- Use the chrome driver
- Use drivers for headless browsers
- Re-use the browser instance
- Run scripts in parallel
- Use HTTP parse libraries
- Pre-populate cookies
- Do not load images in the web page
READ THE FULL ARTICLE:
https://seleniumjava.com/2015/12/12/how-to-make-selenium-webdriver-scripts-faster/
Business Analyst at McKinsey
4 年Can you suggest way to use 13th advice?
Data Engineer at VIRIDIEN
6 年hey how we can disable images? can u tell me?
Director at Veloxhire.AI - Helping companies hire 5x faster with AI
9 年Nice post
MuleSoft Senior Consultant at VASS
9 年Alex: posted worthy link for selenium testers "Can you please tell me- 1. why your pointing to use Only Explicit Wait -why dont we use Implicit & Fluent wait 2. Why dont we load images in web pages? - if there is necessary to load the images must in the web page -is there any alternative way to load the iamges in web page "
Test Automation Consultant | Learner | Web | API | Java | Python | DevOps
9 年Nice post Alex