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 regarding 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.
Test automation involves executing the tests automatically, managing test data, and utilizing results to improve software quality. It’s a quality assurance measure, but its role consists of 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:
Here are the different types of tests that should be automated for a faster and more efficient testing cycle:
Read More: Key Elements of an Effective Test Automation Strategy
Test cases play a crucial role in automated testing. They are the building blocks for designing, executing, and validating computerized tests. Here are some key functions that test cases fulfill in the context of automated testing:
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:
Manual and automated test cases verify functionality but go differently for test case development.
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 google.com website in a Chrome Browser.
Read More: How to create Selenium test cases
To create the test script for the above test case example, instantiate a Chrome browser instance and navigate to the google.com 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:
<dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.5</version> <scope>test</scope> </dependency>
You need to create the test file under src/test/java, as shown below:
package test; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class MavenTest1{ public String baseUrl = "https://www.google.com/"; String driverPath = "C:\\Softwares\\chromedriver_win32 (1)\\chromedriver.exe"; public WebDriver driver ; @Test public void test() { // set the system property for Chrome driver System.setProperty("webdriver.chrome.driver", driverPath); // Create driver object for CHROME browser driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get(baseUrl); // get the current URL of the page String URL= driver.getCurrentUrl(); System.out.print(URL); //get the title of the page String title = driver.getTitle(); System.out.println(title); } @BeforeTest public void beforeTest() { System.out.println("before test"); } @AfterTest public void afterTest() { driver.quit(); System.out.println("after test"); } }
On executing the test case as TestNG test, it will launch the browser, navigate to google.com and give the following output on your IDE Console as seen below:
Try Automation Testing
Want more information on Automatic Sample Tester? Click the link below to contact us.