Replace Timestamp Rule

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

Replace Timestamp rule diagram

The Replace Timestamp rule is useful for modifying a request before it is sent. For example, you can update a timestamp to reflect the current time when the test is run.

The Replace Timestamp rule modifies script code so that values are replaced wherever they appear in the request, including GET or POST data, sent headers, or the URL to which the request is sent.

Example Script Code Changes (Java)

The following example adds the recorded difference of one hour (3,600,000 milliseconds).

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("1442073069000");

 

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(getMillisecondsSinceEpoch(3600000));

 

request1.setMessageBody(form_1);

 

try (Response response1 = request1.send())

{

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

}

}

Generation Rules Wizard Pages

Select a Range of Timestamps to Replace

Select a time range for timestamps to replace

By default, this rule is set to replace timestamps that fall within a specified range from the time of the request in which the timestamp is 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 timestamps in the recording.

To determine whether something is a timestamp, the generation rule looks for strings of numbers between 9 and 13 characters long. It's possible that such a string could represent something other than a timestamp; therefore, including a range reduces the possibility of a false positive.

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 timestamp section shows any requests (in the current recording) that contain timestamps 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 indicate the value you want to insert in place of the matching timestamps.

Choose the value you want to use

Use the Replace value with drop-down list to choose how you want to replace matching values. Your choices are:

Current timestamp: The timestamp in the recording is replaced by the current timestamp when the test is run. With this option, you can also set an offset time value to be added to the current time. The Offset the timestamp by the recorded difference checkbox adds the difference in time between when the request was made and the time recorded by the timestamp.

Value from data dictionary: The timestamp 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 timestamp in the recording is replaced by a fixed value you enter in the Text field. When you select Literal string, a timestamp (in UTC format) reflecting the current time is inserted in the Text field by default. You can enter your own value in the field, or use the date picker below the drop-down list.

Function call: The timestamp in the recording is replaced by a call to a function that returns a value to use. In the Function call field, enter the name of a function that has a return type of long. The function must take two parameters:

  • long timestampMillis: The timestamp found in the recording
  • long requestMillis: The time at which the request was sent in the recording

Both parameters are passed as milliseconds since epoch. The returned value should also be expressed as milliseconds since epoch; it is converted automatically to seconds since epoch if necessary. You can create a function like this in the appropriate custom virtual user class.

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 August 19, 2021, at 03:30:52 PM.

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