Manual Redirection using a Property Set

by Community Manager on 08-31-2011 01:21 PM - last edited on 09-22-2011 04:53 AM



CloudTest does not automatically follow HTTP 302 redirects because the recording itself already has the redirected URL captured in it. The only time redirects need to be handled in the test is when the page being redirected to will differ from test to test.

Redirection occurs when an HTTP response specifies a location or canonical URL as well as in other cases. In order to follow HTTP redirection it is necessary to handle the URL(s) that come back in the HTTP response header for the given HTTP request.

TIP:           CloudTest provides automatic parameterization via Session Templates that will identify, extract to a custom property, and replace the dynamic value with a property placeholder. Refer to Session Templates for instructions to replace an individual value or Session Template Packages to replace one or more values in a clip.

Parameterization for redirects can be performed manually so long as the following conditions are met.

  • A property set is created on the message response header that returns the HTTP redirect for the purpose of extracting the dynamic string. For example, the instructions below will extract the dynamic portion of an URL from the “Location” response header using a SubString (e.g. it will grab only the URL string after the hostname).
  • Use a custom clip property to  replace the URL string in subsequent messages that use it (e.g. redirectURL).
  • Create a custom clip property with a user-friendly name, such as redirectURL.
  • Use the custom clip property in the URL request of the page after the HTTP 302 redirect.

 

Creating a Manual Redirection using a Property Set

Use the following steps to meet the above requirements.

  1. First, locate the message and double-click to open it in the Message Editor (Clip Editor lower panel).

In the example on the right, this message is a POST message called index.php.

 

  1. Optionally, inspect the message response header by selecting the Response Headers node in the tree on the left.

In the example on the right, the Location header is highlighted.

Note: In the following steps we will specify leading and trailing text that surrounds the relevant URL portion. This is a good time to note this text. For example, “?” for leading text and “/#” for trailing text.

  1. Click the Property Sets node in the tree.

  1. Click the green Plus icon on the right to add the Property Sets form to the panel.

When you do so, the Property Sets form appears.

  1. In the top dropdown, change Field to Header.
  2. Enter or paste the leading text. For example, “?” or “Location: http://www.soastastore.com/?”.
  3. Enter or paste the trailing text. For example, “/#”.

Note: You can select a longer string if a match is not produced by the selection above.

  1. Click Test on Recorded Response to test the extraction. A successful extraction will capture all the intended text (e.g. between leading and trailing). If “No match” is returned adjust the leading and/or trailing text
  2. In the bottom section of the form, and with type “Custom” and Starting Element “Current Clip” still set, enter a Property Path. This is the name of the custom clip property that will be created to store the extracted value. For example, post_redirect_url.

    1. Next, click the Clip Editor Properties tab and then click the Clip Custom Properties node. The Custom Clip Properties form name/value fields appear on the right.
    2. Click the Plus sign to add a property.
    3. Enter the exact name used in the Property Set form in the steps above. For example, post_redirect_url.

  1. Next, locate the dynamic URL in the subsequent page request (and any additional requests necessary).

  1. Select the dynamic string (shown in the Query String field above) and then click the Property Chooser icon.
  2. Select the custom clip property created above (from the Clip Properties node) and then click OK.

The dynamic string is replaced by the property path for the selected custom clip property as shown below.

  1. Save the clip after making the above changes.