Performance Testing @ the Frontline

A hidden world where small things make a big difference

Handle HTTP Re-Directions in LoadRunner Scripts yourself

Posted by Kim on Sunday, April 11, 2010

Sometimes you want to grab a Session-Cookie or something else from the HTTP Header’s during a redirection, but normally LoadRunner does not allow you to web_reg_save() those if there are multiple re-directions, and the same “variable” appears multiple times.

I’ve solved this problem by handling the re-directions myself in-script by doing a DO WHILE loop that keeps running till the end of re-directions, or error for that matter.

Here’s the code for a simple redirection loop (tries to go to mercury.com, but gets re-directed to hp.com instead):

Action()
{
	int HttpRetCode=0;

	// Set redirection depth to 0
	web_set_option("MaxRedirectionDepth", "0", LAST);

	// Initial Location where we want to go
	lr_save_string("http://www.mercury.com", "Location");

	do
	{
		// Save new Redirection Info (Location: header)
		web_reg_save_param("Location",
						   "LB=Location: ",
						   "RB=\r\n",
						   "Ord=1",
						   "NotFound=Warning",
						   "Search=Headers",
						   LAST );

		// do any web call (This needs to be modified to suit your needs)
		web_url("my_req",
		  "URL={Location}",
		  LAST );

		// Get HTTP response Code
		HttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE);

	} while ((HttpRetCode>=300) & (HttpRetCode<400));

	return 0;
}
Advertisements

7 Responses to “Handle HTTP Re-Directions in LoadRunner Scripts yourself”

  1. Hi Kim,

    I recently wrote about how this technique should be used to seperate authentication from the subequent page for a web application login.

    http://www.headwired.com/2010/timing-http-redirects-in-loadrunner/

    With some sub transactions in the do while loop, this could help time the mutliple redirects seen in some application. Nice work.

    • Kim said

      Good article Joel!

      Did you know that even if one specifies web_set_user() to LoadRunner, it always does one HTTP request without the Authenticate header and then another WITH the Authenticate header.

      This leads to a situation that if you are posting a large document (HTTP POST), it gets posted twice over the wire !!!! (=not very smart ..)

      • Hi Kim,

        Even though web_set_user() still performs one request with the auth header and one without, you can set up LoadRunner to bypass the 401 all together.

        Tim Koopmans worked this out when we worked together in 2008 to get SSO working, however it also works with basic auth as well.

        You need to set two items:

        1. Enable Integrated Authentication in the run-time settings
        (Internet Protocol->Preferences->Options->Authentication->Enable Integrated Authentication)

        2. Put this line above your web_set_user call web_set_sockets_option(“INITIAL_BASIC_AUTH”,”1″);

        You can read Tim’s article (albiet minus the images) at
        http://altentee.com/blogs/2008/performance-testing-spnego-or-kerberos-with-loadrunner/

      • Kim said

        Great information, Thanx!

  2. kiran said

    There exists a redirection parameter for web reg save,why do you think this will not work in this case.

  3. Hi Kiran,

    There is of course the ‘IgnoreRedirections’ argument for the web_reg_save_param function in LoadRunner.

    When IgnoreRedirections=Yes, ONLY the final page will content will be searched, and the pages leading up to that page are not. With the default IgnoreRedirections=No, ALL pages are searched for content and values can be matched on ANY of those pages. You can even use the “Ord=ALL” option as this allows for all redirections to be found

    So it turns out, the default behaviour of searching all pages leading up to your final page is a great option for matching multiple redirects, however, as in my post, this option does not allow you to set individual timing points for the redirects, something which I find very useful.

  4. Kim said

    For clarification the manual from v9.52 states:

    IgnoreRedirections: If “IgnoreRedirections=Yes” is specified and the server response is redirection information (HTTP status code 300-303, 307), the response is not searched. Instead, after receiving a redirection response, the GET request is sent to the redirected location and the search is performed on the response from that location.
    This attribute is optional. The default is “IgnoreRedirections=No”.

    @Kiran:
    As for the the usefulness of the parameter, it is totally dependent on the situation and type of script one is creating. I was not able to use the parameter since based on the Location I received I was supposed to go/not go there. It was a special case where a special way to handle it had to be created.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: