Thursday 12 August 2010

Replacing dynamic parameters

The last piece of the correlation puzzle is to replace dynamic parameters hard coded is the script with the extracted values. Although this could be done directly in the WebTest editor it is more time consuming and error prone. Since the VSTS WebTests are also plain XML files it is simpler to open them as such in XML viewer and replace hard-coded values with parameters using search and replace functionality.

To open WebTest as an XML document right click on the WebTest in VSTS Solution Explorer and select “Open With…” con text menu option. From the Open With selection window select “XML (Text) Editor” and click OK.

VSTS parameter tag contains two parameter value attributes one with the actual value used during test execution and one with the recorded value.

When the form post parameter is bound to the extracted parameter or data source value in WebTest designer only Value attribute is altered and the original field value is preserved in RecordedValue attribute. This allows VSTS to restore original value of the field upon unbinding.

WebTests recorded in Fiddler always have their RecordedValue attribute blank.

With the correct search and replace rule we could hit two birds with one store and update RecordedValue attributes while replacing hardcoded values.

In this example we could search for:
Value="536877651" RecordedValue=""
and replace with:
Value="{{activityId1}}" RecordedValue="536877651"
Since the dynamic value appear in other context (e.g. as a part of longer expression) it is still required to perform another search and replace just on the value.

The last type of requests which needs to have their hardcoded dynamic parameters replaced with extracted values are requests containing String Body.

Request with String Body
Each requests containing String Body needs to be examined individually and any hardcoded values needs to be replaced.

The reason why this cannot be done from within XML as it was the case with Query String and From Post Data parameters is that String Body is an encrypted.