Saturday, February 20, 2016

Jmeter - Reply Assertion To Assert Reply Code

| Saturday, February 20, 2016
Response assertion inward jmeter is virtually of import chemical ingredient equally it helps y'all to assert the reply of asking inward your software charge attempt out plan. It volition exhibit asking effect failed if reply of asking is non equally expected too exhibit top if response of asking is equally expected. So y'all tin sack verify your software charge attempt out effect using the reply assertion. In this section, We volition larn how to assert reply code of asking using reply assertion.

Add Response Assertion In Your software charge attempt out plan
You tin sack add together assertion nether asking or parallel to request. To add together reply assertion nether request,
  • Right click on asking -> Select Add -> Assertions -> Response Assertion equally shown inward bellow given image.

It volition add together reply assertion nether request.

Example : Assert Response Code Using Response Assertion
I accept created real uncomplicated instance to demonstrate y'all how reply assertion truly works. We volition assert reply code of software spider web application's asking inward this example. If y'all know, reply code 200 represents your HTTP request has succeeded.

In this example, We volition assert for reply code 200 using reply assertion. We volition banking concern agree reply code for bellow given two requests. One for valid too i for invalid.
  1. newtours.demoaut.com(Valid URL which returns reply code : 200)
  2. newtours1.demoaut.com(Invalid URL which returns reply code : Non HTTP reply code)
I accept added two HTTP requests nether thread grouping for higher upward URLs equally shown inward bellow image. 


Also added Response assertion nether both requests amongst same parameter configuration. Here our aim is to assert reply code 200 of HTTP asking thence assertion parameters configuration is equally bellow.

Assertion parameters config for both request's reply assertion : 
  • Apply To = Main Sample only.
  • Response Field to Test = Response Code.
  • Pattern Matching Rules = Contains.
  • Pattern To Test = 200.


Note : In our instance software charge attempt out plan, Both reply assertions has same higher upward parameter configuration.

Above configuration of reply assertion volition banking concern agree reply code of HTTP requests. If reply code contains 200 too thence volition testament travel passed. Else it volition exhibit effect equally fail.

I accept added Assertion Results listener nether both requests equally shown inward higher upward ikon to sentiment assertions effect on attempt out execution.

Thread grouping configuration is equally bellow.


Now run higher upward software charge attempt out plan. Assertion results of both assertions volition facial expression similar bellow.



Assertion Result of 1st HTTP request : Not display whatever fault inward assertion effect of of 1st HTTP request. That agency HTTP request's reply code is 200 equally expected.

Assertion Result of sec HTTP request : Display fault inward assertion effect of sec HTTP request. That agency HTTP request's reply code is non 200 thence assertion is failed.

Also sentiment effect tree of both requests volition looks similar bellow. You tin sack come across that reply code for 1st asking is 200 thence it is pass. But reply code for sec asking is Non HTTP reply code thence it is failed.


This way y'all tin sack assert reply code of whatever HTTP asking of your software charge attempt out innovation equally per your requirement.

Related Posts