0
0
Selenium Javatesting~10 mins

Test suites (testng.xml) in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - TestNG
Selenium Java
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>
*/
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1TestNG suite starts -> ChromeDriver launches browserBrowser window opens maximized, blank page-PASS
2Navigate to https://www.google.com for testHomePageTitleGoogle homepage loads with title 'Google'Check page title equals 'Google'PASS
3Navigate to https://www.google.com for testSearchBoxPresentGoogle homepage loads with search box visibleVerify search box element with name 'q' is displayedPASS
4TestNG suite finishes -> Browser closesBrowser window closes-PASS
Failure Scenario
Failing Condition: If the Google homepage title is not 'Google' or search box is not found
Execution Trace Quiz - 3 Questions
Test your understanding
What does the testHomePageTitle test verify?
AThe search box is clickable
BThe page title is 'Google'
CThe browser opens maximized
DThe page URL contains 'google'
Key Result
Using a test suite XML file like testng.xml helps organize and run multiple tests together easily, improving test management and reporting.