Forum Discussion

rpd's avatar
rpd
Contributor
7 years ago

Can you create data-driven loop with 2 variables and can both variables iterate through their values

I have a data-driven loop in a desktop keyword test that contains 2 variables, Var1 and Var2. Var1 refers to a an Excel spreadsheet with just 5 rows of data in column 1. Var2  is a simple table of integers with 5 values, 100 - 104. For some reason,  I am not able to get both variables to ITERATE through their 5 values if both variables are referenced in the loop. However, if I remove or disable the one statement in the loop that references Var2, then Var1 will ITERATE through its 5 values? Shouldn't both variables ITERATE through their values? 

 

Please note that when I created the data-driven loop I only defined one variable, named Var1. Later on, I needed another variable so I then defined Var2. One thing that I am wondering about is that the statement containing the data-driven loop statement only refers to Var1. Could that be a problem?

 

Data-Driven Loop Var1 [Local] (Records from start to 5)

 

Also, I have the following questions:

 

1) If there is more than one reference to the SAME variable in the data driven loop, does the SAME value get used for each reference, only does the value change on each reference within the loop?

 

2) Is there any way to randomize the selection of values for the variables contained in a data-driven loop?

 

 

 

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    OK, I opened up your attached project... and I'm not seeing anything actual code in the project that includes these two loops...

     

    But, that said, in a Keyword Test, if you want to loop through two different files, you're doing a nested loop.  It would look something like this.

     

     

    Notice that the second loop is indented under the first.  This will cause both loops to iterate, the internal one will iterate once for each loop instance of the second loop.

     

    Now, if you want to loop through two different files simultaneously without nesting, I'm not sure you can do that in KeywordTests.  You can do it in Script Code using the DDT objects.  It would look something like this:


    function doubleLoop(){
        var loopData1 = DDT.CSVDriver(Project.Path + '\\KeywordTests\\test1.csv');
        var loopData2 = DDT.CSVDriver(Project.Path + '\\KeywordTests\\test2.csv');
        while (!loopData1.EOF() && !loopData2.EOF()){
            Log.Message('File 1 column 1 ' + loopData1.Value('column1') + ' and File 2 column 1 ' + loopData2.Value('column3'))
            loopData1.Next();
            loopData2.Next();
        } 
        DDT.CloseDriver(loopData1.Name);
        DDT.CloseDriver(loopData2.Name);
    } 
    • rpd's avatar
      rpd
      Contributor

       Were you SCRIPT language were you using in your answer relating to having 2 variables iterate through their values in the same data loop (ie. no NESTING of data loops)?

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        JavaScript... although, the syntax will work for JScript as well.