Accessing JSON data bank from Jython
Comments
-
Hi aa_dfw,
You can save the values in to a test suite variable and then using the Parasoft api methods:
context.getValue("variable_name") and context.setValue("variable_name","new_value"); to pull and set the new values.Example script:
import com.parasoft.api.*;
public void exampleScript(Object input, ExtensionToolContext context){ //Application.showMessage(string) //This is grabbing the variable x(If the varible exist) from the test suite variables and displays it in the console window. Application.showMessage(context.getValue("x")); //This will set a new value for x test suite variable named x context.setValue("x","1000"); Application.showMessage(context.getValue("x")); //This will print out the input in this example the input was set in the extension tool //If chaining from another tool such as a messaging client the output of the tool will be the Object input Application.showMessage(input.toString()); }
2 -
Señor aa_dfw,
An alternative solution to @Ramiro Martinez's lovely script would be to use the "Allow alteration" option available under JSON databank >options.
This option allows you to alter specific element-values and store them in the databank.After you've altered the element, you can extract the same element (under Extract tab) and use the updated value in subsequent tests.
1 -
Hi OmarR,
Thanks for your reply. This would be perfect, but I'm not sure how to perform the following modification of he current string: I need to replace all occurrences of "\" in the current string with "" (basically removing all "\" from the string. Any suggestions?Thanks,
Amela0 -
A couple things to keep in mind. Please be aware that backslash is an escape character in JSON. When you extract a JSON string value, like with a JSON Data Bank, then any JSON escape sequences are automatically decoded. You don't need to do this manually by script or something. For example, backslash-double-quote (\") would automatically become a double-quote ("), backslash-t (\t) with the tab character, double-backslash (\\) with a single backslash (\), etc. The data bank column will have the logical string value, not way it needed to be encoded within a JSON document.
1