Skip to main content

Jmeter 5.4.1:- Assertions - Part-02

 

Before going through this please check out earlier blog on Jmeter

As we have already learnt In order to run Jmeter on an weblink.

First we need to have

1. Thread group (Users) 

  a. Number of thread (users)----users going to hit the link

  b. Ramp-up period-- Time taken by the user to hit the link

      as shown above  users are 10 time taken by them is 20 so each user will take 2 seconds to hit the link

   c. If infinite (loop will continue until manually stopped)

   d. uncheck the infinite and enter the  no of times you want to run the loop if you choose 2 as shown      

       below then it means link will be hit by 10 users in 20 seconds then again it will be hit by 10 users in 20 seconds




 By right clicking on thread group you can also add  frequently used 2 listener as shown below

 a. view results tree

 b.view results in table


You should also add sampler to the thread group HTTP Request. as shown below


Once HTTP request is added   mention the server Name and Path

for example you have the weblink. https://reqres.in/api/users?page=2

server link is reqres.in (No need to provide https here)


You can run it by any way by clicking on run button or clicking on green arrow

Once run you can check the result


The loop has run exactly 2 time with 10 user in 1 loop mean 20 hits by user 

you can count that on Results

Tree view

Table view

You can also check No of samples (last line in screenshot) i.e. 20


No we can add the assertion,

Assertion 

It is used to validate response in the request , its used to verify Expected result with the actual result

for the above result success code which is 200

If you have no idea what are response code below is the example 

200 OK

Successful.

201 Created

Created.

202

Accepted

300 Multiple choices


301 Moved permanently


302 Found


400 Bad Request

Bad input parameter. Error message should indicate which one and why.

401 Unauthorized

The client passed in the invalid Auth token. Client should refresh the token and then try again.

403 Forbidden

* Customer doesn’t exist. * Application not registered. * Application try to access to properties not belong to an App. * Application try to trash/purge root node. * Application try to update contentProperties. * Operation is blocked (for third-party apps). * Customer account over quota.

404 Not Found

Resource not found.

405 Method Not Allowed

The resource doesn't support the specified HTTP verb.

409 Conflict

Conflict.

411 Length Required

The Content-Length header was not specified.

412 Precondition Failed

Precondition failed.

429 Too Many Requests

Too many request for rate limiting.

500 Internal Server Error

Servers are not working as expected. The request is probably valid but needs to be requested again later.

502 Bad Gateway


503 Service Unavailable

Service Unavailable.

504 Gateway Timeout



Go to the thread group add frequently used assertion- Response assertion

Once added you can  can change field to test as. "Response Code"
and Pattern matching rule as "Equals"
as we are checking expected result should be equal to actual result that is success
In order to achieve this  click on "add"  button and under "pattern to test"  enter "200" response code
and click on "Run"

This time i made the loop count 1 so it will run for 10 users in 20 seconds

Check the result Tree view (verify that it has run for 10 users) -> sampler result you can verify the response code


Table view

    Once we have verified actual and expected result lets take an example where expected is not equal to actual result

Let's fail the assertion by making the reponse code 500


Go to thread group check the settings  and Now run it

Check the result in tree view you can see Assertion result-received- 200
comparison-500  It's failed 


Check in Table view

To give a more user friendly view of assertion lets add "assertion result" as shown below

For deviation in actual to expected result(500 -200) result failed   Assertion result will be Assertion result will be locked 


When actual and expected are same (200-200) result passed
 assertion result will be

add Duration Assertion 
which use to verify if any of the response took more time then the specified time


Now my current thread group is 10 user in 10 second and only 1 loop count

sample time taken by every hit can be fetched from Table view

we want to check is it is taking more time then 700ms

Go to duration assertion enter 700 ms hits taking time less then 700ms will be passed
Run  and check in result hist taking more then 700ms should be failed
Tree view

Table view

Assertion result
Failed one detailing will be present 


Lets move on to another  assertion. which is a Size assertion .

Size in bytes can be checked

Lets enter  the size in byte 2620 if its <= 2620 then it should pass else it will fail

Before running do not forget to remove duration assertion milliseconds column or it will give result for duration as well as size assertion
check the result  in table format
failed ones are those whose size is greater than 2620


Assertion result


 Moving on to HTML Assertion it is going to check if the format of our response is valid HTML or not


Once run it will throw an error message(before moving on please remove condition in previous assertion added)




in HTML assertion we can provide threshold for the error and warning
It should not throw an error or fail as we have errors and warning within the threshold


assertion result you can check its passed successfully

If you wanted to save all error result in a file 
In HTML assertion -click on Errors only and browse select and save file name


check the file it will have all errors and warnings 


Comments

Popular posts from this blog

Cucumber - Execution of test cases and reporting

Before going through this blog please checkout blog on   Cucumber Fundamentals Cucumber is testing tool which implements BDD(behaviour driven development).It offers a way to write tests that  anybody can understand, regardless of there technical knowledge. It users Gherkin (business readable language) which helps to  describe behaviour without going into details of implementation It's helpful for  business stakeholders who can't easily read code ( Why cucumber tool,  is  called  cucumber , I have no idea if you ask me I could have named it "Potato"(goes well with everything and easy to understand 😂) Well, According to its founder..... My wife suggested I call it  Cucumber  (for no particular reason), so that's how it got its  name . I also decided to give the Given-When-Then syntax a  name , to separate it from the  tool . That's why it's  called  Gherkin ( small variety of a cucumber that's been pickled. I...

Jmeter 5.4.1- Config Elements - Part-03

  Part-01- Installation of Jmeter and HTTP's Recorder click  here Part 02--Previous blog on Assertion Config elements in Jmeter are used to configure or modify the samplers requests made to the server. These elements are added at the same or higher level of the samplers that we want to configure  Let' start with  CSV data config As the name suggest it used to read data from CSV first we need to put data in variables and then use the variables in sampler request. create a new test plan add CSV data set config Add a Thread Group and then add Sampler "Java Request"  Create a CSV file  with some data (Name and Data) and save it  Now go to Jmeter CSs data set config browse and upload the css file create Make few more changes in place of  variable name - Name and Dept Ignore first line - True Delimeter - \t (as suggested) Now move on the Sampler-" Java Request" and rename it with header elements of CSV As we have Name and d...

Beginners tutorial -:working with JMeter in Mac and windows - Part-01

  Prequisite   you should have Java downloaded in your system with Home path set under environment variables.(as of today Java version 8 and higher are required fro jmeter ) for help check out this link Note Always run the jmeter on your secondary browser,  if you give the primary browser for proxy settings then your internet connection will be disrupted for the browser as well as system For ex if you have chrome and firefox and your primary or default browser is chrome then do all the proxy setting in firefox so it won't hamper the system Internet connection  if you have safari as your default browser in your mac os then set proxy in chrome/firefox  MAC Download jmeter from the link  here click on the hypelink under section Binaries  "Apache JMeter( 5.3 ). tgz" file  for Mac   Tar file will get downloaded Double click on the tar file to unzip  once you open the folder  got to bin and search for jmeter.sh file this is a executa...