Testing / Selenium Interview questions
How do you run tests in parallel using TestNG and Selenium?
TestNG controls parallelism through its XML suite configuration rather than anything in Selenium itself - Selenium just needs each parallel thread to get its own independent driver instance.
<suite name="Suite" parallel="methods" thread-count="4"> <test name="Test"> <classes> <class name="tests.LoginTest"/> </classes> </test> </suite>
The parallel attribute can target methods, classes, or tests, and thread-count caps how many run concurrently. The critical piece on the Selenium side is making the WebDriver instance ThreadLocal, so each thread gets its own browser session instead of multiple threads fighting over one shared driver - sharing a single driver across parallel threads is one of the most common causes of chaotic, hard-to-debug parallel test failures.
More Related questions...