You can create rules to modify static data that is displayed in the responses that are sent from the web application. For example, response modification rules can be used to remove any reference to a server that you do not want to contact from anywhere outside the production environment.
If you want, you can specify a request variable and specific values as the trigger for completing the response modification. This method enables modification of response data based on a wide range of available criteria.
In the Response Modification dialog, click the pencil icon next to the ReqVar field. The Request Vars window is displayed:
In the left panel, you can browse the sections of the request to locate the request variable to use as the trigger. Click the request variable to use it.
Setting | Description |
---|---|
Value in Request Buffer |
If you create the response mod rule from a displayed request, the value of the selected request variable is displayed. |
Request Var Name |
The name of the selected request variable |
Request Var Value Pattern (regex) |
You can optionally specify a regular expression on which to match values in the regular expression. If this value is not specified, then all instances of the request variable are matched. |
Test | Test a specified regular expression.
|
- In the RTV menu, select Tools > Options > Profiles > Edit Profile.
- Click the host you whose response data you want to modify.
-
Click New. Then, select
Add Response Mod
. - In the Response Modification window, specify the following
properties:
Property Description Hostname
The host name value is inherited based on the host node that you selected. URL
Select the method of matching URLs: All
- response modification is checked for all URLs from the host name.Regular expression pattern
- Enter a regular expression to use to match the URI stem in all URLs from the host.
ReqVar
You can specify request variables as the trigger for applying the response modification rule. Value
If specified, this field defines the value in the selected ReqVar
on which to trigger the response modification rule. This value can be specified as a regular expression.Pattern
The pattern on which to match. You can enter regular expressions here. Replacement
When the Pattern
string is found, this string is used to replace. Leave this value empty to remove instances of thePattern
value.Occurrences
Select the replacement type: First
instance orAll
instances in any matching URL.Test Test the response modification rule on the currently selected page that is displayed in Response View. The number of replaced text items for the selected URL or URLs is displayed. Edit Rules Edit the response modification rule, which opens theProfiles window. - To save changes, click OK.
- If the profile is shared, your changes must be committed to the server. Click Upload Settings to Server.
Test Response Modify Rules
. A dialog with the testing
options is displayed.Example - Modifying based on user agent
Suppose you want to modify the response to improve replay for iPod. Using the request variable configuration option, you can identify sessions that are initiated by iPods and then create a response modification for these mobile devices.
- In RTV, open an iPod-initiated session.
- Click the Response View option.
- Right-click and select Add Response Mod Rule.
- The Response Modification dialog is displayed.
- Click the Regular expression pattern check box.
- Click the Pencil icon next to the
ReqVar
field. - From the left panel, select
env/HTTP_USER_AGENT
. - The Request Variable Name value is populated with the selected request variable.
- For the
Request Var Value Pattern
, enter iPod. - Click Test. If the response that you selected comes from an iPod
session, the result message must be
Found
. - Click OK.
- Configure the Pattern and Replacement fields as needed.
- To test it, click Test.
- If the rule passes the test, click OK.
Example - Removing CDATA formatting
Many web applications are deploying content in application/xhtml+xml
pages. However, Internet Explorer does not support these pages. Since RTV uses an embedded IE
browser control, RTV cannot properly process these pages, which results in replay problems,
especially if they contain CDATA sections.
For replay purposes, it is necessary to be able to run the code within a CDATA node. The solution is to create two response modify rules to remove the CDATA formatting.
-
Create a profile rule with the following properties:
Property Description Hostname
The host name value is inherited based on the host node that you selected. URL
For this rule, you must enter a specific URL, as universally removing the CDATA block can cause problems. Pattern
<![CDATA[
Replacement
Leave blank. Occurrences
Select All
. -
Create a profile rule with the following properties:
Property Description Hostname
The host name value is inherited based on the host node that you selected. URL
For this rule, you must enter a specific URL, as universally removing the CDATA block can cause problems. You must enter the same value that you entered in the previous rule. Pattern
]]\>
Replacement
Leave blank. Occurrences
Select All
. - Be sure to test the response modification rule.
- To save changes, click OK.
- If the profile is shared, your changes must be committed to the server. Click Upload Settings to Server.
The XML version of the rules looks similar to:
<ResponseModify id="36" url="/quote/details.asp"
pattern="<![CDATA[" replacementString=""
occurrences="all" enabled="1"/>
<ResponseModify id="37" url="/quote/details.asp"
pattern="]]>" replacementString=""
occurrences="all"/>
Example - Misaligned forms in RTV
Playback of some web applications can result in misaligned forms that are displayed in RTV. In a typical example, elements that must be aligned horizontally are aligned vertically in the RTV main window.
The root issue is most often the use of conditional HTML to control display style sheets that account for differences between versions of Internet Explorer. In this case, you can correct the issue by changing IE6-specific conditional HTML blocks to be used by later versions.
- Create a profile rule with the following properties:
Property Description Hostname
The host name value is inherited based on the host node that you selected. URL
To apply to the entire site, select All
.Pattern
if IE 6
Replacement
if gte IE 6
Occurrences
Select All
. - Be sure to test the response modification rule.
- To save changes, click OK.
- If the profile is shared, your changes must be committed to the server. Click Upload Settings to Server.
The XML version of the rule must be similar to:
<ResponseModify id="255" url="" pattern="if IE 6"
replacementString="if gte IE 6" occurrences="all"/>