imp
imp

Reputation: 436

Jmeter how to use a response assertion in an include controller

I have a large/complicated project I'm trying to setup in Jmeter 3.

The API request/response is in one folder and in another folder I use an include controller for the API and want to put an assertion inside this. It's a test fragment, there are many different responses I want to put into their own jmx and then call them from another jmx/test plan(See below table).

|topdir
||API (literally just the requests)
|||api1
|||api2
||fragments (this contains the api requests via an include controller)
|||api1_1(with response assertions of abc)
|||api1_2(with response assertion of bca)
||tests
|||testplan A (include controller of fragment api_1)
|||testplan B (include controller of fragment api_2)
|||testplan C (include controller of fragment api_1 and 2)

I'm trying to make my life easier in terms of reusability because i'm goin to be using this bit a lot in many JMX files.

My problem is, no matter how I arrange the Test plan:

|TestPlan
|View results tree
||ThreadGroup
|||Include controller (to test fragment)

Or the first test fragment:

|TestFragment
||simple controller (this can be removed without effect)
|||include controller (to wsdl API request)
|||response assertion

Why does the response assertion not pickup the API response? The api file is setup like this:

|TestPlan
||TestFragment
|||HTTPRequest
|||XmlFormatter

Kindly note I have to put this assertion in middle test fragment since rebuilding each response assertion for the many thousands of tests isnt feasible

I have also tried using the prev.getResponseDataAsString() in jmeterVariables portion of the response assertion but I get a 'response was null'.

I've tried now with setting a variable on the API jmx, printing the variable in 2nd fragement (where i'm trying to do the assertion) and the variable is blank :(. This layer of abstraction seems to be the problem - again, why wont it read variables? Surely it is in scope(Especially if I remove the simple controller from it?

Upvotes: 0

Views: 372

Answers (2)

imp
imp

Reputation: 436

OK - I figured out a way around this using the jsr223 assertion in the test fragment:

if( vars.get('ResultDescription')!=vars.get('descSuccess')){
    prev.setSuccessful(false) // this will fail the step
    prev.setResponseMessage('Got: '+vars.get('ResultDescription')) // you will see this message in the failed sampler result
}

and setting that variable straight from the API via an xpath extractor

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168092

I cannot reproduce your issue with the following setup:

enter image description here

As you can see, the Response Assertion "catches" the response body of a Sampler which is loaded via the Include Controller and if there is no match - it marks the Sampler(s) as failed.

Be aware that JMeter Assertions are applied to all Samplers in their Scope.

If it doesn't reflect your setup please provide a minimal reproducible example and indicate the desired/expected behaviour.

Upvotes: 0

Related Questions