Want better speed for Selenium tests? Run them in parallel.

A few years ago, if anyone asked me how Selenium tests can become faster, my answer would be about:

  1. using fast selectors
  2. using fewer locators
  3. creating atomic tests
  4. not testing the same functionality twice
  5. writing good tests
  6. using only explicit waits
  7. using the chrome driver
  8. using drivers for headless browsers
  9. re-using the browser instance
  10. running scripts in parallel
  11. using HTTP parse libraries
  12. pre-populating cookies
  13. not loading images in the web page

────────────────────────────────────

Did anything change in the last few years?

  1. using fast selectors (minimal impact)
  2. using fewer locators (minimal impact)
  3. creating atomic tests (useful)
  4. not testing the same functionality twice (useful)
  5. writing good tests (useful)
  6. using only explicit waits (minimal impact but useful)
  7. using the chrome driver (useful)
  8. using drivers for headless browsers (useless; I don't remember the last time I used headless browsers)
  9. re-using the browser instance (useless; for tests to be truly independent, they should start in clean browsers)
  10. running scripts in parallel (essential)
  11. using HTTP parse libraries (useless; I don't remember the last time I used http parsing libraries)
  12. pre-populating cookies (useless; too much work for limited benefit)
  13. not loading images in the web page (useless)

────────────────────────────────────

Today, this list would be much shorter:

  1. running scripts in parallel in docker containers
  2. using the chrome driver
  3. creating atomic tests
  4. not testing the same functionality twice
  5. writing good tests

────────────────────────────────────

By default, Selenium tests are very slow because they

  • run on a site in a browser; the browser performance depends on the computer/container it is launched on
  • the site's performance depends on number of concurrent users, servers, bandwidth, etc

So, what can make a difference for the speed of Selenium tests?

Run them in parallel on as many docker containers as possible with pipelines like this:

pipeline {

agent any

stages {

stage ('Run All Jobs') {

parallel {

stage("Login") { steps { script {

runTestsFor("Login")

}  }  }  

stage('My Account') { steps { script {

runTestsFor("My Account")

}  }  }  

stage('Results') { steps { script {

runTestsFor("Results")

}  }  }  

stage('Cart') { steps { script {

runTestsFor("Cart")

}  }  }  

stage('User Registration') { steps { script {

runTestsFor("User Registration")

}  }  }  

}//parallel

}//Run All Jobs

}      

}

The pipeline has 5 stages with tests for different site features.

If all tests for each stage runs in a different docker container, you run all 5 stages in parallel.

This will not lead to a 5 times reduction in execution time.

But you will probably get the execution time reduced with 50%, maybe even more.

So, the only solution that really works for faster Selenium tests is running them in parallel in many, many docker containers.

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

Alex Siminiuc的更多文章

社区洞察

其他会员也浏览了