There are several types of automation testing frameworks available to use in selenium, but the three most commonly used selenium frameworks designed are shown in the below figure:
- Data-Driven Framework
- Keyword Driven Framework
- Hybrid Framework
- Data Driven Framework: Data-driven framework is designed to work with those applications where we want to test multiple sets of data than multiple functionalities of the application.
In data-driven framework, importance is given to Test Data in comparison to multiple functionalities of the application.
For example, data-driven framework is generally designed to test login webpage by different sets of Test Data.
- Keyword Driven Framework: Keyword-driven framework is designed to work with those applications where we want to test multiple functionalities of the application than Test Data.
In the keyword-driven framework, importance is given to multiple functionalities of the application in comparison to Test Data.
For example, suppose we have a railway reservation application that provides many features such as:
- log in to the application by entering credentials.
- Search Trains.
- Book Train tickets
- Cancel tickets.
- Train offers.
- PNR status
- View reports and so on.
To test these kinds of functionality in the application, we can test easily by designing keyword driven automation framework.
- Hybrid Framework: This framework is a combination of data-driven and keyword-driven frameworks. A hybrid framework is designed for those applications where we want to test multiple functionalities of application with different sets of Test Data.
That is, in hybrid framework, importance is given for Test Data and multiple functionalities of application.
After proper analysis of the application, you can decide what kind of framework is best suited for your needs and then you can easily design and structure of automation framework in selenium.
In this tutorial, we will learn the data-driven automation framework which is one of the most popular Automation Testing Frameworks in the current market.
A Data Driven Framework in selenium is a technique in which we keep input test data separate from the actual test script (code).
This framework is completely dependent on the input test data. There are two components in the data-driven framework. First is test script and second test data.
The test data set is created in external sources such as an excel file, CSV file, XML, or any database table. We then connect the test script with test data to get multiple sets of data to perform the software under test.
Take a look at the following block diagram of data driven framework.
In the data-driven framework, we store test data and expected output data/results in a separate data file so that a single script can execute all the test cases with multiple sets of data.
Let’s understand it with an example scenario. Assume that we need to test the login/Register to a webpage with 100 different data sets of usernames and passwords.
To test this login webpage, we have three different approaches:
1) Create 100 scripts, one for each data set, and execute each test one by one.
2) Change the data in the script every time and execute it multiple times.
3) Place all our test data in excel sheets, connect with test script, and execute the script multiple times with different data.
First two scenarios are laborious, time-consuming and of course boring. Hence, we should go towards the third approach in which we will implement the Data-Driven framework technique.
Where the multiple sets of usernames and passwords will be placed credentials in an excel sheet and passed the credentials to the code ( Java class file) to perform automation on the browser.
In addition, we can also easily control how much data needs to be tested. If necessary, we can easily increase the number of test parameters by adding more username and password fields to the excel file (or other sources).
Since we place the test data separate from test case. Therefore, we can easily modify the test case for a particular functionality without changing other portions of the code.
For example, suppose we want to modify the code for login functionality, we can modify related code just instead of modifying any other dependent portion in the same code.
Hope that you will have understood the need and importance of Data-driven framework in selenium.
In simple words, we need to implement a Data-Driven Framework when we have to execute the same test script with different sets of test data.
Data-Driven and Keyword-Driven are two popular approaches to creating automation frameworks in Selenium, and they differ in how test automation is designed and implemented. Here's a comparison of the two frameworks:
In a Data-Driven framework, test scripts are designed to handle different sets of data independently. Test data is typically stored in external files like Excel sheets, CSV files, or databases.
The same test script is executed multiple times with different input data to test various scenarios.
Reusability: Test scripts are generic and can be reused for multiple sets of data.
Scalability: Easily add more test cases by providing additional data.
Maintenance: Test data can be updated without modifying the test script.
Managing test data: You need to create and maintain data sources.
Limited test logic: Data-Driven tests may not handle complex, conditional logic well.
In a Keyword-Driven framework, test scripts are designed to use a set of keywords that represent actions and validations.
A test case consists of a series of keywords, and the framework interprets and executes them to perform the actions and validations required.
Abstraction: Separation of test steps and test logic using keywords.
Non-technical test creation: Test cases can be written in plain English or other human-readable languages, making it accessible to non-technical team members.
Reusability: Keywords can be reused across multiple test cases.
Initial setup: Creating a library of keywords and the infrastructure to interpret and execute them.
Learning curve: Team members need to learn how to work with keywords.
Maintenance: Changes in the application or test scenarios may require updates to the keyword library.
Data-Driven focuses on variations in input data.
Keyword-Driven focuses on defining test steps and actions in a more abstract manner.
Both frameworks promote reusability, but in different ways.
Data-Driven reuses test scripts with different data.
Keyword-Driven reuses keywords to build test cases.
Data-Driven is simpler, while Keyword-Driven requires a more complex setup for managing keywords and their execution.
Data-Driven simplifies maintenance for changes in test data.
Keyword-Driven simplifies maintenance for changes in test steps by modifying keywords.
Test Case Creation:
Data-Driven is more technical, focusing on data.
Keyword-Driven can be more user-friendly, allowing non-technical team members to create and understand test cases.
Both frameworks are scalable, but Keyword-Driven may offer more flexibility as you can create new test cases by combining existing keywords.
In practice, you can also combine Data-Driven and Keyword-Driven approaches. For instance, you can use Data-Driven testing within a Keyword-Driven framework to handle data variations while still defining test steps with keywords. The choice between these frameworks depends on the specific requirements of your project, the skills of your team, and the complexity of your application.