Test Overview
This test demonstrates how to configure and run Selenium tests in parallel using TestNG. It verifies that two tests run simultaneously on different browsers and both pass successfully.
This test demonstrates how to configure and run Selenium tests in parallel using TestNG. It verifies that two tests run simultaneously on different browsers and both pass successfully.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Parameters; import org.testng.annotations.Test; public class ParallelTest { private WebDriver driver; @BeforeMethod @Parameters({"browser"}) public void setUp(String browser) { if (browser.equalsIgnoreCase("chrome")) { driver = new ChromeDriver(); } else if (browser.equalsIgnoreCase("firefox")) { driver = new FirefoxDriver(); } driver.manage().window().maximize(); } @Test public void openGoogle() { driver.get("https://www.google.com"); String title = driver.getTitle(); Assert.assertTrue(title.contains("Google")); } @AfterMethod public void tearDown() { if (driver != null) { driver.quit(); } } } /* TestNG XML configuration for parallel execution: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"> <suite name="ParallelSuite" parallel="tests" thread-count="2"> <test name="ChromeTest"> <parameter name="browser" value="chrome"/> <classes> <class name="ParallelTest"/> </classes> </test> <test name="FirefoxTest"> <parameter name="browser" value="firefox"/> <classes> <class name="ParallelTest"/> </classes> </test> </suite> */
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | TestNG suite starts with parallel tests configured for Chrome and Firefox browsers | TestNG initializes two test threads for ChromeTest and FirefoxTest | - | PASS |
| 2 | ChromeTest thread calls setUp with parameter 'chrome', ChromeDriver instance is created and browser window maximized | Chrome browser window is open and ready | - | PASS |
| 3 | FirefoxTest thread calls setUp with parameter 'firefox', FirefoxDriver instance is created and browser window maximized | Firefox browser window is open and ready | - | PASS |
| 4 | ChromeTest thread navigates to https://www.google.com | Chrome browser displays Google homepage | Page title contains 'Google' | PASS |
| 5 | FirefoxTest thread navigates to https://www.google.com | Firefox browser displays Google homepage | Page title contains 'Google' | PASS |
| 6 | ChromeTest thread calls tearDown and closes Chrome browser | Chrome browser is closed | - | PASS |
| 7 | FirefoxTest thread calls tearDown and closes Firefox browser | Firefox browser is closed | - | PASS |
| 8 | TestNG suite completes with both tests passing in parallel | No browsers open, test suite finished | Both tests passed successfully | PASS |