You can use Groovy scripts to work with various entities on all available project levels.
This topic describes how to use a Groovy script to access SOAP operations and REST resources in APIs. This can be useful when you want to change their properties or content.
Where to use
There are several ways to run this script:
- As a Groovy Script test step.
- As a setup or teardown script on the project, test suite, or test case level in functional tests.
Example
The following code demonstrates how to access the login rq
SOAP operation in the sample SOAP project and change the username and password.
Groovy
// Access the interface
def myInterface = testRunner.testCase.testSuite.project.getInterfaceByName("ServiceSoapBinding")
// Access the operation
def myOperation = myInterface.getOperationByName("login")
// Access the request
def myRequest = myOperation.getRequestByName("login rq")
//Change request parameters
myRequest.setUsername("Login2")
myRequest.setPassword("password")
def myInterface = testRunner.testCase.testSuite.project.getInterfaceByName("ServiceSoapBinding")
// Access the operation
def myOperation = myInterface.getOperationByName("login")
// Access the request
def myRequest = myOperation.getRequestByName("login rq")
//Change request parameters
myRequest.setUsername("Login2")
myRequest.setPassword("password")
See Also
Groovy Script Test Step
Setup, TearDown, and Report Scripts
Groovy Scripting Samples
Scripting