App & Browser Testing Made Easy

Give your users a seamless experience by testing on 3000+ real devices and browsers. Don't compromise with emulators and simulators

Home Guide How to Create Test Cases for Automated tests?

How to Create Test Cases for Automated tests?

By Neha Vaidya, Community Contributor -

Table of Contents

Test cases define the sequence of actions required to verify the system functionality. A typical test case consists of test steps, preconditions, expected results, and actual results. QA teams usually create test cases from test scenarios. These test scenarios provide a high-level overview of what QA should test in terms of user workflows and end-to-end functionality to confirm that the system satisfies customer requirements. In this article, let’s understand how to create test cases for automated testing.

Introduction to Test Automation

Test automation involves executing the tests automatically, managing test data, and utilizing results to improve software quality. It’s basically a quality assurance measure, but its role involves the commitment of the entire software production team. From business analysts to developers and DevOps engineers, getting the most out of test automation takes the inclusion of everyone.

It reduces the pressure on manual testers and allows them to focus on higher-value tasks – exploratory tests, reviewing test results, etc. Automation testing is essential to achieve maximum test coverage and effectiveness, shorten testing cycle duration, and greater result accuracy.

Before developing the automation test cases, it is essential to select the ideal test conditions that should be automated based on the following factors:

  • Tests that need to be executed across multiple test data sets
  • Tests that give maximum test coverage for complex and end-to-end functionalities
  • Tests that need to be executed across several hardware or software platforms and on multiple environments
  • Tests that consume a lot of time and effort to execute manually

Which tests should be automated?

Here are the different types of tests that should be automated for a faster and more efficient testing cycle:

How to write test cases for Automation?

Writing the automated test case is a complex task that requires a different method than its manual counterpart. Automation test cases should further break down workflows compared to manual test cases. Templates for automation test cases vary depending on the automation tools; still, they should all have the following components:

  • Specifications: The Test Case includes the details on the right application state for executing the test, including browser launch and logins.
  • Sync and wait statements: This allows the necessary time for the application to get to the required state before testing the actual functionality.
  • Test steps: Writing Test Steps includes data entry requirements, detailed steps on how to reach the next required state, and steps to return the application to its original state before test runs.
  • Comments to explain the approach.
  • Debugging statements to invoke any available debugging functionality that can be used for code correction to avoid flakiness of the tests.
  • Output statements that describe where and how to record the test results.

Both manual and automated test cases serve to verify functionality, but they go differently for test case development.

Try Test Automation on Real Devices

Creating a Test Case for Automated Test

To understand how to create a test case for test automation, build a test case on a scenario where the user has to navigate the website in a Chrome Browser.

  • Test Scenario: To authenticate a successful user login on
  • Test Steps:
    • Launch Chrome Browser
    • The user navigates to the URL.
  • Browser: Chrome v 86.
  • Test Data: URL of the Google.
  • Expected/Intended Results: Once the Chrome Browser is launched, the web page redirects to the webpage.
  • Actual Results: As Expected
  • Test Status: Pass/Fail: Pass

Converting a Test Case to Test Script for Automated Tests

To create the test script for the above test case example, instantiate a Chrome browser instance and navigate to the website using TestNG annotations. The actual test case is written under @Test annotation.

For using TestNG annotations, you need to either import external libraries or add maven dependency in your pom.xml file as seen below:


You need to create the test file under src/test/java, as shown below:

Create Test Cases for Automated Tests

package test;
import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.WebDriver; 
import org.testng.annotations.AfterTest; 
import org.testng.annotations.BeforeTest; 
import org.testng.annotations.Test; 
public class MavenTest1{ 
public String baseUrl = ""; 
String driverPath = "C:\\Softwares\\chromedriver_win32 (1)\\chromedriver.exe"; 
public WebDriver driver ; 
public void test() { 
// set the system property for Chrome driver 
System.setProperty("", driverPath); 
// Create driver object for CHROME browser 
driver = new ChromeDriver(); 
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
// get the current URL of the page 
String URL= driver.getCurrentUrl(); 
//get the title of the page 
String title = driver.getTitle(); 
public void beforeTest() { 
System.out.println("before test"); 
public void afterTest() { 
System.out.println("after test"); 

On executing the test case as TestNG test, it will launch the browser, navigate to and give the following output on your IDE Console as seen below:

Create Test Cases for Automated Tests


To optimize the Test Automation suite, it is essential to leverage cloud-based platforms like BrowserStack that offer a Cloud Selenium Grid of 3000+ real browsers and devices. Testing on Real Device cloud lets the QAs test under real user conditions, and thus improves the accuracy of the testing, making debugging easier. It also empowers teams to run concurrent Selenium tests on desired real device-browser combinations online. Without the limitations of emulators and simulators, testers can verify website functionality in real user conditions. They can accelerate testing time with parallel testing, and get results faster without compromising on accuracy.

On BrowserStack, testers can leverage integrations with a host of CI/CD tools like Jenkins, Travis, CircleCI, etc. They can also utilize multiple features for more comprehensive testing scenarios – Geolocation Testing, Network Simulation, Testing on dev environments.

Try Automation Testing for Free

Automation Testing Types of Testing

Featured Articles

How to make your Selenium test cases run faster

How to run failed test cases using TestNG in Selenium Webdriver?

Fundamentals of Writing Good Test Cases