Test Overview
This test checks that the login page loads correctly and the login button is visible. It verifies the page is ready for user interaction, which is important as organizations scale test suites to ensure reliability and speed.
This test checks that the login page loads correctly and the login button is visible. It verifies the page is ready for user interaction, which is important as organizations scale test suites to ensure reliability and speed.
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class LoginPageTest { @Test public void testLoginPageLoads() { System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); WebDriver driver = new ChromeDriver(); try { driver.get("https://example.com/login"); WebDriverWait wait = new WebDriverWait(driver, java.time.Duration.ofSeconds(10)); WebElement loginButton = wait.until( ExpectedConditions.visibilityOfElementLocated(By.id("login-button")) ); assertTrue(loginButton.isDisplayed(), "Login button should be visible"); } finally { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | JUnit test runner initializes the test environment | - | PASS |
| 2 | ChromeDriver instance is created | Browser window opens, ready to navigate | - | PASS |
| 3 | Navigate to https://example.com/login | Browser loads the login page | - | PASS |
| 4 | Wait up to 10 seconds for login button to be visible using WebDriverWait and ExpectedConditions | Login page shows login button with id 'login-button' | Check if login button is visible | PASS |
| 5 | Assert login button is displayed | Login button is visible on the page | assertTrue(loginButton.isDisplayed()) | PASS |
| 6 | Close browser and quit driver | Browser window closes, resources freed | - | PASS |