0

I would like to uses jmeter for api functional testing, the jmeter dashboard reporting is not ideal for functional testing.

I have attempted to integrate extent 2.41.2 reporting with groovy script that validates responses (http and expected response code).

I have attempted to use the idea given in Using extentreports for jmeter test results

However that has failed. I used a js2322 assertion to check for valid responses, but then I get errors whenever attempt to run.

I'm not sure whether it should be setup as post processor step instead of an assertion.

Has anyone got any ideas on how this can be achieved?

Nobody
  • 549
  • 1
  • 10
  • 24

1 Answers1

0

You can assert result by using prev which is SampleResult:

prev - (SampleResult) - gives access to the previous SampleResult (if any)

Here's example of checking token exists in response and if not return relevant assertion:

import org.apache.jmeter.assertions.AssertionResult;
boolean assertToken = prev.getResponseDataAsString().contains("token");
prev.setSuccessful(assertToken);
if (!assertToken) {
   AssertionResult assertionResult = new AssertionResult("Assertion expected to contain token")
   assertionResult.setFailureMessage("Assertion failure message: Test failed: text expected to contain /token/");    
   assertionResult.setFailure(true);
   prev.addAssertionResult(assertionResult);
}
Ori Marko
  • 56,308
  • 23
  • 131
  • 233