To generate accurate and correct load usually a script will need to have some changing data that it references in order to perform the actions within it. Typical examples might include:
Here we’ll use the BookStore demonstration application where a list of user names will be extracted. If you want to do this for yourself in addition to AgileLoad and the bookstore you’ll need the MySQL ODBC connector available here: http://dev.mysql.com/downloads/connector/odbc/, alternatively you can just use the BookStore and AgileLoad installation on Amazon Web Services.
In this instance a script has been captured that logs into the application and buys a book from the bookstore. We don’t want to log in as the same user each time though and if we leave the script as it is that’s exactly what will happen. There may be a number of reasons that we’d want to avoid this such as the application may not allow the same user to be logged in with more than one concurrent connection or we may simply want to avoid record locking on the login table in the back end database.
The first step is to connect to the database, in this case we’re using MySQL so we need a special connector to make it available via ODBC (see above).
Once the script is open use the Insert Modify Variable button (circled in red at top of screenshot) to open the Variable Properties window. Enter the name of the Variable (your choice) and in the case of login parameters use Global to ensure that user names are always unique during the test (see the manual for scope definitions for more information). Click on the Database button (circled also in red), choose the data source and if relevant specify the credentials to access the database.
Then choose between SQL or Table and either write the SQL you need to choose the data you require or use the database table browser built into AgileLoad to extract the field that you desire. You’ll then be prompted for how many rows you want to extract, you can also choose all rows.
Now we have the list of Login names we can either save the list into the script or better still into a file. By default Sequential is selected – this means that the data will be ordered sequentially during execution and Random will of course choose a random value from the list. In fact his will either use the NEXT or GENERATE verb in the script to tell AgileLoad how to handle this data. To complete the process click the Generate button. This will add the necessary lines to the script.
Now that the data exists it needs to be used in the script, you can if you prefer manipulate the script directly or use the interface to do it for you. The lines circled in Red are the lines that have been inserted into the script by the Variable Properties window after we clicked Generate. If you need to make edits to these lines you can do this directly in the script or by using the Variable Properties window again by selecting the relevant variable from the Variable drop down box.
In this case we have set all of the passwords to be the same so that it is not necessary to also extract the passwords (most passwords will be stored encrypted in a database anyway). However if you do need to extract two linked values such as a username and password pair then repeat the process and ensure that at the end the line reads NEXT <Variable1>, <Variable2>; (replace the <Variable n> with the values that you have used). This will ensure that the two values remain tied, this is also true for the GENERATE command which will choose the same random record in both lists. For this to work correctly both lists have to be of the same size.
Next Using Data in a Script