How to Write Effective Test Cases for Web Applications (Manual & Automation)

Introduction

It is essential for testers to be able to create test cases effectively, as it ensures the smooth functioning of web applications. When test cases are well-organized, they cover more tests, have less mistakes, and are easier to automate.

In this guide, we’ll explore:
✔️ Best practices for writing test cases
✔️ Manual vs. Automation test case writing
✔️ Step-by-step examples with real scenarios
✔️ Common mistakes to avoid


Understanding Test Cases

What is a Test Case?

A test case is a set of conditions or steps that are used to check a feature in a web application. It includes inputs, expected outputs, and execution conditions.

Components of a Good Test Case

A well-structured test case should include:
✔️ Test Case ID – Unique identifier
✔️ Test Scenario – High-level description
✔️ Preconditions – Setup before execution
✔️ Test Steps – Clear and concise instructions
✔️ Expected Result – What should happen after execution
✔️ Postconditions – Cleanup after execution

Test Scenarios vs. Test Cases

  • Test Scenario: High-level overview of what needs to be tested (e.g., “Verify Login Functionality”).
  • Test Case: Specific actions to test the scenario (e.g., “Enter valid credentials and click login”).

Best Practices for Writing Effective Test Cases

Use Simple & Clear Language – Avoid ambiguity and complex jargon.
Write Reusable Test Cases – Generic test cases that can be used across projects.
Cover Positive & Negative Scenarios – Ensure both valid and invalid inputs are tested.
Use Realistic Test Data – Reflect actual user inputs for accuracy.
Prioritize Test Cases – High-risk functionalities should be tested first.
Maintain Consistency – Use a standard format for all test cases.
Avoid Duplication – Keep test cases unique and non-repetitive.


Manual Testing Approach: Writing Test Cases for Web Applications

Example: Login Functionality (Manual Test Case)

Test Case IDTC-001
Test ScenarioVerify login functionality with valid credentials.
PreconditionsUser must be registered with valid credentials.
Test Steps1. Open the login page.
2. Enter valid username and password.
3. Click the ‘Login’ button.
Expected ResultUser should be redirected to the dashboard.
PostconditionsUser should remain logged in until they manually log out.

Example: Login Functionality (Negative Test Case)

Test Case IDTC-002
Test ScenarioVerify login with invalid credentials.
PreconditionsUser does not exist or enters incorrect details.
Test Steps1. Open the login page.
2. Enter invalid username/password.
3. Click the ‘Login’ button.
Expected ResultError message: “Invalid username or password”.
PostconditionsUser remains on the login page.

Automation Testing Approach: Writing Test Cases with Selenium

In automation testing, we replace manual test steps with scripts that execute actions on the web application.

Example: Login Test Case in Selenium (Java + TestNG)

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class LoginTest {
WebDriver driver;

@BeforeTest
public void setup() {
System.setProperty("webdriver.chrome.driver", "path-to-chromedriver");
driver = new ChromeDriver();
driver.get("https://www.qaonlinetraining.com/wp-login.php");
}

@Test
public void validLoginTest() {
WebElement username = driver.findElement(By.id("username"));
WebElement password = driver.findElement(By.id("password"));
WebElement loginButton = driver.findElement(By.id("loginBtn"));

username.sendKeys("testuser");
password.sendKeys("password123");
loginButton.click();

String expectedURL = "https://www.qaonlinetraining.com/wp-login.php";
assert driver.getCurrentUrl().equals(expectedURL) : "Login Failed!";
}

@AfterTest
public void tearDown() {
driver.quit();
}
}

Explanation of the Code

✔️ Setup: Launches browser and opens login page.
✔️ Test Case: Enters valid credentials and verifies successful login.
✔️ Teardown: Closes browser after execution.


Training Demo Material (Hands-On Practice Section)

📌 Downloadable Resources:
Test Case Template (Excel Format) – Standard format to document test cases.
Test Case Writing Checklist – Ensures quality test cases.

📌 Interactive Challenge:
📝 Task: Write a test case for the “Forgot Password” functionality.
📩 Compare with Answer Key (Available for Download).


Common Mistakes to Avoid

Writing vague test steps – Steps should be detailed and clear.
Skipping negative test cases – Ensure invalid inputs are tested.
Not updating test cases – Keep them relevant to application changes.
Not testing boundary conditions – Example: Password length constraints.
Mixing multiple scenarios in one test case – Keep them modular.


Conclusion & Next Steps

📌 Key Takeaways:
✅ Effective test cases improve quality & reduce defects.
✅ Follow structured writing practices for clarity.
✅ Automate repetitive test cases using Selenium.
✅ Avoid common mistakes to ensure better test coverage.

📢 What’s Next?
🚀 Want to Master Test Case Writing? Join our Live Training Session on Manual & Automation Test Case Writing and get hands-on practice!

👉 Enroll Today! https://www.qaonlinetraining.com/software-testing-online-certification-training/#bookdemo

Free Automation Testing Tutorials: https://www.youtube.com/watch?v=QQ9Rgiq7eBQ

Gain knowledge in software testing and elevate your skills to outperform competitors.

Training Program Demo Timing Training Fees Action
Software Testing Online Certification Training Demo at 09:00 AM ET Starts at $1049 Book your demo
Software Testing Classroom Training in Virginia Demo at 01:00 PM ET every Sunday Starts at $1699 Book your demo
Selenium Certification Training Demo at 10:00 AM ET Starts at $550 Book your demo
Manual Testing Course Demo at 09:00 AM ET Starts at $400 Book your demo
SDET Course – Software Automation Testing Training Demo at 11:00 AM ET Starts at $550 Book your demo
Automation Testing Real-Time Project Training Demo at 10:00 AM ET Starts at $250 Book your demo
Business Analyst Certification Demo at 12:00 PM ET Starts at $550 Book your demo

Search for QA Testing Jobs, Automation Roles, and more…