Data Driven Testing

Top  Previous  Next

Purpose

Data Driven Testing is an automated testing technique in which test case data is separated from test case logic.  Each set of test case data consists of input values and a set of expected output values.  The actual output values are compared to the expected output values to determine whether the test passed.

 

Usage

The Spreadsheet object is useful for implementing data-driven tests.  It allows you to connect to, query, and read an excel spreadsheet from your test script.  To create a data-driven test, you will:

 

1.Record a test.  The exact inputs you use for the recording will not matter as much as your interactions with the objects.  The following excerpt was recorded using www.google.com:

function Test()

{

       //Set Text SmarteSoft in q

       SeS('Obj1').DoSetText("SmarteSoft");

       //Click on btnG

       SeS('Obj2').DoClick();

}

The actions recorded were: (1) Type SmarteSoft into the search box. (2) Press the Google Search button.

 

2.Parameterize the Test() function. The Test() function has all of the procedural logic for the test.  Replace input values with variables.  Encapsulate the logic in a nested function with one parameter for each variable you created.  As an example, we will parameterize  the Test() function we created in step one:

function Test()

{

       function Logic(searchterm){  //our new function encapsulates the test logic

          //Set Text using searchterm

          SeS('Obj1').DoSetText(searchterm)  //here we changed a hard-coded value into a variable

          //Click on btnG

          SeS('Obj2').DoClick()

       }

       Logic("SmarteSoft") //don't forget to call your new function

}

 

3.Create the test case data.  In an excel spreadsheet, create a column for every variable in step two.  Add columns for any expected output values you wish to verify.  Each row is a test case.

 

In our google example, we only have one input value (searchterm) and we're not comparing any expected output values, so we will only need one column in our spreadsheet.  Save the spreadsheet in the test folder as searchterms.xls:

data driven testing,spreadsheet

 

 

4.Add spreadsheet to the test

Use "Add File(s)..." to add a spreadsheet to the test files:
TwoDialogsAddFileMenu

 

5.Attach Spreadsheet object to searchterms.xls

Drag the 'searchterms.xls' from files tree into appropriate place in your test source:

SpreadsheetDragFile

 

6.Use Spreadsheet to access the test case data.

 

In our example, we use a Spreadsheet object and run the test logic once for every row.

function Test()

{

       function Logic(searchterm){  

          //Set Text searchterm in q

          SeS('Obj1').DoSetText(searchterm)

          //Click on btnG

          SeS('Obj2').DoClick()

       }

 

       Spreadsheet.DoAttach('searchterms.xls', 'Sheet1');

 

       // Go through all rows

       while(Spreadsheet.DoSequential())

       {

               // Read cell value from column 0

               var term = Spreadsheet.GetCell(0);

               // Pass it into Logic function

               Logic(term);

       }

}