How I made my Selenium Test Execution faster?


As your automation test suite grows, so does the execution time. What once took 5 minutes now takes 45, and that's unacceptable.
I once worked on a framework using Selenium with Cucumber and TestNG. I found the execution time took much longer and the scenarios ran one after another in line.
I searched something for parallel execution and got to know the easiest method to have it in my framework.
The Solution was to use Parallel Scenarios with TestNG’s DataProvider.
What this does:
The scenarios() method returns all your Cucumber scenarios
Marking it with @DataProvider(parallel = true) tells TestNG to run each scenario in a separate thread.
Let’s say if you have 30 scenarios and in sequential run it takes around 30 minutes for execution by using parallel test execution and thread count as 10 the test execution time will take around 3-4 minutes that’s around 80% of time reduction.
When you run tests in parallel, especially with @DataProvider(parallel = true) or TestNG’s parallel="methods", multiple threads execute simultaneously.
These threads share the same JVM memory space, but they don’t wait for each other. If your test setup isn't thread-safe, you can get test failures, flakiness, or browser crashes.
How to fix this issue?
Use ThreadLocal<WebDriver> to ensure each thread gets its own browser instance.
private static ThreadLocal<WebDriver> driver = new ThreadLocal<>();
Each test thread will now have its own driver — completely isolated.
Parallel execution can double or triple your test speed, but only if done correctly.
Subscribe to my newsletter
Read articles from Chetan Shinde directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Chetan Shinde
Chetan Shinde
SDET | Writing about test automation, Java, Selenium, and everything in between. Helping devs build better software through clean, reliable testing.