SoftwareTestPilot
Manual TestingPublished: Updated: · 1 week ago14 min read

How to Write Test Cases for a Login Page (Method + 40 Examples)

Write login page test cases step by step: turn the rules into test conditions, apply boundaries and a decision table, then use 40 ready examples and a template.

SoftwareTestPilot
QA Editorial Team
Share:XLinkedInWhatsApp
How to Write Test Cases for a Login Page (Method + 40 Examples): Manual Testing article cover, SoftwareTestPilot.com
How to Write Test Cases for a Login Page (Method + 40 Examples): Manual Testing article cover, SoftwareTestPilot.com

Short answer: to write test cases for a login page, first list the rules the login must follow (valid credentials, error messages, lockout, session, "Remember me"). Turn each rule into a test condition, pick test data with equivalence partitioning and boundary values, cover rule combinations with a decision table, then write each case with an ID, preconditions, steps, test data and one clear expected result. Finish with security, accessibility and session checks.

This guide walks through that method on a worked example, gives you a copyable template and 40 example cases, and ends with a practice exercise. If you are preparing for interviews, rehearse your answer in the QA Community.

1. What a good login test case looks like

A test case checks one behaviour and has one expected result you can mark pass or fail without arguing. "Test login" is not a test case. "Registered user with correct password is taken to the dashboard and sees their name" is.

Good login cases are:

  • Atomic – one behaviour per case, so a failure points to one cause.
  • Independent – each case sets up its own user and state; running order does not matter.
  • Specific – exact test data and exact expected message, not "an error appears".
  • Traceable – linked to the rule or acceptance criterion it proves.

For the difference between a scenario ("user logs in") and a case (the exact steps and data), see test scenario vs test case.

2. Worked example: from login rules to test cases

The rules below are an illustrative example, not taken from a real product. In a real project you would get them from the user story, acceptance criteria or by asking the product owner.

  1. Email and password are required.
  2. Email is case-insensitive and surrounding spaces are trimmed; password is case-sensitive and never trimmed.
  3. Password length on this form is 8 to 64 characters.
  4. Wrong email or wrong password shows the same message: "Email or password is incorrect".
  5. After 5 failed attempts in a row the account locks for 15 minutes.
  6. Unverified accounts cannot log in and see "Please verify your email".
  7. "Remember me" keeps the user signed in for 30 days; without it the session ends when the browser closes.
  8. After login the user returns to the page they came from, or the dashboard by default.

Step 1: Ask questions before writing

Unclear rules create wrong expected results. For this example you would ask: does the lock counter reset after a successful login? Does a locked account show a different message (which would reveal that the email exists)? Is the 64-character limit enforced on the server too, or only in the browser?

Step 2: List the test conditions

A test condition is something that can be checked. From the rules: required fields, email normalisation, password case, password length, generic error, lockout at the 5th failure, unverified account, session length with and without "Remember me", redirect after login.

Step 3: Choose test data with partitions and boundaries

Equivalence partitioning groups inputs that should behave the same; boundary value analysis tests the edges where bugs cluster. For the password length rule (8–64):

PartitionLengths to testExpected
Too short (invalid)7Rejected
Valid8, 9, 63, 64Accepted if it matches the stored password
Too long (invalid)65Rejected without a server error

Do the same for failed attempts: 4 failures (not locked), 5 failures (locked), and a correct password on attempt 6 (still locked). More practice is in boundary value analysis and equivalence partitioning examples.

Step 4: Cover combinations with a decision table

RuleR1R2R3R4R5
Email registeredYYNYY
Password correctYN–YY
Email verifiedY––NY
Account lockedNN–NY
ResultLogged inGeneric errorGeneric errorVerify emailLocked message

Each column becomes at least one test case. R2 and R3 together prove there is no user enumeration: the message must be identical.

Step 5: Write the cases

