Test Overview
This test suite runs two simple Selenium tests using TestNG. It verifies that the Google homepage title is correct and that the search box is present.
This test suite runs two simple Selenium tests using TestNG. It verifies that the Google homepage title is correct and that the search box is present.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class GoogleTests { WebDriver driver; @BeforeClass public void setUp() { driver = new ChromeDriver(); driver.manage().window().maximize(); } @Test public void testHomePageTitle() { driver.get("https://www.google.com"); String title = driver.getTitle(); Assert.assertEquals(title, "Google"); } @Test public void testSearchBoxPresent() { driver.get("https://www.google.com"); WebElement searchBox = driver.findElement(By.name("q")); Assert.assertTrue(searchBox.isDisplayed()); } @AfterClass public void tearDown() { driver.quit(); } } /* testng.xml file content */ /* <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"> <suite name="GoogleTestSuite"> <test name="GoogleTests"> <classes> <class name="GoogleTests"/> </classes> </test> </suite> */
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | TestNG suite starts -> ChromeDriver launches browser | Browser window opens maximized, blank page | — | PASS |
| 2 | Navigate to https://www.google.com for testHomePageTitle | Google homepage loads with title 'Google' | Check page title equals 'Google' | PASS |
| 3 | Navigate to https://www.google.com for testSearchBoxPresent | Google homepage loads with search box visible | Verify search box element with name 'q' is displayed | PASS |
| 4 | TestNG suite finishes -> Browser closes | Browser window closes | — | PASS |
testng.xml file in Selenium testing?testng.xmltestng.xml file is used to define which tests to run and how to organize them.testng.xml?<suite>, inside it we define <test>, then <classes> and <class>.testng.xml snippet, what tests will run?<suite name="Suite1" parallel="tests" thread-count="2">
<test name="TestA">
<classes>
<class name="tests.LoginTest"/>
</classes>
</test>
<test name="TestB">
<classes>
<class name="tests.PaymentTest"/>
</classes>
</test>
</suite>parallel attribute in <suite>parallel="tests" means each <test> runs in parallel threads.testng.xml file but tests are not running:<suite name="Suite1">
<test name="Test1">
<class name="TestClass">
</class>
</test>
</suite><class> tag syntax<class> should be self-closing like <class name="TestClass"/> or empty without content.<class> which is invalid and causes tests not to run.<class> tag should be self-closing or empty, not with separate open and close tags [OK]LoginTest and PaymentTest in parallel but limit total threads to 1 in testng.xml. Which configuration achieves this?parallel="classes" runs test classes in parallel, and thread-count="1" limits to one thread, so classes run one at a time.Pass the test and this pattern moves unknown