Master Login Automation

Practice login form automation on a free, interactive demo page โ€” fill fields, submit, and assert success and error states with Selenium, Cypress, or Playwright.

Login to Your Practice Account

Practice UI Automation for Secure Banking

Don't have an account? Register now

Explore common test scenarios for login functionality to enhance your automation practice.

How to Automate This Login Page

This login form is a classic first automation exercise. Practice filling inputs, submitting, and asserting the success and error states โ€” all handled entirely in your browser, nothing is sent anywhere.

The same scenario written for two popular frameworks. These use the stable id and data-testid locators documented in the cheat sheet below.

import { test, expect } from '@playwright/test';

const URL = 'https://www.qapractice.com/practice-login-form';

test('valid credentials log the user in', async ({ page }) => {
  await page.goto(URL);

  await page.getByTestId('login-email').fill('user@premiumbank.com');
  await page.getByTestId('login-password').fill('Bank@123');
  await page.getByTestId('login-submit').click();

  // Auto-retrying assertion waits for the success banner to appear
  await expect(page.getByTestId('login-success'))
    .toContainText('Login Successful');
});

test('invalid credentials show an error', async ({ page }) => {
  await page.goto(URL);

  await page.getByTestId('login-email').fill('wrong@example.com');
  await page.getByTestId('login-password').fill('nope');
  await page.getByTestId('login-submit').click();

  await expect(page.getByTestId('login-error'))
    .toContainText('Invalid');
});

test('submitting empty fields is rejected', async ({ page }) => {
  await page.goto(URL);
  await page.getByTestId('login-submit').click();
  await expect(page.getByTestId('login-error'))
    .toContainText('required');
});
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;

public class LoginTest {
  public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    driver.get("https://www.qapractice.com/practice-login-form");

    // Valid login
    driver.findElement(By.id("login-email")).sendKeys("user@premiumbank.com");
    driver.findElement(By.id("login-password")).sendKeys("Bank@123");
    driver.findElement(By.id("login-submit")).click();

    String message = wait.until(ExpectedConditions.visibilityOfElementLocated(
        By.cssSelector("[data-testid='login-success']"))).getText();
    assert message.contains("Login Successful") : "Expected success message";

    driver.quit();
  }
}

Every interactive element on this page exposes a stable id and/or data-testid so your scripts don't depend on brittle positions or styling.

Elementiddata-testidPlaywright locatorSelenium locator
Email inputlogin-emaillogin-emailgetByTestId('login-email')By.id("login-email")
Password inputlogin-passwordlogin-passwordgetByTestId('login-password')By.id("login-password")
Remember-me checkboxlogin-rememberlogin-remembergetByTestId('login-remember')By.id("login-remember")
Forgot-password linklogin-forgot-passwordlogin-forgot-passwordgetByRole('link', { name: 'Forgot password?' })By.linkText("Forgot password?")
Sign-in buttonlogin-submitlogin-submitgetByTestId('login-submit')By.id("login-submit")
Register linklogin-registerlogin-registergetByRole('link', { name: 'Register now' })By.linkText("Register now")
Success messageโ€”login-successgetByTestId('login-success')By.cssSelector("[data-testid='login-success']")
Error messageโ€”login-errorgetByTestId('login-error')By.cssSelector("[data-testid='login-error']")

Use these as a checklist to build your automation suite. Download them as a Markdown file to keep alongside your test project.

IDScenarioStepsExpected Result
TC01Valid login
  1. Enter user@premiumbank.com in the email field
  2. Enter Bank@123 in the password field
  3. Click Sign in
A success message "Login Successful! Welcome to Premium Banking." is shown.
TC02Both fields empty
  1. Leave email and password empty
  2. Click Sign in
Error "Email and Password are required" is shown.
TC03Missing password
  1. Enter a valid email
  2. Leave password empty
  3. Click Sign in
Error "Password is required" is shown.
TC04Missing email
  1. Leave email empty
  2. Enter any password
  3. Click Sign in
Error "Email is required" is shown.
TC05Invalid credentials
  1. Enter wrong@example.com
  2. Enter a wrong password
  3. Click Sign in
Error "Invalid email id and password" is shown; no success message.
TC06Password is masked
  1. Type any value into the password field
The characters are obscured (input type="password").
TC07Forgot-password navigation
  1. Click the "Forgot password?" link
The browser navigates to /forget-password.
TC08Register navigation
  1. Click the "Register now" link
The browser navigates to /register.