IDTitlePreconditionsSteps and dataExpected result
TC_LOGIN_001Valid login goes to dashboardVerified user qa.user@example.com existsOpen /login, enter email and correct password, click Sign inDashboard opens and shows the user's name
TC_LOGIN_002Wrong password shows generic errorSame userEnter correct email, password WrongPass1"Email or password is incorrect"; stays on /login; password field cleared
TC_LOGIN_003Unknown email shows the same errorNo account for nobody@example.comEnter nobody@example.com, any passwordExactly the same message as TC_LOGIN_002
TC_LOGIN_004Email is case-insensitive and trimmedVerified userEnter " QA.User@Example.com ", correct passwordLogged in
TC_LOGIN_005Password is case-sensitivePassword is Valid@123Enter valid@123Generic error
TC_LOGIN_0064 failures do not lockCounter at 0Fail 4 times, then correct passwordLogged in
TC_LOGIN_0075th failure locks the accountCounter at 0Fail 5 times, then correct passwordLocked message; not logged in
TC_LOGIN_008Unverified user is blockedUnverified user existsEnter its correct credentials"Please verify your email"; no session created
TC_LOGIN_009Remember me keeps sessionVerified userTick Remember me, log in, close and reopen browserStill signed in
TC_LOGIN_010Redirect back after loginLogged outOpen /account/orders, get sent to login, log inLands on /account/orders

Step 6: Check coverage

Map every rule to at least one case: rule 1 needs the empty-field cases from section 4, rule 2 is TC_004–005, rule 3 is the length table, rule 4 is TC_002–003, rule 5 is TC_006–007, rule 6 is TC_008, rule 7 is TC_009 plus its opposite, rule 8 is TC_010. Any rule with no case is a gap.

3. Login test case template

Copy these columns into a spreadsheet or your test management tool:

FieldWhat to write
Test case IDTC_LOGIN_001
TitleBehaviour in one line, e.g. "Wrong password shows generic error"
RequirementRule or acceptance criterion it proves
PriorityHigh / Medium / Low, based on risk
PreconditionsUser state and setup (verified, locked, logged out)
Test dataExact email and password used
StepsNumbered actions
Expected resultExact message, page and state
Actual result / StatusFilled in during execution

More writing tips are in test case writing best practices.

4. Functional and validation examples (12)

  1. Valid email and password → dashboard.
  2. Valid email, wrong password → generic error.
  3. Unregistered email → same generic error.
  4. Empty email → "Email is required".
  5. Empty password → "Password is required".
  6. Both empty → both messages; no request sent.
  7. Invalid email format (qa.example.com) → format message.
  8. Email with surrounding spaces → trimmed and accepted.
  9. Email in mixed case → accepted.
  10. Password in wrong case → rejected.
  11. Remember me off → session ends when browser closes.
  12. Forgot password link → opens the reset page.

5. UI and accessibility examples (8)

  1. Password is masked by default.
  2. Show/hide toggle reveals the password and works with the keyboard.
  3. Tab order: email → password → Remember me → Sign in.
  4. Enter key submits the form.
  5. Each field has a visible label linked to its input.
  6. Error messages are announced by screen readers.
  7. Email and password fields allow the browser's password manager to fill them.
  8. Form stays usable at 320px wide and at 200% zoom.

Accessibility rules come from WCAG 2.2; our accessibility testing guide shows how to check them.

6. Security examples (10)

  1. Login page and form submit only over HTTPS; HTTP redirects to HTTPS.
  2. Password never appears in the URL, logs or browser history.
  3. Lockout or throttling after the documented number of failures.
  4. Error message and response time do not reveal whether the email exists.
  5. SQL injection text (' OR '1'='1) in email is treated as plain text.
  6. Script text (<script>alert(1)</script>) is shown escaped, never run.
  7. Session cookie has HttpOnly, Secure and SameSite set.
  8. A new session ID is issued after login (no session fixation).
  9. Logout ends the session on the server; reusing the old cookie fails.
  10. Pages behind login return the login page or 401 when signed out.

