You can use Groovy scripts to perform various actions with responses, like modifying their content, logging the results, and so on.
This topic describes how to use a Groovy script to modify the responses.
Where to use
There are several ways to run this script:
-
As an event handler.
-
As a teardown script on the project, test suite, or test case level in functional tests.
Example
The following code demonstrates how to change a specific value in all response messages with the RequestFilter.afterRequest
event handler:
Groovy
if( request.response == null )
return
// Get the response content.
def content = context.httpResponse.responseContent
// Modify the content – replacing all 555 with 444.
content = content.replaceAll( "555", "444" )
// Override the response.
context.httpResponse.responseContent = content
return
// Get the response content.
def content = context.httpResponse.responseContent
// Modify the content – replacing all 555 with 444.
content = content.replaceAll( "555", "444" )
// Override the response.
context.httpResponse.responseContent = content
See Also
Handling Events
Setup, TearDown, and Report Scripts
Groovy Scripting Samples
Scripting