The Script assertion runs a groovy script to perform custom checks on the message. Use it to verify the message content, headers, properties and other components.
This assertion is available in multiple ReadyAPI applications. Depending on the application, it validates the following data:
In... | Checks... | To learn more... |
---|---|---|
The request or response. | ||
The response. | See Security Assertions. | |
The request. |
Write a script verifying the value you need. Some script examples are available below.
Tip
If the font of the editor is not comfortable for you, change it by using Ctrl + mouse wheel.
Assertion scripts have access to the following objects:
Object
Description
log
An Apache
Logger
object that you can use to post messages to the test log.For information on methods, see the Apache
log
object documentation.context
A
TestCaseRunContext
object that provides scripting interface to test steps and the test runner.For information on methods, see the Context object documentation.
messageExchange
A
MessageExchange
object that provides scripting interface for request and response data, and for information on request execution.For information on object methods, see the MessageExchange object documentation.
Click
to test your script.
Important
Make sure you have the value to assert before testing the script.
The following script validates the response’s HTTP header:
// Check for the Amazon ID headerassert messageExchange.responseHeaders["x-amz-id-1"] != null
The following script verifies that the response was received within the specified time limit:
// Check whether the response time is less than 400 msassert messageExchange.timeTaken < 400
The following script verifies that the attachment exists:
// Check whether there are 2 attachments availableassert messageExchange.responseAttachments.length == 2
The following script verifies that the
RequestId
XML element exists:// Import the XmlHolder namespaceimport com.eviware.soapui.support.XmlHolder // Check for the RequestId element in the responsedef holder = new XmlHolder( messageExchange.responseContentAsXml ) assert holder["//ns1:RequestId"] != []