0
0
Selenium Javatesting~10 mins

Test groups in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test demonstrates how to use test groups in Selenium with TestNG. It runs a login test that belongs to the 'smoke' group and verifies successful login by checking the page title.

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 LoginTest {
    WebDriver driver;

    @BeforeClass
    public void setUp() {
        driver = new ChromeDriver();
        driver.manage().window().maximize();
    }

    @Test(groups = {"smoke"})
    public void testValidLogin() {
        driver.get("https://example.com/login");
        WebElement username = driver.findElement(By.id("username"));
        WebElement password = driver.findElement(By.id("password"));
        WebElement loginButton = driver.findElement(By.id("loginBtn"));

        username.sendKeys("user1");
        password.sendKeys("pass123");
        loginButton.click();

        String expectedTitle = "Dashboard";
        String actualTitle = driver.getTitle();
        Assert.assertEquals(actualTitle, expectedTitle, "Page title should be Dashboard after login");
    }

    @AfterClass
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 10 Steps
StepActionSystem StateAssertionResult
1Test startsTestNG initializes and prepares to run tests-PASS
2Browser opens Chrome and maximizes windowChrome browser window is open and maximized-PASS
3Navigates to https://example.com/loginLogin page is loaded with username, password fields and login button-PASS
4Finds username input field by id 'username'Username input field is located-PASS
5Finds password input field by id 'password'Password input field is located-PASS
6Finds login button by id 'loginBtn'Login button is located-PASS
7Enters username 'user1' and password 'pass123'Username and password fields are filled-PASS
8Clicks login buttonLogin form submitted, page navigates to dashboard-PASS
9Checks page title equals 'Dashboard'Dashboard page is displayedAssert.assertEquals(actualTitle, expectedTitle)PASS
10Test ends and browser closesBrowser window is closed-PASS
Failure Scenario
Failing Condition: Page title after login is not 'Dashboard' due to failed login or navigation error
Execution Trace Quiz - 3 Questions
Test your understanding
Which step verifies that the login was successful?
AEntering username and password
BChecking the page title equals 'Dashboard'
CClicking the login button
DOpening the browser window
Key Result
Using test groups helps organize tests and run only relevant subsets, improving test suite efficiency and management.