Data Driven Framework

October 3, 2016

In Data Driven framework the test data is kept separate from the actual scripts. So, if any change occurs in test data or if you have to test the script with multiple sets of test data, then no change is required in the script. This data can be kept in some external file like Excel Sheet or CSV file, or some database.

For example:
If we have to test a scenario like a login into facebook with some ten credentials that can be done using data-driven approach, keeping all these credential in some external file like an excel sheet.

Let us now design data-driven framework solution for above example. For this, we will be using Excel sheet, TestNG, Selenium WebDriver and APACHE POI.

Before, proceeding with this article, it is advisable to cover TestNG and Working with Excel Sheet.

Scenario to test with Data-Driven Framework:

  1. Open any browser say, Chrome.
  2. Navigate to http://www.facebook.com
  3. Read data from an excel sheet which has ten different pairs of credentials.
  4. Login to Facebook using these ten pairs of credentials.
Classes created:
  • Facebook login – which has a method to invoke browser, login into Facebook and close the browser.
  • Excel Driver – This class has methods to work with an excel sheet. Here, I am using the same class which we designed in the last article i.e. Working with Excel using POI apache API.

Code:

Excel Sheet which has Test Data:

data-driven-testing

Facebook Project:

In the below code there are four methods written

  1. setup – This method is with @BeforeMethod annotation of TestNG which means it will be executed before every test case. Here, we are simply invoking the chrome browser, setting up few configurations and then navigating to Facebook.
  2. facebook_login – This is the actual scenario to be executed, here we are passing test data to this method using dataProvider.
  3. getData – written with an annotation @DataProvider this method provides test data reading from an excel sheet. To read data from excel sheet we are using ExcelDriver class created in the last article.

Working with Excel:

Here, in this framework we worked with only one scenario, considering it a base, you can write multiple scripts to test with multiple test data.

This can also be extended to use POM (Page Object Model) design pattern, which I will be covering in next tutorial.

PS: For any questions queries or comment feel free to write us at saurabh@qatechhub.com or support@qatechhub.com. Happy Learning 🙂

Saurabh

About the Author

Saurabh

Follow Saurabh:

Leave a Comment: