Test Overview
This test opens a web page and verifies that a button is present using Selenium's PageFactory to initialize web elements.
This test opens a web page and verifies that a button is present using Selenium's PageFactory to initialize web elements.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.chrome.ChromeDriver; import org.junit.jupiter.api.*; public class PageFactoryTest { WebDriver driver; @FindBy(id = "submit-btn") WebElement submitButton; @BeforeEach public void setUp() { driver = new ChromeDriver(); driver.get("https://example.com"); PageFactory.initElements(driver, this); } @Test public void testSubmitButtonIsDisplayed() { Assertions.assertTrue(submitButton.isDisplayed(), "Submit button should be visible"); } @AfterEach public void tearDown() { driver.quit(); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | JUnit test runner initializes the test class | - | PASS |
| 2 | Browser opens ChromeDriver | Chrome browser window opens | - | PASS |
| 3 | Navigates to https://example.com | Browser loads the example.com homepage | - | PASS |
| 4 | PageFactory initializes elements annotated with @FindBy | submitButton WebElement is linked to element with id 'submit-btn' | - | PASS |
| 5 | Checks if submitButton is displayed | submitButton element is visible on the page | Assert that submitButton.isDisplayed() returns true | PASS |
| 6 | Test ends and browser closes | Chrome browser window closes | - | PASS |