How To Make Your Selenium Scripts Faster

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:

  1. Use fast selectors
  2. Use fewer locators
  3. Create atomic tests
  4. Don’t test the same functionality twice
  5. Write good tests
  6. Use only explicit waits
  7. Use the chrome driver
  8. Use drivers for headless browsers
  9. Re-use the browser instance
  10. Run scripts in parallel
  11. Use HTTP parse libraries
  12. Pre-populate cookies
  13. 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/

Togrul Kazimov

Business Analyst at McKinsey

4 年

Can you suggest way to use 13th advice?

回复
Usama Akram

Data Engineer at VIRIDIEN

6 年

hey how we can disable images? can u tell me?

Anju Yadav

Director at Veloxhire.AI - Helping companies hire 5x faster with AI

9 年

Nice post

回复
Deepthi Prabhakaran MCD,MCIA,CSM?

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 "

回复
Sanjay Dubey

Test Automation Consultant | Learner | Web | API | Java | Python | DevOps

9 年

Nice post Alex

回复

要查看或添加评论,请登录

Alex Siminiuc的更多文章

社区洞察

其他会员也浏览了