0
0
Selenium Javatesting~10 mins

Custom annotations in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses a custom annotation to mark a Selenium test method. It verifies that the test navigates to a webpage, finds a button by its ID, clicks it, and checks the resulting page title.

Test Code - JUnit 5 with Selenium WebDriver
Selenium Java
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
@interface CustomTest {
}

@ExtendWith(CustomTestExtension.class)
public class CustomAnnotationTest {

    WebDriver driver;

    @CustomTest
    @Test
    public void testButtonClick() {
        driver = new ChromeDriver();
        driver.get("https://example.com");
        WebElement button = driver.findElement(By.id("start-button"));
        button.click();
        String title = driver.getTitle();
        assertEquals("Welcome Page", title);
        driver.quit();
    }
}

// CustomTestExtension would be implemented to process @CustomTest annotations, but is omitted here for brevity.
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test starts and ChromeDriver is initializedBrowser window opens with a blank page-PASS
2Navigates to https://example.comBrowser displays the example.com homepage with a button having id 'start-button'-PASS
3Finds the button element by id 'start-button'Button element is located on the page-PASS
4Clicks the buttonPage navigates or updates to the Welcome Page-PASS
5Gets the page titleBrowser shows the Welcome PageCheck if page title equals 'Welcome Page'PASS
6Quits the browserBrowser window closes-PASS
Failure Scenario
Failing Condition: Button with id 'start-button' is not found on the page
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the button?
AThe button becomes disabled
BThe URL changes to a login page
CThe page title changes to 'Welcome Page'
DAn alert popup appears
Key Result
Using custom annotations can help organize and extend test behavior, but the core Selenium steps like locating elements and assertions remain essential for verifying functionality.