About Data Replacers

Applies to LoadComplete 4.97, last modified on May 20, 2019

This topic describes the data replacer functionality of LoadComplete.

About Data Replacers

In LoadComplete, you use data replacers to insert data into a request body, header fields and cookies. A data replacer includes an expression that defines the request data fragment to replace and a variable whose value will replace the selected data. The variable can store a value extracted from some earlier response or a value loaded from an external data source.

You can create data replacers for individual requests or WebSocket messages, as well as for scenarios. In the latter case, the test runner will apply replacers to all the outgoing messages in a scenario.

You work with data replacers on the Data Replacers tab of the Scenario editor. To open the tab, depending on whether you want to work with request-level data replacers or with scenario-level data replacers, do the following:

  • To work with a data replacer for a single request (for HTTP traffic) or client message (for WebSocket traffic), select the needed request or message in the Scenario Explorer and switch to its Data Replacers tab:

    Data replacers in a request

    Click the image to enlarge it.

– or –

  • To work with a data replacer for the entire scenario, select the top-level node in the scenario and open the Data Replacers page:

    Data replacers in a acenario

    Click the image to enlarge it.

Creating Data Replacers

You can configure LoadComplete to create data replacers and data selectors for dynamic parameters and cookies in your scenarios automatically:

Note: Creating data replacers automatically is supported only for individual requests and client messages. Scenario-level data replacers can be created only manually.
  1. Before you start scenario recording, in the Tools > Options > Recording > Data Correlation dialog, make sure that the correlations rules for dynamic parameters, for which you want to create data replacers, are enabled.

    To create cookie replacers, make sure that the Common/Cookie rule is enabled.

    If needed, create custom correlation rules.

  2. After you finish recording a scenario, LoadComplete will show the Correlate Request and Response Parameters wizard. (You can also call the wizard any moment at design time by clicking on the Scenario editor toolbar.)

    Command the wizard to correlate the scenario.

  3. The wizard will analyze requests and responses in the scenario, and will create data selectors and data replacers for dynamic parameters and cookies it will find.

You can also create custom data replacers in the Scenario editor to insert the needed data to requests. For information on how to do this, see Creating Data Replacers.

How Data Replacers Work

  1. LoadComplete applies data replacers to outgoing messages (HTTP requests and WebSocket client messages) at run time, before simulating these requests and messages.

    If you defined scenario-level data replacers, LoadComplete applies them first. Then it applies the data replacers that you defined for the simulated request or WebSocket message.

  2. LoadComplete searches for the data that the replacer specifies in the message header or body:

    • For body and header data replacers, LoadComplete can use regular expressions or parameter names to find the data to replace.

    • For cookie data replacers, LoadComplete uses cookie names to find the data to replace. LoadComplete sets cookies using the same rules as any other web browser. That is, it uses cookie attributes to determine when to delete, block or send a cookie to the server.

  3. If LoadComplete finds the data in the outgoing message, it replaces it with the variable value the data replacer specifies.

    If LoadComplete cannot find the data to be replaced, or the specified variable is not initialized, LoadComplete does not perform any actions and moves to the next data replacer (if any).

Important notes:

  • We recommend that you apply data replacers only to POST requests and to WebSocket client messages that pass their data in a textual form.

  • LoadComplete will apply scenario-level data replacers to all the requests in your scenario.

    If it applies a data replacer that modifies the request body content (with the Body (RegExp) area) to a GET request, the resulting request may have a non-empty payload. HTTP/1.1 specification does not recommend using GET requests with a non-empty payload body (to learn more, see Section 4.3.1 of RFC 7231). Your tested web server may reject such a request, or return an unexpected response.

    To avoid possible issues, make sure that the regular expression of your scenario-level data replacer matches data only in the needed requests. As an alternative, instead of using scenario-level data replacers, create individual data replacers only for requests whose data you want to modify.

  • Replacers work in series, one after another. If some replacer updates message data, then the next replacer will search in the updated message contents.

    LoadComplete applies scenario-level replacers before request-level replacers. In other words, you can see scenario-level replacers as request-level replacers that are applied to each request and that work before other request-level replacers.

  • The variable that a data replacer uses must exist and contain a value when the data replacer inserts it into a request. If the variable does not exist when the data replacer is trying to insert it, LoadComplete does not change the request data.

    You can create a variable with the Variable wizard or define it on the Data Selectors tab of one of the previous requests.

  • Make sure the names of variables your data replacers use do not include names of other variables (for example, MyVariable and MyVar). Otherwise, your data replacers may distinguish such variables incorrectly.

  • If the data replacer’s regular expression includes parentheses, LoadComplete replaces data enclosed in the parentheses. Else, it replaces data that matches the entire expression.

    For example, if you have the following data in the request –


    – the following regular expressions will return the following data:

    • Regular expression:


      Result: LoadComplete will select data in parentheses only, that is, my+search+data.

    • Regular expression:


      Result: LoadComplete will select data that matches the entire expression, that is, <QueryText>my+search+data</QueryText>.

    For a step-by-step description of how to determine what data a replacer will replace, see How to Determine What Data Will Be Replaced.

  • If the request includes several fragments that match the data replacer’s regular expression, LoadComplete will replace only the first match. It will not replace the other matches. To make sure that your test works correctly, specify the expression that will be unique for the desired value. For instance, you can use a regular expression that selects a set of characters wider than needed and use parentheses to pinpoint the piece of data to replace (see above). See also Data Replacers - Tips.

  • Changing the area type of an existing data replacer from Body(RegExp) or Header(RegExp) to any other (Cookie, Body(Path) or Header(Path)) clears the data replacer’s attributes.

Data Replacer Alternatives

Using data replacers is one of several approaches you can use to modify simulated traffic. Data replacers is a powerful and universal solution for protocols that pass data in the textual form, however, they require that you be familiar with regular expressions. In some cases, it is much easier to use other approaches.

For example, if you are testing a SOAP or JSON application, the easiest way to replace request data with variables is to insert those variables into a request directly on the Request Body tab of the request. See Inserting Variables in Rich Internet Application Requests .

See Also

Using Variables in Requests
Regular Expressions Syntax
Editing Recorded Requests

Highlight search results