0
0
Selenium Javatesting~10 mins

Why form testing validates user workflows in Selenium Java - Test Execution Impact

Choose your learning style9 modes available
Test Overview

This test checks if a user can successfully fill out and submit a login form. It verifies that the form accepts valid input and leads to the expected page, ensuring the user workflow works correctly.

Test Code - JUnit with Selenium WebDriver
Selenium Java
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;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class LoginFormTest {
    private WebDriver driver;
    private WebDriverWait wait;

    @BeforeEach
    public void setUp() {
        driver = new ChromeDriver();
        wait = new WebDriverWait(driver, 10);
    }

    @Test
    public void testValidLoginFormSubmission() {
        driver.get("https://example.com/login");

        WebElement usernameInput = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("username")));
        WebElement passwordInput = driver.findElement(By.id("password"));
        WebElement submitButton = driver.findElement(By.id("submit-btn"));

        usernameInput.sendKeys("validUser");
        passwordInput.sendKeys("validPass123");
        submitButton.click();

        wait.until(ExpectedConditions.urlContains("/dashboard"));
        String currentUrl = driver.getCurrentUrl();
        assertEquals("https://example.com/dashboard", currentUrl, "User should be redirected to dashboard after login");
    }

    @AfterEach
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser window is open and ready-PASS
2Navigates to https://example.com/loginLogin page is loaded with username, password fields and submit button visibleWaits until username input is presentPASS
3Finds username, password input fields and submit buttonAll form elements are located and interactable-PASS
4Enters 'validUser' into username fieldUsername field contains 'validUser'-PASS
5Enters 'validPass123' into password fieldPassword field contains 'validPass123'-PASS
6Clicks the submit buttonForm is submitted, page starts loading-PASS
7Waits until URL contains '/dashboard'Browser navigates to dashboard pageChecks current URL equals 'https://example.com/dashboard'PASS
8Test ends and browser closesBrowser window is closed-PASS
Failure Scenario
Failing Condition: If the submit button is not found or clicking it does not redirect to the dashboard page
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the submit button?
AThat an error message appears on the login page
BThat the username field is cleared
CThat the browser URL changes to the dashboard page
DThat the submit button becomes disabled
Key Result
Testing form submission validates the entire user workflow from input to navigation, ensuring the app behaves as a user expects.