Showing posts with label Jmeter Assertions. Show all posts
Showing posts with label Jmeter Assertions. Show all posts

Saturday, February 20, 2016

Jmeter - Reply Assertion To Assert Reply Code

Jmeter - Reply Assertion To Assert Reply Code

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.

Friday, February 19, 2016

Jmeter - Answer Assertion To Assert Answer Message

Jmeter - Answer Assertion To Assert Answer Message

Earlier nosotros learnt how to role reply assertion inwards your jmeter software charge exam to assert reply code of asking inwards my previous post. So forthwith you lot already aware close how response assertion works. Here nosotros volition run into event on how to role reply assertion inwards your software charge exam to assert reply message.

Example : Assert Response Message Using Response Assertion
I accept prepared uncomplicated event on how to assert reply message of asking using reply assertion. If HTTP request has been succeeded thence nosotros volition become reply message OK.

We volition assert reply message for bellow given ii requests.
  1. newtours.demoaut.com(Valid URL which returns reply message : OK)
  2. newtours1.demoaut.com(Invalid URL which returns reply message : Non HTTP reply message)
All other configuration is same every bit described inwards my PREVIOUS POST except reply assertion configuration. Configuration of reply assertion for both requests is every bit bellow.
  • Apply To = Main Sample only.
  • Response Field to Test = Response Message.
  • Pattern Matching Rules = Contains.
  • Pattern To Test = OK.


Note : Both assertions accept same configuration inwards in a higher house software charge exam plan.

Now if you lot run inwards a higher house event software charge exam plan, Assertion results for both requests volition expect similar bellow.


In number you lot tin dismiss run into that assertion of valid asking is dice every bit reply message is received "OK" but assertion of invalid asking is failed every bit reply message received "Non HTTP response".

This agency you lot tin dismiss assert reply message of asking using reply assertion inwards software charge exam plan.
Jmeter - Using Duration Assertion Amongst Example

Jmeter - Using Duration Assertion Amongst Example

Duration assertion is used to assert the answer fourth dimension of asking inwards jmeter software charge exam plan. It volition assert that answer of asking is received inside given amount of fourth dimension or not. If answer of asking is received inwards given amount of fourth dimension thence it volition locomote buy the farm together with if it exceeds given amount of fourth dimension thence it volition locomote fail. Let's acquire how to purpose duration assertion inwards jmeter software charge exam plan.

Add Duration Assertion In Software Load Test Plan
You tin mail away add together duration assertion parallel to asking or nether asking of your software charge exam plan. To add together it nether request,
  • Right click on asking -> Add -> Select Assertions -> Duration Assertion. Please aspect inwards to the bellow given image.

It volition add together duration assertion nether selected request.

Example : Assert Response Time of Request Using Duration Assertion
I attain got prepared uncomplicated event to tech you lot purpose of  duration assertion inwards jmeter software charge exam plan. Test innovation config is equally bellow.
  • I attain got added ii HTTP request.
  • Under each request, Added Duration Assertion and Assertion Results.
  • 1st request's Duration Assertion : Set Duration inwards milliseconds = 200
  • 2nd request's Duration Assertion : Set Duration inwards milliseconds = 5000
  • Thread Group Config : Number of Threads = 1, Ramp upwards menses = 1, Loop count = 1.
  • Added sentiment consequence inwards tree listener nether thread group.

You tin mail away meet that duration inwards milliseconds = 200 for 1st duration assertion together with duration inwards milliseconds = 5000 for 2nd duration assertion.

Now when you lot piece of occupation to a higher house sample software charge exam plan, consequence of 1st duration assertion volition looks similar bellow.


You tin mail away meet inwards consequence that asking has taken 1274 milliseconds to consummate which is greater than expected 200 milliseconds thence assertion is failed. 2nd assertion is buy the farm equally nosotros laid duration inwards milliseconds = 5000.

This agency you lot tin mail away purpose duration assertion inwards your software charge exam innovation to assert fourth dimension duration of request.
Jmeter - Xpath Assertion Utilisation Amongst Example

Jmeter - Xpath Assertion Utilisation Amongst Example

XPath Assertion is useful to assert the page element's xpath. You tin acquire to a greater extent than nearly XPath together with how to honour it postulate on THIS PAGE. Earlier nosotros learnt unlike assertions of jmeter to purpose them inward software charge examination innovation then i recall forthwith you lot are good aware nearly assertion. Let's acquire XPath assertion amongst example to know how to purpose it inward your practical software charge examination innovation using jmeter.

