Non-Iterative Data Driven Testing


Is there a way to data drive a step in a test script so that each time the script is run, the test step will select a different sequential row from the data source?


The solution is to save the number of the row into an XML file. Each time you execute the test, read the number of the row from the XML file and tell Test Studio to use this row from your data source. 

  1. Create an XML file which will contain the row number.
    1. Right-click somewhere in the project folder and select New > Text Document. Rename it to "IterationIndex.xml"
    2. Right-click on "IterationIndex.xml" > Edit and choose a program (Notepad, for example).
    3. Write the following code into the file:


    <?xmlversion="1.0" encoding="UTF-8"?>


  2. Create your data source, if you don't have one already. In my case this is an Excel file called "foo.xlsx" containing numbers from 1 to 20.


  4. Open or create your project in Test Studio.
    1. Start new project or open existing project
    2. Add the needed project references from Project Settings > Script Options (learn how to add an assembly reference in the Standalone version here).
      • Microsoft.Office.Interop.Excel
      • System.Xml
      • System.Xml.Linq
    3. Create a new Web Test.
    4. Add a Script Step and click on the View Class button.
    5. Create a method which will save the row number into the XML file:


      public void SaveValue(intnumVal)


          string path = @"C:\Box\NextRowOnEachRun\IterationValue.xml";

          XElement e = new XElement("IterationValue");

          e.Add(new XElement("numVal", numVal));




    7. Create a method which will load the row number from the XML file:



      public int LoadValue()


          string path = @"C:\Box\NextRowOnEachRun\IterationValue.xml";

          XElement e = XElement.Load(path);

          int numVal = int.Parse(e.Element("numVal").Value);


          return numVal;



    9. Create a method which will read the row from the Excel file:



      public string ReadingExcel()


          int rowValue = LoadValue();

          string input = @"C:\Box\NextRowOnEachRun\foo.xlsx";

          Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();

          Microsoft.Office.Interop.Excel.Workbook inputBook = app.Workbooks.Open(input, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

          Microsoft.Office.Interop.Excel.Worksheet inputSheet = (Microsoft.Office.Interop.Excel.Worksheet)((inputBook.Worksheets).get_Item(1));


          string value = ((Microsoft.Office.Interop.Excel.Range)inputSheet.Cells[rowValue, 1]).Text asstring; //this is ""


          app = null;


          if (rowValue < 20)




          else{ SaveValue(0); }


          return value;




      See this video to see how this sample works.