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.

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.
- Email and password are required.
- Email is case-insensitive and surrounding spaces are trimmed; password is case-sensitive and never trimmed.
- Password length on this form is 8 to 64 characters.
- Wrong email or wrong password shows the same message: "Email or password is incorrect".
- After 5 failed attempts in a row the account locks for 15 minutes.
- Unverified accounts cannot log in and see "Please verify your email".
- "Remember me" keeps the user signed in for 30 days; without it the session ends when the browser closes.
- 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):
| Partition | Lengths to test | Expected |
|---|---|---|
| Too short (invalid) | 7 | Rejected |
| Valid | 8, 9, 63, 64 | Accepted if it matches the stored password |
| Too long (invalid) | 65 | Rejected 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
| Rule | R1 | R2 | R3 | R4 | R5 |
|---|---|---|---|---|---|
| Email registered | Y | Y | N | Y | Y |
| Password correct | Y | N | – | Y | Y |
| Email verified | Y | – | – | N | Y |
| Account locked | N | N | – | N | Y |
| Result | Logged in | Generic error | Generic error | Verify email | Locked 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
| ID | Title | Preconditions | Steps and data | Expected result |
|---|---|---|---|---|
| TC_LOGIN_001 | Valid login goes to dashboard | Verified user qa.user@example.com exists | Open /login, enter email and correct password, click Sign in | Dashboard opens and shows the user's name |
| TC_LOGIN_002 | Wrong password shows generic error | Same user | Enter correct email, password WrongPass1 | "Email or password is incorrect"; stays on /login; password field cleared |
| TC_LOGIN_003 | Unknown email shows the same error | No account for nobody@example.com | Enter nobody@example.com, any password | Exactly the same message as TC_LOGIN_002 |
| TC_LOGIN_004 | Email is case-insensitive and trimmed | Verified user | Enter " QA.User@Example.com ", correct password | Logged in |
| TC_LOGIN_005 | Password is case-sensitive | Password is Valid@123 | Enter valid@123 | Generic error |
| TC_LOGIN_006 | 4 failures do not lock | Counter at 0 | Fail 4 times, then correct password | Logged in |
| TC_LOGIN_007 | 5th failure locks the account | Counter at 0 | Fail 5 times, then correct password | Locked message; not logged in |
| TC_LOGIN_008 | Unverified user is blocked | Unverified user exists | Enter its correct credentials | "Please verify your email"; no session created |
| TC_LOGIN_009 | Remember me keeps session | Verified user | Tick Remember me, log in, close and reopen browser | Still signed in |
| TC_LOGIN_010 | Redirect back after login | Logged out | Open /account/orders, get sent to login, log in | Lands 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:
| Field | What to write |
|---|---|
| Test case ID | TC_LOGIN_001 |
| Title | Behaviour in one line, e.g. "Wrong password shows generic error" |
| Requirement | Rule or acceptance criterion it proves |
| Priority | High / Medium / Low, based on risk |
| Preconditions | User state and setup (verified, locked, logged out) |
| Test data | Exact email and password used |
| Steps | Numbered actions |
| Expected result | Exact message, page and state |
| Actual result / Status | Filled in during execution |
More writing tips are in test case writing best practices.
4. Functional and validation examples (12)
- Valid email and password → dashboard.
- Valid email, wrong password → generic error.
- Unregistered email → same generic error.
- Empty email → "Email is required".
- Empty password → "Password is required".
- Both empty → both messages; no request sent.
- Invalid email format (qa.example.com) → format message.
- Email with surrounding spaces → trimmed and accepted.
- Email in mixed case → accepted.
- Password in wrong case → rejected.
- Remember me off → session ends when browser closes.
- Forgot password link → opens the reset page.
5. UI and accessibility examples (8)
- Password is masked by default.
- Show/hide toggle reveals the password and works with the keyboard.
- Tab order: email → password → Remember me → Sign in.
- Enter key submits the form.
- Each field has a visible label linked to its input.
- Error messages are announced by screen readers.
- Email and password fields allow the browser's password manager to fill them.
- 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)
- Login page and form submit only over HTTPS; HTTP redirects to HTTPS.
- Password never appears in the URL, logs or browser history.
- Lockout or throttling after the documented number of failures.
- Error message and response time do not reveal whether the email exists.
- SQL injection text (
' OR '1'='1) in email is treated as plain text. - Script text (
<script>alert(1)</script>) is shown escaped, never run. - Session cookie has HttpOnly, Secure and SameSite set.
- A new session ID is issued after login (no session fixation).
- Logout ends the session on the server; reusing the old cookie fails.
- 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)
- Remember me on → still signed in after browser restart.
- Session expires after the documented idle time.
- Logging in on a second device follows the product's rule (both allowed, or first signed out).
- Changing the password signs out other sessions, if that is the rule.
- Back button after logout does not show private data.
- Redirect back to the original page after login.
- Works in current Chrome, Firefox, Safari and Edge.
- Works on mobile with autofill and the on-screen keyboard.
- Login responds within the team's agreed time under normal load.
- Double-clicking Sign in sends one request and creates one session.
8. Common mistakes
| Mistake | Why it hurts | Fix |
|---|---|---|
| "An error appears" as expected result | Any error passes, even the wrong one | Write the exact message and page |
| Testing password strength on login | Strength rules belong to signup and change password | Only check the stored credential at login |
| Different messages for wrong email and wrong password | Reveals which emails are registered | Assert both messages are identical |
| One shared test user for every case | Lockout cases break other cases | Create a fresh user per case or reset state |
| Skipping the boundary just below the limit | Off-by-one bugs slip through | Test 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:
- 2 failures → no CAPTCHA.
- 3 failures → CAPTCHA shown on the next attempt.
- 3 failures, then correct password with correct CAPTCHA → logged in, counter resets (confirm this rule with the product owner first).
- 4 failures → CAPTCHA still shown, not locked.
- 5 failures → locked; correct password is refused.
- Wait 15 minutes after lock → correct password works.
- 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.
