Modern web applications pass data from earlier responses to subsequent requests. It is quite possible that the subsequent request will require data in a different format than the data format in server response. Server responses can contain HTML entities or URL-encoded characters. If you extract this data and pass it to further requests, these symbols may cause errors. This topic describes the issue and explains how to work it around.
Why Converting Is Needed
It is possible that the format of response data will differ from the format that subsequent requests need. For instance, response data may include HTML entities (like , <, or >) or URL-encoded characters (like %20, %2B), and the subsequent request may require a string which contains regular characters, not entities or URL-encoded symbols. These entities and URL-encoded characters should be converted to the textual form before the string is sent to the server.
Usually, the client part of your web application does the replacement during the scenario recording:
However, LoadComplete does not detect replacement operations that your client application performs. During the test run, LoadComplete simply reproduces the recorded traffic, it does not launch the client part of your web application. If you extract data from responses, LoadComplete does not convert the extracted data by default:
If requests require data in another format, your tests may fail. Special characters may also cause problems with validation if the latter expects data to be in the regular text form.
To avoid possible issues, you have to configure LoadComplete to convert data to the needed format.
The conversion can also be needed, if you are going to use the extracted value for response validation (the validation condition may require data to have a specific format).
|Note:||If your client application modifies the server response in a more elaborative way and LoadComplete is not able to correlate requests and responses automatically, you can correlate the data manually. To learn how to modify the correlation data before sending it to a server, see Modifying Correlation Data.|
How Conversion Works
LoadComplete converts values during the scenario simulation. It does this in the following cases:
After receiving a response and extracting data from it with a data selector (in this case, the variable will get and store the converted value).
– or –
Before inserting a variable into a request with a data replacer.
You specify the conversion rules:
In the Data Correlation Options dialog.
In the Response | Data Selectors panel.
In the Data Replacers panel.
|Note:||You do not need to encode variable values before inserting them into the request URL and header. See below.|
When to Convert Data
You need to convert data only if you use data replacers to insert data. For example, to use a data replacer to insert a URL-encoded string into the request body, configure the data replacer to apply the URL encode rule to the data, or alternatively, configure the data selector that extracts a variable for the replacer. If you have an automatic data correlation rule for that data, configure the rule to use the URL encoding for the data replacer.
Do not apply encode rules on data you insert into –
- Request URL
- Request header
- In a Rich Internet Application parameter
- In a web form
The reason for that is that LoadComplete encodes variable values automatically depending on the place in which you insert them. For example, if your data selector uses the URL decode or HTML Decode rule, the variable will contain the plain text. If you insert this variable into a URL, LoadComplete will automatically URL-encode it. If you insert this variable into a request parameter, LoadComplete will automatically HTML-encode it.
Automatic encoding does not work if you use data replacers to insert variables into requests, because data replacers can change any part of a request, and LoadComplete simply does not “know” what encoding format to apply.
In LoadComplete, you can apply the following rules to data in your scenarios:
|None||LoadComplete does not convert the data. It saves the data to the specified variable or gets it from the specified variable as is.|
|HTML decode||LoadComplete replaces HTML entities (like , <, > and others) with their textual equivalents.|
|HTML encode||LoadComplete replaces special characters with appropriate HTML entities (for example, replaces & with
|URL decode||LoadComplete replaces URL-encoded characters within the extracted data with their textual equivalents (for example, it replaces %20 with spaces).|
|URL encode||LoadComplete replaces spaces, colons, commas and other characters in the extracted data with their URL-encoded equivalents (%20, %3C, %2C and so on).
|\x decode (2 hex digits), and
\x decode (4 hex digits)
|LoadComplete replaces symbols specified in a hexadecimal format (like
The difference between these two options is that one of them expects 2 hexadecimal digits after the \x prefix, while the other expects 4 hexadecimal digits. If the number of hexadecimal digits following \x in a response is less than expected, LoadComplete uses the available number of digits for replacement. For example, if you chose to use the \x decode (4 hex digits) option, and there are only 3 hex digits following \x, LoadComplete will try to find the appropriate symbol for these 3 hex digits.
|Calculate MD5 Hash||LoadComplete calculates MD5 hash of a string (a sequence of 32 hexadecimal digits).|
|Upper case||Converts all the letters in a string to upper case.|
|Lower case||Converts all the letters in a string to lower case.|
Applying Conversion Rules
To apply conversion rules to a data correlation rule:
Open the Data Correlation Options dialog.
Select the correlation rule you want to edit.
To configure the rule to convert extracted data before inserting it into requests, select the needed rules from the Convert drop-down list in the Replace in requests section.
To configure the rule to convert the data it extracts from server responses, select the needed rule from the Convert drop-down list in the Select from response section.
Save the rule.
To apply conversion rules to an existing data selector or data replacer:
Open the scenario for editing. To do this, right-click the scenario in the Project Explorer and choose Edit from the context menu.
To convert data before inserting it into a request, open the Data Replacers panel of the needed request (or of the scenario top-level node).
To convert the data you extract from a server response, select the needed request for editing, and then switch to the Response > Data Selectors panel. (In this case, the variable to which you save the extracted data will store the converted value).
Select the data selector or a data replacer in the panel. Click in the Convert column and select the needed rule from the drop-down list:
Select File | Save from the LoadComplete main menu to save the changes.