Add XPath Assertion In Software Load Test Plan
Mostly XPath assertion is beingness added nether request. To add together it nether request,
  • Right click on asking -> Add -> Select Assertions -> XPath Assertion. See bellow given image.

It volition add together XPath assertion nether request.

Example : Assert XPath Of Element Using XPath Assertion
I accept develop real elementary software charge examination innovation to assert the xpath of http://jmeter.apache.org/ website's logo(See bellow given image) inward jmeter charge examination plan. Function of XPath assertion is real simple. It volition cheque if chemical component subdivision amongst given xpath is acquaint on page or not. Assertion volition piece of occupation past times if given xpath is acquaint on page. Else it volition fail. Using xpath assertion you lot tin confirm that targeted chemical component subdivision is displayed on requested page.


I accept added ii asking together with xpath assertion nether both requests inward my jmeter software charge examination plan. 1st request's xpath assertion has valid xpath(//img[@alt='Logo ASF']) together with 2d request's xpath assertion has invalid xpath(//img[@alt='Logo ASF1']) every bit shown inward bellow image. Actual XPath of logo is "//img[@alt='Logo ASF']".


Configuration of 1st request's XPath assertion is every bit bellow.

  • Apply to = Main sample only.
  • XML Parsing options : Selected options -> Use Tidy (tolerant parser), Quiet
  • XPath Assertion = //img[@alt='Logo ASF']

Configuration of 2d request's XPath assertion is every bit bellow.
  • Apply to = Main sample only.
  • XML Parsing options : Selected options -> Use Tidy (tolerant parser), Quiet
  • XPath Assertion = //img[@alt='Logo ASF1']
Only divergence inward configuration of both xpath assertions is xpath syntax. Everything else is same.

HTTP Request configuration for both requests is same every bit bellow.


Thread grouping config is every bit bellow.


Now if you lot run inward a higher house examination plan, consequence volition looks similar bellow.


In consequence you lot tin run across that 1st asking is pass. That agency nodes amongst given xpath syntax is institute on page. 2d request's xpath assertion is failed together with display Assertion failure message: "No Nodes Matched //img[@alt='Logo ASF1']".

This way you lot tin purpose xpath assertion inward your software charge examination innovation to assert xpath of whatever element.
Jmeter - Size Assertion Amongst Example

Jmeter - Size Assertion Amongst Example

Size assertion inwards jmeter software charge examine innovation is useful to assert the byte size of asking response. You tin purpose dissimilar weather inwards answer assertion like equal to, non equal to, greater than, less than, greater than or equal to, less than or equal to a given position out of bytes for response. Here nosotros volition larn how to purpose size assertion inwards your jmeter software charge examine innovation to assert size of response.

Add Size Assertion In Test Plan
Practically nosotros need to add together size assertion nether request. To add together size assertion nether request,
  • Right click on asking -> Add -> Select Assertions -> Size Assertion. See bellow given image.

It volition add together size assertion nether request.

Example : Using Size Assertion In Jmeter Test Plan
I convey prepared sample jmeter software charge examine instance to demo yous how genuinely size assertion works. I convey added two HTTP requests amongst size assertion equally shown inwards bellow image.


Size assertion configuration for both requests is equally bellow.


1st HTTP request's size assertion config

  • Apply To : Main Sample Only
  • Response Size Field To Test : Full Response
  • Size In bytes : 5000
  • Type Of Comparison : >=(Greater than or equal to)

s HTTP request's size assertion config
  • Apply To : Main Sample Only
  • Response Size Field To Test : Full Response
  • Size In bytes : 5000
  • Type Of Comparison : <=(Less than or equal to)
Only departure inwards both assertion's config is type of comparison.

Both HTTP request's config is same equally bellow.


When yous run higher upward examine plan, Result volition looks similar bellow.


In trial yous tin encounter that 1st asking is top away that agency asking answer size is greater than or equal to 5000 bytes which nosotros convey laid inwards 1st request's size assertion. Size assertion of s asking is neglect in addition to display Assertion failure message: "The trial was the incorrect size: It was 10,256 bytes, but should convey been less than or equal to 5,000 bytes."

This way yous tin purpose size assertion inwards your jmeter software charge examine innovation to assert size of asking response.