Test Overview
This test opens a web page, logs in using reusable methods from a test framework, and verifies the user dashboard loads. It shows how framework design with reusable components helps scale tests easily.
This test opens a web page, logs in using reusable methods from a test framework, and verifies the user dashboard loads. It shows how framework design with reusable components helps scale tests easily.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.junit.jupiter.api.*; public class LoginTest { static WebDriver driver; @BeforeAll public static void setup() { driver = new ChromeDriver(); driver.manage().window().maximize(); } @AfterAll public static void teardown() { if (driver != null) { driver.quit(); } } // Reusable login method from framework public void login(String username, String password) { driver.get("https://example.com/login"); WebElement userField = driver.findElement(By.id("username")); WebElement passField = driver.findElement(By.id("password")); WebElement loginButton = driver.findElement(By.id("loginBtn")); userField.sendKeys(username); passField.sendKeys(password); loginButton.click(); } @Test public void testUserDashboardLoads() { login("testuser", "testpass"); WebElement dashboardHeader = driver.findElement(By.id("dashboardHeader")); Assertions.assertEquals("Welcome, testuser!", dashboardHeader.getText()); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Chrome browser window is open and maximized | - | PASS |
| 2 | Navigates to https://example.com/login | Login page is loaded with username, password fields and login button | - | PASS |
| 3 | Finds username and password input fields and login button | All elements are present and interactable | - | PASS |
| 4 | Enters username 'testuser' and password 'testpass', then clicks login | Login form submitted, page starts loading user dashboard | - | PASS |
| 5 | Finds dashboard header element by id 'dashboardHeader' | Dashboard page loaded with header visible | Verify dashboard header text equals 'Welcome, testuser!' | PASS |
| 6 | Test ends and browser closes | Browser closed, test complete | - | PASS |