top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

Different ways to implement Data Driven Testing in your automation framework

Data-driven testing is the creation of test scripts where test data and output values are read from data files instead of using the same hard-coded values each time the test runs. Providing hard-coded values directly in the script is not a good practice. Testers can create parameters of different scenarios, using data sets that the same code can run against to test how the application handles various inputs effectively. The test data sets can be provided through different external data sources which are as follows,  
1. Direct Data Table 
2. Excel sheet
 3. properties file 
4.Json 
5.XML  
Different approaches to DDT using external data sources:  
1. Direct Data Table
Connecting to a direct data table in the database and fetching the data using JDBC and using them for automating the test case. we first need to create a connection to our database table, retrieve the test data from it, and call our test method for every row in the table.This potentially generates a lot of results and subsequently a lot of test iterations. Even though this gives great test coverage, it also takes more time to execute all test cases. Especially when you use this approach in combination with Selenium WebDriver, you might want to use a narrower query (or limit the number of results returned) to prevent your test from taking too long to finish.  Here number of test iterations will be very similar to the number of records available in the data table. This process is known as parameterization.  Parameterization can be achieved using TestNG as well. In TestNG, we have one annotation known as @DataProvider. We can also parameterize when we are working on BDD Cucumber. we can use a scenario outline and provide the direct test data sets separated by pile line.
2. Excel sheet
The most accepted way to parameterize the test script is to use an Excel sheet in our automation framework and fetch the data from the Excel sheet then import it into automation testing tools to feed to the software under test. When using Selenium WebDriver, we can achieve data-driven testing by using third-party APIs like Apache Poi which supports read and write operations in excel files. This can be achieved by properly using of PoI interface with respect to excel files like HSSF or .xls and XSSF for .xslx files. This way of implementing data-driven testing helps improve test coverage, reusability of the code, and faster execution.
  3. properties file
We can use a properties file in our frame work to specify the test data in terms of keys and values. However, the data cannot be parameterized. The extension of this file is filename.properties. This file can be read using Java File Reader and by setting the path of the properties file.
4. Json 
Json is a lightweight format for storing and transporting data. It stores the data in a text format in an organized way which is easy to access. We can also have multiple sets of data in JSON. Reading data from Json file is done using JsonParser. Create a JsonParser instance to parse Json into a tree structure with any FileInputStream object by using the path of the source file as a parameter.
5.XML
XML files provide a structured way to store and manage test data, making it easier to automate and maintain your test scripts. You can expand your XML data-driven testing approach by adding more test data in the XML file. This way, you can easily test different scenarios without modifying the test script itself. XML data-driven testing allows you to separate test data from test logic, making it easier to maintain and update your test cases. Additionally, it enables you to perform comprehensive testing by running the same test scenarios with various input data sets.

24 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page