Parallel execution means running multiple tests at the same time to save time and get faster results.
Click to reveal answer
intermediate
How do you configure parallel execution in TestNG?
You set the 'parallel' attribute in the TestNG XML file to 'tests', 'methods', or 'classes' and specify 'thread-count' to control how many tests run at once.
Click to reveal answer
intermediate
Why is thread safety important in parallel execution?
Thread safety ensures that tests running at the same time do not interfere with each other, preventing errors and unreliable results.
Click to reveal answer
advanced
What is a common problem when running Selenium tests in parallel and how to fix it?
A common problem is sharing the same WebDriver instance across tests, causing conflicts. Fix it by creating a separate WebDriver instance for each test thread.
Click to reveal answer
beginner
Example of TestNG XML snippet to run tests in parallel by classes with 3 threads:
Step 1: Understand thread-count and parallel attribute
parallel="tests" means tests run in parallel. thread-count="3" limits max parallel threads to 3.
Step 2: Apply thread-count to number of tests
There are 4 tests but only 3 threads, so 3 tests run simultaneously and 1 waits.
Final Answer:
3 tests run in parallel, 1 waits -> Option B
Quick Check:
thread-count limits parallel tests to 3 [OK]
Hint: thread-count limits max parallel tests running [OK]
Common Mistakes:
Assuming all tests run parallel ignoring thread-count
Confusing parallel="tests" with parallel="methods"
Ignoring that thread-count caps parallelism
4. You configured parallel="methods" and thread-count="2" in TestNG XML, but tests still run sequentially. What is the likely cause?
medium
A. TestNG does not support parallel execution
B. thread-count must be set to 1 for parallel methods
C. Test methods share state and are not thread-safe
D. parallel attribute should be set to "tests" for methods
Solution
Step 1: Understand parallel methods and thread safety
parallel="methods" runs test methods in parallel only if they are thread-safe and independent.
Step 2: Identify cause of sequential execution
If tests share data or state, TestNG runs them sequentially to avoid conflicts.
Final Answer:
Test methods share state and are not thread-safe -> Option C
Quick Check:
Shared state blocks parallel method execution [OK]
Hint: Ensure test methods are independent for parallel execution [OK]
Common Mistakes:
Setting thread-count to 1 disables parallelism
Using wrong parallel attribute value
Believing TestNG lacks parallel support
5. You want to run test classes in parallel but ensure each class uses its own WebDriver instance to avoid conflicts. Which TestNG XML configuration is best?
hard
A. <suite name="Suite" parallel="instances" thread-count="4">
B. <suite name="Suite" parallel="tests" thread-count="4">
C. <suite name="Suite" parallel="methods" thread-count="4">
D. <suite name="Suite" parallel="classes" thread-count="4">
Solution
Step 1: Understand parallel modes in TestNG
parallel="classes" runs test classes in parallel, isolating each class's WebDriver instance.
Step 2: Match requirement to configuration
Running classes in parallel with thread-count=4 allows 4 classes to run simultaneously, each with its own driver.
Final Answer:
<suite name="Suite" parallel="classes" thread-count="4"> -> Option D
Quick Check:
parallel="classes" isolates WebDriver per class [OK]
Hint: Use parallel="classes" for separate WebDriver per class [OK]
Common Mistakes:
Using parallel="methods" causing shared driver issues
Choosing parallel="tests" which runs test tags, not classes
Using parallel="instances" which is less common and may confuse
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.