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 |