Back to Blog

LoadRunner Run-Time Settings: Additional Attributes

Many times I want to set up Vugen scripts so that I can easily move from one environment to another. Often, the environment being tested if not the same one I script in because of logistics in getting the environments ready. Without getting into the issue of poor configuration management between environments screwing up your scripts – and most LoadRunner scripters know how bad of a problem this is –  I wanted to demonstrate the use of the “Additional Attributes” run-time setting to easily change environments without changing the Vugen code.

You could just as easily create a parameter for the server within the script and switch back and forth between a specific line in the data file, but I think this might be a little bit easier to maintain, especially if you have to share it with other groups or people who come behind you after you are done with the project and may not be “script view” friendly.

1. Create a new attribute in the run-time settings by selecting the “additional attribute” option and put in an argument called “host”, with a value of the server portion of the URL you are testing against. This could be an IP address or the domain name, such as “www.<yoursitenamehere>.com”. I always include a description as well.

2. Put the following code in your vuser_init section:

/* LPCSTR is Microsoft's way of calling a constant char * . */

LPCSTR server;
server=lr_get_attrib_string("host");

if (server==NULL){
 lr_error_message("Failed to login. Unknown host.\n");
 return 0;
 }

/*Prepare a string with login information */

lr_message("INFO:>> Using %s server for host environment.", server);
lr_save_string(server, "pURL");

3. Parametrize the URL value hard coded in the script with {pURL}, such as the following example first page request to our test server:

web_url("{pURL}",
 "URL=http://{pURL}/",
 "TargetFrame=",
 "Resource=0",
 "RecContentType=text/html",
 "Referer=",
 "Snapshot=t1.inf",
 "Mode=HTML",
 EXTRARES,
 "Url=/intro.swf", ENDITEM,
 LAST);

4. Do a “find and replace” for the hard coded URL throughout the script.

5. When the time comes to change to a new domain, simply replace the value in the additional attribute run-time setting and never have to touch a line of code.

And optionally….

6. Be prepared for your entire script to break in the new environment anyway, because development forgot to tell you about all the changes they made to the code in the environment under test. Recreate your scripts from scratch and get the project done in spite of the odd against you. 🙂

Good luck!

What are some other uses for the Additional Attributes run-time setting? Let me know how you use it in the comment section below.

Back to Blog