Test Overview
This test runs two simple Selenium tests in parallel using TestNG in a Continuous Integration (CI) environment. It verifies that both tests execute independently and pass without interference.
This test runs two simple Selenium tests in parallel using TestNG in a Continuous Integration (CI) environment. It verifies that both tests execute independently and pass without interference.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class ParallelTest { private WebDriver driver; @BeforeMethod public void setUp() { driver = new ChromeDriver(); } @Test(timeOut = 10000) public void testGoogleTitle() { driver.get("https://www.google.com"); String title = driver.getTitle(); Assert.assertEquals(title, "Google"); } @Test(timeOut = 10000) public void testBingTitle() { driver.get("https://www.bing.com"); String title = driver.getTitle(); Assert.assertEquals(title, "Bing"); } @AfterMethod public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | TestNG starts test suite with parallel execution enabled | TestNG initializes two test methods to run in parallel threads | - | PASS |
| 2 | First thread runs testGoogleTitle: opens Chrome browser | Chrome browser instance 1 opens at blank page | - | PASS |
| 3 | Second thread runs testBingTitle: opens Chrome browser | Chrome browser instance 2 opens at blank page | - | PASS |
| 4 | First thread navigates to https://www.google.com | Browser instance 1 shows Google homepage | Page title is 'Google' | PASS |
| 5 | Second thread navigates to https://www.bing.com | Browser instance 2 shows Bing homepage | Page title is 'Bing' | PASS |
| 6 | First thread asserts page title equals 'Google' | Title retrieved from browser instance 1 | Assert.assertEquals(title, "Google") | PASS |
| 7 | Second thread asserts page title equals 'Bing' | Title retrieved from browser instance 2 | Assert.assertEquals(title, "Bing") | PASS |
| 8 | First thread closes browser instance 1 | Browser instance 1 closed | - | PASS |
| 9 | Second thread closes browser instance 2 | Browser instance 2 closed | - | PASS |
| 10 | TestNG completes all parallel test executions | All tests finished with no failures | All assertions passed | PASS |