Replace Key Value Rule
The Replace Key Value rule is one of the rules you can apply when you generate a script in Eggplant Performance using the Generation Rules wizard. You use this rule to replace a key/value pair (e.g. in an HTML form) that was sent to the server during recording with a different value when a virtual user (VU) runs the script.
This rule is useful for parameterizing a script—that is, making different VUs send different data in their HTTP requests during a test. For example, different Virtual Users could log into a website with different usernames and passwords.
This rule is similar to the Replace Value rule but is more specific. The Replace Key Value rule will modify script code so that values are replaced wherever a particular key is used in GET
or POST
data within a request.
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@example.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
Using the Replace Key Value rule involves using two pages in the Generation Rules Wizard:
Select the Keys to Replace
Enter a value that was sent in GET
or POST
data in a request within the current recording. For example, enter text that you know you typed into a web page during recording, such as an email address.
As you type, suggestions are given for values that were sent in the current recording.
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 Matching keys list shows any key/value pairs that were sent (in the current recording) with the specified value.
- Select one or more key/value pairs in the Matching keys list, and then click the arrow to copy them to the Selected keys list.
- OR, click the Add button, and then type a key into the new blank entry in the Matching keys list.
The Matching requests table shows any requests (in the current recording) which sent GET
or POST
data containing any of the keys in the Selected keys list. This is so you can see which requests will be affected in the generated script.
The keys in the Selected keys list are the ones which will be replaced during script generation.
Select the Replacement Value
This page uses the Choosing a value page to determine what to send in GET or POST data as the replacement value wherever the selected keys occur.
After the Select the Replacement Value page, the common pages Create Request Filter and Rule name and summary appear.