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.
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.
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.
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and ChromeDriver is initialized | Browser window opens with a blank page | - | PASS |
| 2 | Navigates to https://example.com | Browser displays the example.com homepage with a button having id 'start-button' | - | PASS |
| 3 | Finds the button element by id 'start-button' | Button element is located on the page | - | PASS |
| 4 | Clicks the button | Page navigates or updates to the Welcome Page | - | PASS |
| 5 | Gets the page title | Browser shows the Welcome Page | Check if page title equals 'Welcome Page' | PASS |
| 6 | Quits the browser | Browser window closes | - | PASS |