Replace Value Rule

The Replace Value rule is one of the rules you can apply when you generate a script in Eggplant Performance using the Generation Rules wizard. Use this rule to replace a value that was sent to the server in a request during a recording with a different value when a virtual user (VU) runs the script.

Replace value rule diagram

This rule is useful for modifying a request before it is sent. For example, different VUs could send requests to different URLs.

This rule is similar to the Replace Key Value rule but is more general. The Replace Value rule will modify script code so that values are replaced wherever they appear in the request, including GET or POST data, sent headers, or even the URL that the request is sent to.

If the replacement value needs to be based on something that the server sends, such as a session ID, then the Data Correlation rule may be more applicable.

Example Script Code Changes (Java)

Url url1 = new Url(protocol1, httpbin, "/post");

try (Request request1 = getWebBrowser().createRequest(HttpMethod.POST, url1))

{

Form form_1 = get("form_1");

form_1.addElement(new InputElement("email", "bob@testplant.com"));

 

request1.setMessageBody(form_1);

 

try (Response response1 = request1.send())

{

response1.verifyResult(HttpStatus.OK, ActionType.ACT_WARNING);

}

}

Changes to the following:

Url url1 = new Url(protocol1, httpbin, "/post");

try (Request request1 = getWebBrowser().createRequest(HttpMethod.POST, url1))

{

Form form_1 = get("form_1");

form_1.addElement(new InputElement("email", getString("Email")));

 

request1.setMessageBody(form_1);

 

try (Response response1 = request1.send())

{

response1.verifyResult(HttpStatus.OK, ActionType.ACT_WARNING);

}

}

Generation Rules Wizard Pages

Enter the Values to Replace

Enter Values to Replace page in the Rules Generation wizard

Enter text in the Text to replace box, and then click Add.

As you type, suggestions are given for values that were sent in the current recording.

Note: The current recording can be opened in a separate window by clicking the View Recording button, and GET and POST data can be viewed in the Web Log Viewer.

The text to replace will be added to the list.

The Requests containing the value table shows any requests (in the current recording) which contain any of the values in the list. This is so you can see which requests will be affected in the generated script. If you select a request in the table, the Matching request data box will show where the match occurs.

You can remove a value from the list by selecting it, and then clicking Remove.

If the Use regular expressions check box is selected, then the values in the list are interpreted as regular expressions.  This enables you to replace a wider range of values with a simple regular expression.

The values in the All the values below will be replaced list are the ones which will be replaced during script generation.

Select the Replacement Value

This selection step uses the Select the replacement value page to determine what to replace the values with.

Select the replacment value page for a Replace Value rule in the Rules Generation Wizard

After the Select the Replacement Value page, the common pages Create Request Filter and Rule name and summary appear.

 

This topic was last updated on January 13, 2022, at 02:42:23 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2022 Eggplant