groovyguy
5 years agoCommunity Hero
Re: [TechCorner Challenge #9] A script to include custom details to the report
Task: Write a Groovy script for the "TestRunListener.afterStep" event that will post the raw request URL and the full raw response to the printable report.
This is a solution created for [TechCorner Challenge #9]
Here's what I came up with:
// Get the test step's results, PASS or FAIL
def testStatus = testStepResult.getStatus();
// Get a reference to the test step
def testStep = testStepResult.getTestStep();
// Get the test type, looking for soap or rest, not sure if needed for challenge
def tsType = testStep.config.type.toString()
// Skip steps that are not soap or rest
if (tsType.equals("soaprequest") || tsType.equals("restrequest"))
{
// Skip tests that are not PASS
if (testStatus.toString().equals("PASS"))
{
// Build full URL
def endPoint = testStep.getHttpRequest().getEndpoint();
def URI = testStepResult.getTestStep().getHttpRequest().getPath()
def path = "$endPoint/$URI";
def response = testStep.getPropertyValue("RawResponse");
// Add the URL and raw response to the test step result messages, which flows to the test report.
testStepResult.addMessage("Request URL: $path");
testStepResult.addMessage("Raw Response: $response");
}
}