Forum Discussion

vxramad's avatar
vxramad
Contributor
13 years ago

updating task variables

could you please tell me on how to create and update task variables in script

8 Replies

  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi,


    I do not quite understand exactly what you mean by "task variables".

    If you mean load testing variables shown in the Variables table of the Tasks editor, there is no way to create and configure such variables from scripts. You can only do this visually via the Tasks editor.

    If you mean request variables, you can create and update them using methods and properties of the HTTPRequestVariables program object.

    If these are not what you mean, please clarify your query.


    Thanks.

  • I am testing a web site and i want to run a HTTP task for certain number of Vusers and login credentials.

    To do this i am dbl clicking tasks where i can declare variables depending on the type like list or constant.

    Then replaced the values in each request FORM with this variable, and create subsequent number of virtual users using script.



    Now the problem is that i do not want to go and manually set the values for the variables declared.

    I want to read the data from csv file for which we are using  DDT driver.

    Until here its fine. But i am not sure on how to access the declared variables.

    For fuctional project variables we use project.variables.variablename for accessing project varialbes.

    I am not sure on how to modify the values of variables declared for task from script.

    I am using VB script.



    To summarise is there a way i can access and modify the variables declared in task editor while scripting instead of manually doing the same?
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi,


    I want to read the data from csv file for which we are using  DDT driver.


    First of all, you can parameterize requests using the CSV files without scripting at all. For this purpose, you can use the database variables that can read the values from different data storages, for example from CSV files. Note that using these variables requires both the correct connection string for accessing the needed file (you can find examples of the connection strings on the following page http://www.connectionstrings.com/textfile) and the necessary value access type (for example, Next value on each use, or Next value on each use by a virtual user, or Next value on each use within a station, or another type that corresponds to your file).


    For example, you can create one database variable for the column that stores logins, and another variable for the passwords column. Then, you just specify the names of these variables in the corresponding parameters of the request that simulates login. After that, if you run the test, virtual users will use the values from the CSV file in turn.


    On the other hand, you can parameterize the recorded requests from scripts. This approach is described in the Modifying Traffic in Scripts help topic. In this case, the load testing task variables declared in the Tasks editor are not used at all, and access to the request parameters is implemented directly through the URLVariables, BodyVariables and Variables collections of the HTTPRequest object. In other words, you can replace the request parameter with the value from the CSV File using the following approach:

    HTTPRequestObj.BodyVariables.Item("login") = DataDriverObj.Value("Login")


    You can also find an example that demonstrates this approach in the Load Testing Advanced tutorial.

  • Thanks. Hoped that i can directly update the variable.

    Anyways, i have tried with the DB variable wizard. I have one small issue and i am not able to figure it out

    I have provided the correct provider, data source and Extended properties (For Excel 2007)

    and i am able to see all the three sheets of the Excel sheet.

    But after selecting the excel object i am getting an error saying "unable to retrieve data from the specified database object. The database engine reports: Syntax error in FROM clause"



    I am not able to figure out the issue as i am selecting the sheet from the drop down and i am not providing any additional information

    I have attached the screen shots. Please provide a solution.
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi,


    This situation may be caused by the fact that the requirements for using Excel files as data storages are not met. For example, the required drivers may be not installed in the system.



    As you may know, TestComplete uses the ACE driver to retrieve data from Microsoft Excel 2007 sheets. The ACE driver is part of the Office 2007 System Driver: the Data Connectivity Components package that is installed along with Microsoft Office 2007. So, please, make sure that this driver is installed in your system. If it's not, you can download the package from Microsoft’s web site (http://www.microsoft.com/downloads/details.aspx?familyid=7554F536-8C28-4598-9B72-EF94E038C891) and install it manually.


    For more information on using Excel sheets as data storages, please see the Using Excel Files as Data Storages help topic.

  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi,


    One more advice that may help:  Try enclosing the name of the database object in brackets.  In other words, select the needed object from the drop-down list and then enclose it in brackets manually, that is, enter [Test1$] instead of Test1$ in the Object field.



    For more information on this, see the Database Variable Wizard - Select Database Object Page help topic.