Why do you need a Data Driven Framework?

Published on 2nd July 2020 blog, Test automation

As you progress in your test automation, your scripts will quickly get more complex and your test data sets get larger. You will now need to handle your test data separately to make your scripts independent of it.

Let us consider the example of the test scenario for an online book purchasing application, that we discussed in our previous blog. Here is how the scenario looks-

In this scenario file, the input data for Login i.e. the values for Username and Password are picked from the argument columns shown against it.

The login data is hardcoded in this test. It will mostly be the same data that we use across multiple tests and scenarios. When a password changes, we will need to update all these tests.

Instead it makes sense to keep it in one place and access it from there. This can help us accomplish 2 things-

1) The logic of the test is kept separate from the data. Test cases are edited only when there is a change in logic. Not for a change in data.

2) It reduces effort when data needs to be modified. There is only one place to change instead of multiple.

Now consider the steps of adding books and verifying total. The input data for the no. of books to be added to cart as well as the expected cart total are all going to be picked up from this scenario file.

But we would like to check that the cart handles normal values, zero values and negative values for book count and gives the total correctly. To do this we need multiple sets of input data and the same steps need to be repeated for each row of data.

In such cases of multiple test data sets, it does not make sense to manually keep changing the data and re-running the same test case to verify the functionality.

So, we need a framework to enable a testcase to be run repeatedly with multiple sets of data. This is called a Data Driven framework.

A Data-driven framework will prove beneficial to any automation tester because-

  • It enables us to store our test data in separate data files, separating it out of our script code
  • The data files act as a store for any reusable data that we may need for many tests
  • Enables our tests or steps within a test case to run repeatedly with multiple sets of data

 

The Challenge

Setting up a data-driven framework can be a challenge. Most test automation tools provide no straight-forward way of doing that. So, setting up a data driven framework often requires you to:

  • Write code to be able to read excel files,
  • Looping through rows to read the data
  • Importing files
  • The steps also vary for the type of data files you would want to use (like csv / .xls/ .xlsx etc)

It can get cumbersome and complex, leading to higher maintenance. Bad implementations abound where you need to edit your code every time you want to change the data file or sheet to use!

The Solution – with Sahi Pro’s Business-Driven Test Automation

Sahi Pro v9.0 brings you the concept of Business-Driven Test Automation (BDTA) that solves the problem of functional automation in a simple and elegant way.

Once you create your Business-Driven Test Automation scenario with Sahi Pro 9.0, you can then Data-drive that scenario

With its simple and intuitive UI, Sahi Pro 9.0 enables testers to

  • Set up data files (csv or excel) to store the test data
  • Automatically adds the test data to the data file
  • Groups the test data for different step within the data file (using Labels)
  • Automatically maps the test data to its step in the test case

all while keeping the test case readable and understandable.

It takes a few clicks and no manual creation of files, looping or reading of files is required.

You can, thus, automatically set up the scenario to pick up its data from a separate data file and re-execute itself with the provided data.

You can even perform Data Drive and Extract your data when the keywords are not yet implemented – that means you can set up your data driven framework even when the application under test is not ready!

This gives a big advantage to testers to set up their tests and think of more possible test cases with regards to varying test data and document them by adding more rows to their test data files.

Sahi Pro will look at these rows when running tests and repeat the test / steps as many times as the rows, without you having to explicitly state it.

Example- For our Shopping Cart Application, the following scenario is Data Driven where

  1. The DATA column shows the name of Data file and the Label used to store data therein

Repeat and End tags demarcate the portion that needs to be executed repeatedly based on data.

 

The Data File for this Scenario shows

  1. The two labels store data for different steps
  2. Multiple rows in “BookDetails” label indicate different tests data input and expected total output combinations
  3. The steps will execute 4 times as per the no of rows of test data entered here

The execution report for this test shows that the steps ‘Add Books’ and ‘Verify Cart Total’ were executed 4 times, as per the number of data rows added in the data file.

Getting Started

Download a trial version of Sahi Pro to give BDTA a try –  https://crm.sahipro.com/pay/index.php/registration/register

A step-by-step guide to Data Drive your first Business Driven Test Automation scenario –

Here is the complete Playlist to take you end-to-end through BDTA concept and usage – https://www.youtube.com/watch?v=z7KBi4chxS4&list=PLahWnsaxlY7Q-A6WqHIRWor9k2n6uhz5r

Learn more about Sahi Pro v9.0 at – https://sahipro.com/docs/introduction/whats-new-in-sahi-pro-v9.0.0.html

Request for Demo – https://sahipro.com/request-demo/