Data List Correlation Rule

The Data List Correlation rule is one of the rules you can apply when you generate a web virtual user (VU) script from a recording in Eggplant Performance Studio using the Generation Rules wizard. This rule is useful if the web server sends a list of values, such as a list of form options, during the recording and one or more of these items need to be sent back to the server in a later request. This rule enables you to correlate the associated list values so that, during a test, the virtual users (VUs) send back one or more items within the list they received from the server, and not what was received during recording.

The Data List Correlation rule is very similar to the Data Correlation rule, except there might be more than one value extracted from the response at runtime. The value (or values) are placed as a list in the VU's data dictionary.

How the Data Correlation Rule Works

The following diagram illustrates how the Data List correlation rule works:

The Data List Correlation rule diagram

Example Script Code Changes (Java)

The following example code shows the effect of applying a Data List Correlation rule:

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

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

{

....

 

try (Response response1 = request1.send())

{

....

}

}

 

....

 

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

try (Request request2 = getWebBrowser().createRequest(HttpMethod.POST, url2))

{

Form postData2 = new Form();

postData2.setCharEncoding("ISO-8859-1");

postData2.addElement(new InputElement("custname", "Bob Smith", "ISO-8859-1"));

postData2.addElement(new InputElement("custemail", "bob@testplant.com", "ISO-8859-1"));

postData2.addElement(new InputElement("custcountrycode", "US", "ISO-8859-1"));

 

request2.setMessageBody(postData2);

 

try (Response response2 = request2.send())

{

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

}

}

Changes to the following:

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

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

{

....

 

try (Response response1 = request1.send())

{

// 3 matching values extracted from recording. First matching value is "UK"

ExtractionCursor extractionCursor1 = new ExtractionCursor();

if (response1.find(

extractionCursor1,

"<select name=\"country\">",

ActionType.ACT_WARNING,

true,

SearchFlags.SEARCH_IN_BODY))

{

set("formOption_1", response1.extractList(

extractionCursor1,

"<option value=\"","

"\">","

"</select>",

true,

3,

ActionType.ACT_WARNING,

SearchFlags.SEARCH_IN_BODY));

}

....

}

}

 

....

 

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

try (Request request2 = getWebBrowser().createRequest(HttpMethod.POST, url2))

{

Form postData2 = new Form();

postData2.setCharEncoding("ISO-8859-1");

postData2.addElement(new InputElement("custname", "Bob Smith", "ISO-8859-1"));

postData2.addElement(new InputElement("custemail", "bob@testplant.com", "ISO-8859-1"));

postData2.addElement(new InputElement("custcountrycode", this.<List<String>>get("formOption_1").get(1), "ISO-8859-1"));

 

request2.setMessageBody(postData2);

 

try (Response response2 = request2.send())

{

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

}

}

Generation Rules Wizard Pages

The pages you see in the Generation Rules Wizard vary depending on the type of rule you select and whether you are creating a new rule or editing an existing one. Following are the pages you see when you create or edit a Data List Correlation rule:

Select a Rule Type Page

The first page you see when you create any new rule in the Rules Generation Wizard is the Select a Rule Type page shown below.

Select a Rule Type page with the Data List Correlation Rule selected in the Rules Generation Wizard

Select Data List Correlation from under Data Correlation Rules in the Rule Types pane on the left. The diagram on the right changes to display an explanation of how the Data List Correlation rule works. The same diagram is shown at the top of this page.

Enter List Values to Correlate Page

The second page you see when you create a Data List Correlation rule in the Rules Generation Wizard is the Enter the list values to correlate page shown below.

Enter list values to correlate page in the  Rules Generation wizard

In the List items to correlate box at the top of the screen, enter a value that you think might change depending on what the server sends during a test.

Click Add to add that value to the list box below. You can enter as few or as many items as you want to find the value you want. Note that you can remove an entry by highlighting that value in the list box and clicking Remove.

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

