https://support.smartbear.com/readyapi/docs/soapui/steps/groovy.html
Get test case object
To obtain the object which refers to the containing test case, use the following code snippet:
testCase
object, you can access and manipulate test items of the project.
Fail the test run
There are two ways to fail the test run from your scripts:
-
To fail only the Groovy Script test step, throw an exception in your script:
throw new Exception(“Result not as expected!”)
If the Abort test if an error occurs option is enabled in TestCase Options, the test will stop. Otherwise, it will continue.
-
To fail the entire test run, use the
testRunner.fail
method. This marks the test failed and stops the test run regardless of the Abort test if an error occurs option.testRunner.fail(“Result not as expected!”)
Stop test execution
The testRunner
scripting object has two methods to stop the current test run:
-
cancel(String reason)
– Stops the test run and marks it as Canceled. The string argument specifies the reason. -
fail(String reason)
– Stops the test run and marks it as Fail. The string argument specifies the reason.
Valid HTTP Status Codes assertion for the Test Request test step:
Valid HTTP Status Codes and Invalid HTTP Status Codes by using the setCodes
method of the Assertion
object.
You can get this object when creating it in the following way:
// Get the test step object
def ts = testRunner.testCase.getTestStepByName(“Test Request”)
// Search all assertions
for ( e in assertionsList)
{
// If the assertion name matches
if (e.getName() == “Valid HTTP Status Codes”)
{
// Delete the assertion
ts.removeAssertion(e)
}
}
Get property value
To get a property value:
-
Obtain the containing object.
-
Use the
getPropertyValue()
method to get a property object.
For example, the following code snippet gets a test suite property:
// Get username property from the test suite object
def username = testRunner.testCase.testSuite.getPropertyValue( “Username” )
Set property value
To write a value to a property, use the setPropertyValue()
method. For example, the following code snippet, specifies the Username parameter of the HTTP Request test step:
// Write the username to the HTTP Request
testRunner.testCase.testSteps[“HTTP Request”].setPropertyValue( “Username”, username )