How To Perform Data Driven Testing Using TestComplete Tool

Data Driven Testing using TestComplete (Part-II):

TestComplete is a UI as well as a functional automation tool. In our first article we have created simple Desktop and Web projects, recorded our test, played back and observed the results through Visual Analyzer.

We have extended this functionality to both Desktop and Web-based Applications.

In this tutorial, we will be covering Data Driven Testing using TestComeplete tool.

DataDriven Testing

Introduction

Automated test scripts, whether recorded or programmed, execute a set of actions on the application to test. In practice, we often have to run the same test on different sets of input data.

For instance, to test a form we might use a certain input data set. However, to make this test comprehensive you will probably have to plan to run it on different input values. So, the general approach of testing one functionality with multiple data values is what we call Data Driven Testing.

The common method to data drive a test is to import the data from a file and then utilize it in our test, instead of using hard coded values. Data Driven testing is a great way to save time and effort. It also improves test coverage thereby increasing the ROI on Test Automation

How is Data Driven Testing implemented in Test Automation?

The high-level steps to data driving a test can be listed as follows:

#1) Create a test script around a certain transaction/functionality. Identify the ones that need validation via multiple data sets.

#2) First test your test to see if it works for hard coded values/constants of one data set.

#3) Find out what is the best input source. It could be an Excel or connection to a database, etc.

#4) Populate your data source. If it is an excel sheet, create your data. If it is a database, find the query that mines that exact data that you need.

#5) Establish a connection between the data source and the automation script.

#6) Run one or two iterations first to debug and validate. (Keep in mind that for each iteration, the application on which you are testing should have the same start and end points.

For example, if you are testing a login operation with multiple credentials, make sure that after the first set of credentials are entered, you return the application back to the login page, so the second set of the credentials can go in.)

#7) Iterate on your full data set.

#8) Make improvements, once the happy path works, include exception handling steps.

For example, Let the code know what to do if a failure comes up. If say, the row 10 login credentials fail, write steps on what you want it to do.

  • Do you want it to write the failure message in a log and move on to the 11th row?
  • Do you want the script to abort?
  • Do you want it to wait for some manual entry, such as a mouse click or an alert OK, etc?

Implementing Data Driven Testing through TestComplete

#1) Click on File | New | New Project.

#2) Specify the name and location for the project. Let us name it as Learn data Driven. Click on Next button.

(Note: Click on any image for enlarged view)

TestComplete Project

#3) Now we need to define the type of application. In our case it is a desktop based application, so select Generic Windows application and click Next.

#4) Click on Add button and navigate to the location to add our application to the project. We will import a sample application provided by the SmarBear.

You can find the application at following location

Eg: C:\Users\Public\Documents\TestComplete 12 Samples\Desktop\Orders\C#\bin\Release\Orders.exe

#5) Click next, on this page of the wizard, you can enable/disable Test Visualizer. Click Next.

#6) On the last page of the wizard, select the VBScript scripting language and click on Finish.

Our project is ready for us to implement data-driven testing.

Record Test with One Iteration

We will begin by creating our script for one iteration of our sample application. The objective of our test is to create an order with the sample application and iterate it with different input values.

Follow steps to record the test:

#1) Go to Test | Record | Record Keyword This will launch our application on which test is to be performed.

Execute code

#2) Recording mode will start and recording toolbar is displayed. Click on the icon (as shown) to insert the comment.

Recording Toolbar

#3) Now, Add comment dialogue box will appear, in the dialogue box enter “Recording starts”. Click Add.

Add Comment

#4) Select Orders | New Order item from the menu of the launched application. This will open the order form.

Application

#5) Add comment “Enter details of the order”.

#6) You can enter any values of your choice in the input fields.

For instance, you can use the following values

FieldValues
ProductMy Money (dropdown)
Quantity100
Price per unit20 Rs
Discount5 %
Total190 Rs
Date4/9/2017
Customer NameAnkitesh Kumar
StreetDurga nursery road
CityUdaipur
Zip313001
Card Number1234-4567-9876
Expiration Date4/9/2017

#7) Click OK button.

#8) Add comment “Details of the order filled successfully”.

#9) Close the application by clicking the close button on the title bar of the application.


#10) Click No on the pop-up dialog box.

Close Software

#11) Click Stop, to stop the recording.

#12) Once TestComplete is ready with the TestScript, click on the Play button to ensure recording process is executed successfully.

Creating Data Storage

To implement data driven testing we require data set.  We can store our data in Database tables, excel sheets etc.

In this tutorial, we are using excel sheet to store our data, and using the same for our test.

Follow the steps below to create the data

  • Open Excel and create different columns for different input fields. Populate the data in these input values which will function as the data for the test. Check the image below.

Test Input Data

  • Alternately, you can select the sample data textbook provided by the TestComplete.

You can find the textbook at following location:

Eg: \Users\Public\Documents\TestComplete 12 Samples\Common\Data-Driven Testing\TestBook.xlsx

Modifying Test to use it for multiple data sets

Once we are ready with data, we need to modify our test so that the data from the Excel can be imported and used in our test.

#1) Locate the comment (Enter details of the order), click on it and press SHIFT and click on the comment (Details of the order filled successfully). This will select all the keywords lying between these two comments.

Logically, we need to select the keywords so as to populate the fields for different input values, or the process which we need to iterate multiple times.

#2) Right click on the selected keywords. Click Make Data loop. This will open Data Creation Wizard.

Data loop right click

#3) On the first page of the wizard, we can specify whether a new DB table is required or to use an existing data table. In our case, we are using a new DB table. Click Next.

New Variable

#4) On the next page of the wizard, we have options to select the type of source for our data table. Since we are using excel sheet as a source of data, select Excel worksheet.

Excel select

#5) Select Excel worksheet and Click Next.

#6) On the next page of the wizard, we need to specify the location of the excel file.

Note: You can use the sample “TestBook.xlsx” provided by the TestComplete at the following location

Eg: C:\Users\Public\Documents\TestComplete 12 Samples\Common\Data-Driven Testing\TestBook.xlsx

Path of excel

#7) Click Next. On the next page, all the sheets in the excel will be displayed. Select the sheet which contains the data. Since the sample Excel workbook contains only one sheet, Select it and Click Next.

TestSheet

#8) On this page, we can select the range of the rows which is to be used for testing. Leave default values and click Next.

Select top column

#9) Now we have to select the input field parameters and click on [Use hard coded value].

Data select

#10) Select the name of the column corresponding to the field that needs to be parameterized.

#11) Input parameter whose name coincides with the column name in the excel gets selected automatically.

#12) Once we have selected columns for the input values. Click on Finish button.

We have now modified our test for different input values and implemented data-driven testing using TestComplete.

Executing Test

Now let us execute the test. Click on the Play button. This will launch our test. As you can see tested application is launched and our test is executed for each data set.

Once the test has been executed, we can find the test results in the Test Log.

Conclusion

In addition to the automation of unit and functional tests, TestComplete offers Data Driven Testing which phenomenally improves test coverage. Even though data driven testing is not exclusively achieved through TestComplete, it’s simple GUI makes it very approachable and easy for testers.

Part III – The 3rd part of this series is Automating Android Applications using Test Complete”.

Give it a try and let us know how it goes! Happy data-driving your tests, it’s a fun ride! 




Recommended reading

2 comments ↓

#1 Haroon

Thanks, Vivek for this detailed tutorial.

#2 Vinothkumar

Really very useful Tool and the way the steps provided is easy to remember ?

Leave a Comment