The tables display responses and requests (in the current recording) that contain ALL the correlation value items you entered.

Select a response or request in the table to show its contents in the box on the right-hand side, with the text items to correlate highlighted.

Enter the Before and After Values Page

The third page you see when you create a Data List Correlation rule in the Rules Generation Wizard is the Enter the before and after values page shown below.

Enter before and after values page for a data list correlation rule in the Rules Generation wizard

The text to correlate value(s) you entered on the previous page can help you locate the values that might change during a test. Because the values from the server might be different when a VU runs the generated script, you need to provide a reliable way of extracting the values from the responses sent by the server.

The Enter the before and after values page enables you to provide the text before and after the value in the response content. Enter the before and after text values in the before and after boxes respectively.

Search Options

In a similar manner to the Data Correlation rule, you can use extra search options to help extract the values you want from the responses sent by the server. The Data List Correlation rule provides the following options:

  • Limit the search: This option helps to restrict, or narrow down, the body of data that is searched in each response:
    • Start the search after the following text: You can enter a text value to specify that the search should start after the position of this value within the response data.
    • Stop the search at the following text: Likewise, you can enter a text value to specify that the search should stop at the position of this value within the response data.
  • Limit the number of extracted items: Unlike the Data Correlation rule, the Data List Correlation rule can extract more than one matching value. As such, the extracted items are stored in a list in the VU's data dictionary. Use this option to limit the number of values that are extracted and stored in that list.
    • Maximum number of items in the list: Enter the required value in the box (or use the up/down arrows).
  • Search case sensitive: This option performs a case-sensitive search when looking for the before and after values.
  • Extract from: This option helps to narrow down from which part of the HTTP response you want to extract a value. This is useful in case the before/after values are too general, or if you only want to make sure matches are only found in headers or cookies. The Response contents box is divided into Body and Headers tabs to help distinguish from where the values should be extracted.
  • Exclude binaries: This option prevents extraction of values from responses that appear to contain binary data. You should only deselect this checkbox if you expect extractions to occur within binary data. This option excludes responses with the Content-Type header set to the following:
    • application/octet-stream
    • Any starting with image/*
    • Any starting with audio/*
    • Any starting with video/*
    • Any specified in the comma-separated customBinaries list within the generation options file (Advanced)

The table at the bottom lists Responses containing the value(s) to correlate.

Select one of these responses. The response content is displayed on the Body or Headers tab in the Response contents box. The response content is also highlighted in different colors to show exactly where the value would be extracted from if that response were received during the test.

The yellow highlighted text shows the text matched by the before and after expressions you entered, including the use of any search options. The text between them is highlighted in blue.

Note: If you make your before or after search expressions too general, a value could be extracted from a response not in this list. The list shows only responses that match the text value(s) to correlate. To see how the before or after search expressions (and search options) apply to all responses in the current recording, click Preview matching responses.

The Matching Responses window shown below opens:

The Matching Responses window

The responses are listed in the table, along with the text extracted from each. Any value(s) found are listed in each row under the Extracted value(s) column.

Note: This list of values is affected by the Limit the number of extracted items search option (above). For example, if you chose to limit the number of extracted items to two, then only two values will be listed (if more than two values were found). Likewise, the effects of any other search options you selected impact the results shown in this window, such as Search case sensitive.

To illustrate the effect of the Limit the number of extracted items option, the Matching Responses window above is an example of matching responses where no limit is placed on the number of extracted items.

The example below shows the same responses with a limit of two placed on the number of extracted items:

Preview Matching responses with number of matches limited to two

Enter Variable Name Page

The fourth page you see when you create a Data List Correlation rule in the Rules Generation Wizard is the Enter the variable name page shown below.

Enter a Variable Name page in the Rules Generation Wizard

Enter a name in the List variable name box at the top of the page. The variable name is used as the key in the VU's data dictionary, and can be passed as the key parameter to a suitably parameterized get() method (for example, <List<String>>get("<variable name>")) to obtain the extracted value(s). The index of the request or response the value was extracted from is appended as a suffix to the variable name. For example, if the value is extracted from request number 4 and you enter ProductUrl as the variable name, the variable name is stored as ProductUrl_4. Appending the suffix makes it possible to have multiple "live" values of variables.

Note: The variable name you choose could conflict with the names of keys in data sources bound to a VU group running the generated script during a test.

You can optionally enter code in the Code to execute on success/failure boxes. Other than the List variable name box, this page is the same as the common Success/failure options page. The options are for the success or failure of the extract of the value(s) from a response. If the VU receives a response but the before or after search expressions cannot be found within the response content, then the script takes the failure action.

The Select Replacement Policy Page

The fifth page you see when you create a Data List Correlation rule in the Rules Generation Wizard is the Set the replacement policy page shown below.

Select replacement policy page when you create a Data List Correlation rule in the Rules Generatinon Wizard

The Set the replacement policy page allows you to choose what to do with the extracted value(s), if anything is found. The options are as follows:

Which values to replace

  • Do not replace any values sent in requests, just extract and store the list: This is very similar to the default behavior for the Data Correlation Rule - any value or values that are extracted from the response data are stored in a list in the VU's data dictionary, where the key is the variable name entered earlier. It is up to you to then modify the generated script, if you want, to get and use the extracted data stored in the VU's data dictionary.
  • Replace all list items found in the recording: Choosing this option also enables the three Replacement Value options at the bottom of the page. See What to replace the values with, below, for more details on replacement values.
  • Replace the following list items: Choosing this option also enables the three Replacement Value options at the bottom of the page. See What to replace the values with, below, for more details on replacement values. You can add one or more values to the list box by typing in the text box and clicking the Add button. Use the Remove button to remove any unwanted values. Use this option when you specifically want just those values replaced, should they appear in the response data. If none of the values are found in the response data, no replacement occurs.

What to replace the values with

Note: The following three options are disabled if you chose the Do not replace any values option, above.
  • The item at the same position within the list extracted from the response: This means that if any value is found in the response data for subsequent requests that matches any of the extracted values (and is also in the list specified in the Replace the following list items option, if that option was chosen) then do the following: replace that value with a relevant get() method which gets that same value from the extraction list in the VU data dictionary, using the relevant index.
  • A random item from the list: This means that if any value is found in the response data for subsequent requests that matches any of the extracted values (and is also in the list specified in the Replace the following list items option, if that option was chosen) then do the following: replace that value with a value picked randomly from the extraction list stored in the VU data dictionary. The generated script will contain a call to the VU's selectRandomEntryFromList(String key) method which expects the key to the required data dictionary item (using the variable name that you entered earlier).
  • A call to a custom virtual user function: This means that if any value is found in the response data for subsequent requests that matches any of the extracted values (and is also in the list specified in the Replace the following list items option, if that option was chosen) then do the following: replace that value with a call to a method (function) that you can either define later in the generated script, or prepare beforehand in the existing custom VU script. The function you define must accept the following parameters:
    • List<String> list: the list of values that was extracted from the response
    • int replacementItem: the index in the list that points to the value that was found in the subsequent response data
    • String originalValue: the original value that was found in the subsequent response data

The Create Request Filter Page

The sixth page you see when you create a Data List Correlation rule in the Rules Generation Wizard is the common Create Request Filter page. Add any filters you want as described in Create Request Filter.

The Rule Name Page

The seventh page you see when you create a Data List Correlation rule in the Rules Generation Wizard is the common Rule Name and Summary page. Enter a name in the Rule name box, and a summary in the Summary box if you want. See the Rule Name and Summary page for more information about naming your rule and finishing the wizard.

 

This topic was last updated on August 19, 2021, at 03:30:51 PM.

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