Forum Discussion

Bryant's avatar
Bryant
New Contributor
14 years ago

DDT - Nested Loops

Is there any way to construct a nested loop using DDT? TestComplete 7 only seems to support one instance of the DDT object at a time.

My goal is to be able to use part of a CSV file as its own CSV to populate part of a wizard in the application I'm testing. Since the wizard allows an arbitrary number of entries, I wanted to be able to add a variable number of entries to each item I create.

My base CSV looks something like this:

Item, Associated Entries

Item1, "Entries, Values

            Entry1, Value1

            Entry2, Value2"

Item2, "Entries, Values

            Entry3, Value3

            Entry4, Value4

            Entry5, Value5"

The idea would be for the main loop to open the wizard for each item, then add an entry for each of the associated entries using the specified values.

I could theoretically do this using a table variable and DDT, but that seems like a clumsy solution and prevents my team from easily plugging in csv files.

Any advice?

2 Replies


  • Hi Bryant,





    You can use the script below to accomplish your task:



    function Test()

    {

      var driver = DDT.CSVDriver("Path_to_the_CSV_file");

      while(!driver.EOF()) {

        Log.AppendFolder(driver.Value(0));

        var tempCSVPath = Project.Path + "\\Temp.csv";

        var file = aqFile.OpenTextFile(tempCSVPath, aqFile.faReadWrite, aqFile.ctUTF8, true); 

        file.Write(driver.Value(1));

        file.Close();

        var internalDriver = DDT.CSVDriver(tempCSVPath);

        while(!internalDriver.EOF()) {

          Log.Message(internalDriver.Value(0), internalDriver.Value(1));

          internalDriver.Next();

        }

        aqFileSystem.DeleteFile(tempCSVPath);

        Log.PopLogFolder();

        driver.Next();

      }

    }







    The script works with the CSV file that contains the following data:

    Item; Associated Entries

    Item1; "Entries; Values

    Entry1; Value1

    Entry2; Value2"

    Item2; "Entries, Values

    Entry3; Value3

    Entry4; Value4

    Entry5; Value5"
  • Bryant's avatar
    Bryant
    New Contributor
    Thanks David, we managed to put together a working test for that wizard using the template you gave us.

    Bryant