This topic explains how to configure and apply the JSON Data Bank tool in SOAtest and Virtualize. This tool extracts JSON values (e.g., from a request or response message) so that they can be used in another place. Data can also be sent to a Writable Data Source and accessed in the Extension Tool or it can be sent to variables for easy reuse across the test, Responder, or Action suite.
Sections include:
The JSON Data Bank tool was re-implemented in version 9.7. The previous implementations are deprecated: any existing tools will continue to work, but all new JSON Data Banks you add will use the new implementation. This topic focuses on the current JSON Data Bank implementation.For details on the deprecated JSON Data Bank, see JSON Data Bank Deprecated. |
This tool enables you to extract certain JSON values (e.g., from a request or response message) so that they can be used in another place. The JSON Data Bank tool can be chained to any other tool that outputs JSON. It can extract any information from the JSON and make that information available for later use.
For example, you can configure a test suite that tests a bank’s service transactions. Test 1 of that test suite can log on to the service using a User ID, then the JSON response would return a session ID back to Test 1. Test 2 of that test suite can be configured to use the session ID from Test 1 to perform transactions. You can configure any of the tests in a test suite to use JSON response parameters as JSON request parameters.
Users typically configure a JSON Data Bank by accessing the "Use Data Source Wizard" while parameterizing a value in a tool such as the REST Client or Messaging Client tool. This provides a quick, intuitive, and largely automated way to extract data from one tool and use it another. You simply go to the tool where you want to insert extracted data, then use a wizard to specify what data (e.g., from what tool) you want to extract. This is the usage model demonstrated in the Storing Results to Be Used in Subsequent Tests tutorial. This same method can be used to extract data that is used to set a variable. Alternatively, you can manually configure a JSON Data Bank tool to extract data from one tool, then manually configure other tools to use the extracted values.
Video TutorialIn this video, you'll learn how to extract values from JSON responses and reuse them in other tests. |
To use the "Use Data Source Wizard" wizard to configure a JSON Data Bank:
Ensure that you have a test suite or action set with at least two tools.
Under Expected Message, indicate what element(s) you want to extract, then click Add. The right panel lists the values you have configured for extraction and shows the name of the data source column where each value will be stored (if you keep the default setting).
If you later want to specify additional options (e.g., if you want to change the name of the column used to store the value, you want the value saved to a writable data source, or you want the value stored to an existing variable) —or if you want to modify the referenced element—then select the appropriate element in table on the right and click Modify. Next, configure the options as needed, then click OK.
For details on how to use this dialog to configure additional options, see JSON Selector Reference.
You can also manually chain the JSON Data Bank tool to a tool within the test, Responder, or Action suite. To configure the JSON Data Bank as a chained tool, complete the following:
Ensure that you have a test suite or action set with at least two tools.
Right-click the node for the tool associated with the data you want to extract, then choose Add Output.
In the Add Output wizard, indicate where you want to extract the value from, select JSON Data Bank from the list of tools, then click the Finish button. A JSON Data Bank node displays below the tool.
Use the available controls to specify what element you want to extract. To extract an element, select a value from the JSON tree and click the Extract Element button. The value you added displays in the Selected Element list with a Data Source Column name containing the name of the tool the value came from, as well as the extracted value.
The left panel displays the expected JSON response used to create a template from which you can select elements. If JSON Data Bank receives a valid JSON message (e.g., from traffic or as defined in the client tool it is attached to), this panel will be populated automatically. Alternatively, you can copy a sample message into the Literal or Tree tabs. Note that the expected JSON does not get saved by default; if you want to save it, enable the Save Expected JSON option. |
If you later want to modify the element referenced by the extraction, click Modify, then modify it as desired. See JSON Selector Reference for details.
After adding and/or modifying the extraction, configure the tool that you want to use the extracted data.
Set the value to Parameterized, and choose the appropriate item from the drop-down. For example, if you saved the value to the "title" data source column, you would select it as follows.
The following options can be configured in the lower portion of the JSON Data Bank tool configuration panel.
XPath: Displays the selected XPath. See JSON Selector Reference for details.
You can configure the Console view (Window> Show View> Console) to display the data bank variables used during test execution. For details, see Monitoring Variable Usage.
By default, empty and missing elements will not be extracted. This could impact the integrity of the JSON response for use in a Writable Data Source.
For instance, assume you have the following JSON:
{
"e": 5,
"e": "",
"e": 6
}
Also assume that you want to create an extraction for all 'e'
elements. To do this, select the first element, then click Extract Element.
Next, select the new extraction, then click Modify.
In the Modify dialog, change the XPath to extract from /root/e[1]/text()
to /root/e/text()
.
This will extract all three text nodes.
Next, click Data source column and select a writable data source column. When the Data Bank is executed, the writable data source will only contain two rows because the second element is missing text:
ROW 1 = 5
ROW 2 = 6
If you want to write the empty value, change the XPath from /root/e/text()
to /root/e
and ensure that Content Only is enabled.
This way, all three elements are extracted, including their content. You can optionally enable the Extract empty element as option to change the value extracted for the empty value. The Data Bank will now append the empty value to the writable data source:
ROW 1 = 5
ROW 2 =
ROW 3 = 6