SoapUI Assertion - Script



Script Assertion technique is the most widely used technique since managing and maintaining hundreds of assertions are quite difficult for a long response message.

SoapUI uses either Groovy Scripting or JavaScript for scripting assertions. The scripting technique is adopted for developing a framework for testing SOAP.

Important Features

  • Scripting allows the user to perform different operations before and after executing a TestCase using setup and tear down methods respectively.

  • Setup is a procedure which is executed before executing a particular method (Example – Object creation and Initialization).

  • Tear down is a procedure which is executed after executing the method (Example - Destroying objects and clean up).

  • This feature is not available in other Assertion types and can be done only through scripting language.

  • It allows the users to perform opening/closing a Project, in order to initialize or clean up project-related settings and also to work with environmental variables, which is very helpful during scripting.

  • It helps in asserting a dynamic Response content.

  • Scripting assertions are used for creating user-defined assertions that are NOT predefined by SoapUI.

Adding Script Assertion

We will follow the same TestCase “ConversionRate TestCase” of CurrencyConvertor.

Step 1 − After clicking Add Assertion, select Assertion Category – Script.

Step 2 − Select Assertion Type – Script Assertion.

Step 3 − Click Add.

Adding Script

The Script Assertion wizard opens, where the script should be defined to validate the response message.

Step 4 − Write a Groovy script to validate the Conversion Rate. It is recommended to have knowledge on JavaScript or Groovy Script before attempting to write the script.

Groovy Script

Step 5 − Click 'Execute' button to trigger the execution.

The output of the Script is shown in the Output pane. It has printed both, Conversion Value as well as the end result (Pass or Fail).

Execute

The information displayed is 'Script Assertion Passed'. Click OK.

Script Assertion Passed

Note − The final Information popup will always display the message 'Script Assertion Passed' as long as the script is syntactically correct. It has no correlation with the assertion within the script.

soapui_assertions.htm
Advertisements