Replace Date/Time Rule

The Replace Date/Time 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 the date/time that was sent to the server in a request during a recording with a different date/time (or other value) when a virtual user (VU) runs the script.

The Replace date/time option in the Generation Rules Wizard

The pattern that you enter to match the date/time will be different depending on the language of the VU type selected when creating the rule. The Replace Date/Time rule is useful for modifying a request before it is sent.

Example Script Code Changes (Java)

The following example uses the formatDateTime method to substitute in the current date/time when the VU runs the code.

Url url1 = new Url(protocol1, timeanddate, "/worldclock/uk/london");

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

{

Form form_1 = get("form_1");

form_1.getInputElement("expiryTime").setValue("2017-10-30T13:35:10+01:00");

 

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, timeanddate, "/worldclock/uk/london");

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

{

Form form_1 = get("form_1");

form_1.getInputElement("expiryTime").setValue(formatDateTime("uuuu-MM-dd'T'HH:mm:ssxxx"));

 

request1.setMessageBody(form_1);

 

try (Response response1 = request1.send())

{

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

}

}

Generation Rules Wizard Pages

Select a Range of Dates/Times to Replace

Dates/times to replace in the Generation Rules Wizard

By default, this rule is set to replace dates/times that fall within a specified range from the time of the request in which the dates/times are found. Indicate the range by setting the Upper limit and Lower limit values you want to use. If you clear the checkbox, the rule will replace all detected dates/times in the recording.

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

The Requests containing a matching date/time section shows any requests (in the current recording) that contain date/times in the indicated range so that you can see which requests will be affected in the generated script. If you select a request in the list, the Matching request data box shows details about the match.

When you have set your values, click Next.

Select the Replacement Value

Use this page to define the value you want to insert in place of the matching date/time.

Replacement date/time in the Generation Rules Wizard

Use the choices listed under Where should the date/time come from? to choose how you want to replace matching values. Your choices are:

Current date/time: The date/time in the recording is replaced by the VU's current date/time. Optionally, you can choose to apply an offset to the date/time.

  • The Offset the date/time by the recorded difference checkbox adds the difference between the time at which the request was actually sent and the time represented by the date/time found in the request.
  • The Offset the date/time by a fixed amount checkbox allows you to define how much time to offset the date/time by.

Value from data dictionary: The date/time in the recording is replaced by a value retrieved from an external data file, based on a key entered in the Data key field. With this method, each virtual user in the test can retrieve a different value at runtime.

Note: This method requires that you define a data binding for the test, and the data file must contain a matching key.

Value from data dictionary (with default): This option works the same as Value from data dictionary; however, if there is no data binding for the test or the data binding does not include a matching key, the replacement will use the default value (i.e., the original value from the recording).

Fixed value: The date/time in the recording is replaced by a the value you enter in the Replacement date/time field, using the format entered on the previous page. Use the drop-down calendar to determine the correct date/time in UTC.

Function call: Enter the name of a function that has a return type of string, and takes four parameters:

  • string originalText: The date/time found in the recording.
  • string datetimeFormatPattern: The format pattern entered on the previous page.
  • LocalDateTime originalDatetime: The date/time decoded from originalText.
  • LocalDateTime requestDatetime: The date/time at which the request was sent in the recording.
Note: For Java custom virtual users, the originalDatetime and requestDatetime parameters should be of type LocalDateTime. For C# custom virtual users, the originalDatetime and requestDatetime parameters should be of type DateTime.

Java example:

public String customDatetimeFunction(String originalText, String datetimeFormatString, LocalDateTime originalDatetime, LocalDateTime requestDatetime)

{

return "";

}

C# example:

public string CustomDatetimeFunction(string originalText, string datetimeFormatString, DateTime originalDatetime, DateTime requestDatetime)

{

return "";

}

When you've chosen the options you want for your replacement value, click Next.

After the Select the replacement value page, the common Generation Rule wizard pages Create Request Filter and Rule Name and summary appear.

 

This topic was last updated on June 21, 2019, at 02:49:50 PM.

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