This article provides a quick tutorial on how to use TestComplete's data driven testing feature with Excel spreadsheets.
Lets say youve been given a new application to test. It's called Contact Builder, and it's a quick way to enter information about people you know into your email client's address book. The application looks like this:
By completing the fields and clicking the OK button, you receive a message in the status field stating whether or not the contact was successfully added to your email client.
This has a couple of drawbacks. First, all your test data is hard coded. Second, if you want to test using different data in the fields, you'll have to copy and paste the above lines. This is very inefficient and can quickly become a script maintenance nightmare. Luckily, TestComplete has an answer to both these problems - data driven testing.
In a nutshell, data driven testing is a technique used to separate code from input data. This allows you to place your test data into separate files from your scripts. So, let's say we create an Excel file that contains all the input data we'll need for our test case. It has 10 columns; one for each text field, and one for the message that should be displayed after clicking the OK button. Let's say that we've saved this file as c:myTestData.xls, in a worksheet called myData. It would look something like this:
So now, we'll write some code that will loop over each row in the spreadsheet, enter the appropriate values, click the OK button and confirm the message that's displayed.
This is good, but the code could be cleaner. The DDT object has a built-in function called DriveMethod that allows you to run a specific function for each row in the spreadsheet. This eliminates the need for the loop in the example above, and allows us to further modularize the code. Let's also remove the Column Name/Index pairs and place them at the top of the unit. This will make them constants, and will keep us from having to redeclare them. So the new code would look like this:
Notice that in our new example, we're using DDT.CurrentDriver rather than inputData. This is because the Logger function doesn't know about the inputData object. It does know that there is a DDT object in memory, but it just doesn't know it by the name we assigned it in the test method. So the code above is going to use the DDT object that was last loaded into memory.
This tutorial should give you a good overview of how to use data driven testing and Excel spreadsheets in your test efforts. DDT is a powerful technique that can save you both time and lines of code. Once you've mastered it, you have a powerful tool in your automation arsenal. Nick Olivo
is the Automation Lead for a software company in Nashua, NH. When he's not coding or writing, he can usually be found watching Elmo with his son.