Boost Web Automation Speed: Parallel Testing with Cucumber & TestNG
At Halodoc, we simplify healthcare by leveraging a CI/CD environment to release and manage multiple features seamlessly. Achieving this requires robust testing. The automation suite must be executed with high efficiency and speed for rapid feature releases.
Executing automation test cases sequentially consumes considerable time and can hinder the release timeline. Utilizing parallel execution addresses this challenge, enabling quicker and more efficient delivery.
In this blog, we will discuss how we enabled and executed our existing web automation test cases in a parallel environment.
Benefits of Parallel Execution
- Reduces the test execution time
- Generates the test results very quickly compared to sequential execution
- Enables faster deployment of features to the production environment than sequential execution.
- Reduces resource utilization in cloud based environment
Migrating From Sequential to Parallel Execution: A Step-by-Step Journey
In Halodoc we use cucumber and testNG framework to implement and execute our test cases in a remote environment. Below are the steps we followed to migrate from seqential to parallel exection with the help of testNG parallel execution feature
1. Setting up pom.xml for Parallel Execution
Update your current pom.xml file to configure the thread count. This will allow us to launch N browsers and run N test cases in parallel.
When we attempted to run test cases with a higher number of threads, we observed increased CPU and memory utilization, which led to test case failures. To mitigate this, we conducted trial and error to determine an optimal thread count and found that setting it to 3 balanced performance and stability.
2. Configuring Cucumber for Parallel Execution
Updating the Existing Runner file with the below code to execute our current test cases in a parallel environment
3. Setting Up Parallel Execution in TestNG
Update your current TestNG configuration file by setting the parallel attribute to "methods" allowing each test method to run concurrently.
4. Handling Challenges in Parallel Execution
When running tests in a multi-threaded environment, even after implementing all necessary modifications, static variables can pose significant risks. Their shared nature across threads makes them susceptible to race conditions, data inconsistencies, and unpredictable test failures if not handled with proper synchronization.
To over come this we need to user below changes in our automation code
-
Leveraging ThreadLocal Variables In Automation Code: Leverage ThreadLocal to provide each thread with its isolated instance of a variable, preventing data conflicts in parallel execution.
Example: To prevent a single WebDriver instance from being shared across multiple threads, we utilize ThreadLocal variables along with getter and setter methods. This approach ensures that each thread maintains its own separate WebDriver instance, thereby avoiding concurrency issues.
-
Replacing Static Variables With Instance Variables: to Ensure Each Thread Gets Its Own Copy.
-
Utilizing Synchronized Blocks For Controlled Access: When shared resources are unavoidable, use synchronized blocks to ensure only one thread modifies the variable at a time, preventing race conditions.
-
CI/CD Pipeline Enhancements for Parallel Execution: There have been no changes to our CI/CD jobs or Cucumber reporting framework, our current setup effectively generates reports for both sequential and parallel executions.
Conclusion
Integrating parallel execution into our existing automation framework has reduced test case execution time by approximately 60% compared to sequential execution. This approach has enabled us to perform faster releases without compromising build quality by promptly identifying and resolving issues.Adopting parallel Execution is a strategic approach to improve software quality and accelerate delivery timelines.
References

Join us
Scalability, reliability and maintainability are the three pillars that govern what we build at Halodoc Tech. We are actively looking for engineers at all levels and if solving hard problems with challenging requirements is your forte, please reach out to us with your resumé at careers.india@halodoc.com.
About Halodoc
Halodoc is the number 1 all around Healthcare application in Indonesia. Our mission is to simplify and bring quality healthcare across Indonesia, from Sabang to Merauke. We connect 20,000+ doctors with patients in need through our Tele-consultation service. We partner with 3500+ pharmacies in 100+ cities to bring medicine to your doorstep. We've also partnered with Indonesia's largest lab provider to provide lab home services, and to top it off we have recently launched a premium appointment service that partners with 500+ hospitals that allow patients to book a doctor appointment inside our application. We are extremely fortunate to be trusted by our investors, such as the Bill & Melinda Gates Foundation, Singtel, UOB Ventures, Allianz, GoJek, Astra, Temasek, and many more. We recently closed our Series D round and In total have raised around USD$100+ million for our mission. Our team works tirelessly to make sure that we create the best healthcare solution personalised for all of our patient's needs, and are continuously on a path to simplify healthcare for Indonesia.