Forum Discussion

standardmodell's avatar
13 years ago

data-driven-loop on different db-connections

Hi,



I have a data-driven-loop using a DB-Table Variable in my project. The problem is that the connection string for the DB may vary. For example if I want to test the bugfix-db instead of the development-db.



Is it possible to change the DB-Table Variable in a script so that I first run the script setting the DB-Table Variable and then use the data-driven-loop?



I just figured out how I can handle the whole task using a script... something like this:




Sub TestProc

  set Kampagnen = ADO.CreateADOTable

  Kampagnen.ConnectionString = "connection_string..."

  Kampagnen.TableName = "table_name..."

  Kampagnen.Open

  Kampagnen.First

  For i = 0 To 9

'   Do everything what should be done in the designer

  Kampagnen.Next

  Next

  Kampagnen.Close

End Sub




...but thats not excatly what I want to do because this way I can't benefit from the "Test-Steps-Designer View".



Benjamin

1 Reply

  • Hi Benjamin,



    Currently, there is no way to programmatically change the connection string used by a DB Table variable during the test execution. You can only visually configure such a variable at design time. However, I would like to suggest you the following workaround:



       1. If you need to retrieve data from several database sources, create several DB Table variables in your keyword test at design time. Configure each variable so that it uses the appropriate connection string and retrieves data from the needed source. Let's suppose that you have two DB Table variables, DBVar1 and DBVar2.

       

       2. Create a helper DB Table variable (say, it is named DBVar3) to be used as your data-driven loop's variable. Note that you must specify a valid connection string for this helper variable at design time to properly add the Data-Driven Loop operation to your test. It doesn't matter what connection string you specify for this variable at design time. The string just must be valid, because the Data-Driven Loop operation's wizard requires valid settings to be specified when you add a new operation. For example, for this helper variable, you can specify the same settings as you specified for one of the other variables.



       3. Create a data-driven loop and specify the helper DB Table variable created in the previous step (DBVar3) as the data-driven loop's variable.

       

       4. Then, before executing your data-driven loop, you need to set the needed DB Table variable's value (for instance, DBVar1 or DBVar2) to this helper variable (DBVar3) in the test. So, the data-driven loop will use the data previously stored in the appropriate variable and retrieved from one of the needed sources and copied to the helper variable.

      

    A few notes on copying one DB Table variable's value to another variable. The Set Variable Value operation doesn't allow setting values of DB Table variables. Therefore, you need to assign one DB Table variable to another using one of the following approaches:



       1. Use the Call Object Method operation. When adding such an operation to the test, specify the following settings in the operation's wizard:

       

         a. In the edit box on the Specify Object page, type the following code snippet and click Next:

      

       
    KeywordTests.<test_name>.Variables


        

         b. On the Specify Method or Property page, select the appropriate method for setting a new value to the needed variable, that is, the method that is named like var_name [Set] (for instance, DBVar3 [Set]) and click Next.

      

         c. In the Value column of the table displayed on the Operation Parameters page, specify the variable whose value you want to be assigned to the helper variable and click Finish.

     

       2. Use the Run Code Snippet operation. In the operation's parameters, specify a code snippet that just assigns one variable to another. There is one important note: since you are using VBScript, you need to specify the assignment in the following way:

     

      
     



           Without using the Execute statement, the Run Code Snippet operation will interpret the '=' operator as a comparison, not as an assignment. This is caused by the specifics of the VBScript syntax.

     

    Although the second approach seems to be easier, I would recommend that you use the first one (the Call Object Method operation). The assignment will be performed a bit faster in this case during the test execution.

     

    Please let me know whether the described workaround helps you.