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 the TestComplete tool.
Table of Contents:
Data Driven Testing Using TestComplete Tool
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.
A 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?
High-level steps to data drive 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 credentials can go in.)
#7) Iterate on your full data set.
#8) Make improvements, once the happy path works, including exception handling steps.
For example, let the code know what to do if a failure comes up. If, say, your Row 10 login credentials fail, write the steps on what you want them to do.
- Do you want it to write the failure message in the log and move on to the 11th row?
- Do you want the script to be aborted?
- 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’s call it Learn Data Driven. Click on the Next button.
#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 SmarBear.
You can find the application at the following location
E.g: 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 these steps to record the test:
#1) Go to Test | Record | Record Keyword This will launch our application on which test is to be performed.
(Note: Click on any image for an enlarged view)
#2) Recording mode will start and the recording toolbar will be displayed. Click on the icon (as shown) to insert the comment.
#3) Now, Add comment dialogue box will appear, and in the dialogue box enter “Recording starts”. Click Add.
#4) Select Orders | New Order items from the menu of the launched application. This will open an order form.
#5) Add comment “Enter details of the order”.
#6) You can enter any value of your choice in the input fields.
For instance, you can use the following values
Field | Values |
---|---|
Product | My Money (dropdown) |
Quantity | 100 |
Price per unit | 20 Rs |
Discount | 5 % |
Total | 190 Rs |
Date | 4/9/2017 |
Customer Name | Ankitesh Kumar |
Street | Durga nursery road |
City | Udaipur |
Zip | 313001 |
Card Number | 1234-4567-9876 |
Expiration Date | 4/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.
#11) Click Stop, to stop the recording.
#12) Once TestComplete is ready with the TestScript, click on the Play button to ensure the recording process is executed successfully.
Creating Data Storage
To implement data driven testing we require a data set. We can store our data in Database tables, excel sheets etc.
In this tutorial, we are using an 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 out the image below.
- Alternately, you can select from the sample data textbook provided by TestComplete.
You can find the textbook at the following location:
E.g.: \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 on Make Data loop. This will open the Data Creation Wizard.
#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.
#4) On the next page of the wizard, we have the option to select the type of source for our data table. Since we are using an excel sheet as a source of data, select Excel worksheet.
#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 TestComplete at the following location
Eg: C:\Users\Public\Documents\TestComplete 12 Samples\Common\Data-Driven Testing\TestBook.xlsx
#7) Click Next. On the next page, all the sheets in the excel will be displayed. Select the sheet that contains the data. Since the sample Excel workbook contains only one sheet, Select it and Click Next.
#8) On this page, you can select the range of rows which are to be used for testing. Leave the default values and click Next.
#9) Now we have to select the input field parameters and click on [Use hard coded value].
#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 the 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, a 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, its 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 was a fun ride!
good article. Can you suggest how to validate PDF file content using Testcomplete [Window Application]
Thanks, Vivek for this detailed tutorial.
This is a great tutorial, very clear, thank you.
I have a question! 🙂
When a test (with a data loop that refers to data stored in a spreadsheet) runs, does the spreadsheet need to be opened and closed before the test can use it? I have tests like this that don’t use the data unless the spreadsheet is opened & closed before it tries to enter the data and I am wondering if I can avoid opening and closing the spreadsheet – it seems like a step that shouldn’t be required. I wonder if it’s a format thing with the spreadsheet file?
Any ideas?
Hi Sir,
Could you tell me how to skip the iteration while performing the data-driven testing using test complete tool.
Really very useful Tool and the way the steps provided is easy to remember ?
How to Launch Windows application using TestComplete Tool without recording.
Directly you should provide the path of windows application which you want to open while creating the project thats it thankyou.