Check these against the OWASP Authentication Cheat Sheet. For the 401 vs 403 difference, read HTTP status code for unauthorized request.

7. Session, compatibility and performance examples (10)

  1. Remember me on → still signed in after browser restart.
  2. Session expires after the documented idle time.
  3. Logging in on a second device follows the product's rule (both allowed, or first signed out).
  4. Changing the password signs out other sessions, if that is the rule.
  5. Back button after logout does not show private data.
  6. Redirect back to the original page after login.
  7. Works in current Chrome, Firefox, Safari and Edge.
  8. Works on mobile with autofill and the on-screen keyboard.
  9. Login responds within the team's agreed time under normal load.
  10. Double-clicking Sign in sends one request and creates one session.

8. Common mistakes

MistakeWhy it hurtsFix
"An error appears" as expected resultAny error passes, even the wrong oneWrite the exact message and page
Testing password strength on loginStrength rules belong to signup and change passwordOnly check the stored credential at login
Different messages for wrong email and wrong passwordReveals which emails are registeredAssert both messages are identical
One shared test user for every caseLockout cases break other casesCreate a fresh user per case or reset state
Skipping the boundary just below the limitOff-by-one bugs slip throughTest 4 and 5 failures, 7/8 and 64/65 lengths

9. Automating the core cases

Functional cases automate well. Here is TC_LOGIN_002 and TC_LOGIN_003 as one Playwright test. It is an example to adapt: the URL, labels and message are placeholders for your app, and this code was not run against a real site.

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

const GENERIC = 'Email or password is incorrect';

for (const [name, email] of [
  ['wrong password', 'qa.user@example.com'],
  ['unknown email', 'nobody@example.com'],
]) {
  test(`login shows generic error for ${name}`, async ({ page }) => {
    await page.goto('/login');
    await page.getByLabel('Email').fill(email);
    await page.getByLabel('Password').fill('WrongPass1');
    await page.getByRole('button', { name: 'Sign in' }).click();
    await expect(page.getByRole('alert')).toHaveText(GENERIC);
    await expect(page).toHaveURL(/\/login/);
  });
}

The locators follow the Playwright locators guide. Keep lockout and brute-force checks in a separate suite with their own users so they never lock the account other tests use.

10. Practice exercise

Task: the product adds one rule: "After 3 failed attempts, show a CAPTCHA; after 5, lock for 15 minutes." Write the boundary test cases for this rule.

Answer:

  1. 2 failures → no CAPTCHA.
  2. 3 failures → CAPTCHA shown on the next attempt.
  3. 3 failures, then correct password with correct CAPTCHA → logged in, counter resets (confirm this rule with the product owner first).
  4. 4 failures → CAPTCHA still shown, not locked.
  5. 5 failures → locked; correct password is refused.
  6. Wait 15 minutes after lock → correct password works.
  7. Wait 14 minutes → still locked.

11. Next steps

Practise the method on the API side with the free API Playground, which has a real login endpoint, then strengthen your interview answers with Interview Prep. Share your test cases for review in the QA Community.

Frequently asked questions

1.How many test cases should a login page have?
There is no fixed number. Write enough to cover every rule, every boundary and every rule combination that carries risk, then check that each rule maps to at least one case. For a typical email and password form that often lands between 30 and 50 cases.
2.What is the most important login test case?
Valid credentials log the user in, and wrong email or wrong password both show the same generic message. Together these prove the main flow works and that the page does not reveal which emails are registered.
3.How do I write negative test cases for login?
For each field and rule, ask what happens when the input is empty, the wrong format, too short, too long, the wrong case, or malicious text. Add state-based negatives too: locked, unverified and expired sessions.
4.Should I test password strength on the login page?
No. Strength rules belong on signup and change-password pages. The login page only checks whether the entered password matches the stored one.