Assertions in Jmeter is very useful components ,Assertions in Jmeter are performs an extra task to verify results of Samplers whether it may be HTTP Requests,SOAP request or REST API services.Assertions are verifies once the main sampler is completes the requests.Mainly assertions are applied for main samplers and not applied on sub-samplers.
Response Assertion
Duration Assertion
Size Assertion
XML Assertion
BeanShell Assertion
MD5Hex Assertion
HTML Assertion
XPath Assertion
XML Schema Assertion
BSF Assertion
JSR223 Assertion
Compare Assertion - The Compare Assertion can be used to compare sample results within its scope
SMIME Assertion
Assertions can be applied to Main samples or Sub samples and default is main samples or you can apply for both together i.e main sample and sub-samples options in assertion window.Let's see one by one assertions explanation in details.
1.Open Apache Jmeter from apache jmeter 3.0/bin/ folder
2.Double click on jmeter.bat file
3.JMeter window opens
4.Now right click on Test plan - add-Threads - Thread Group
5.Right Click on Thread Group - Add - Assertions- here all available assertions will displays.
In Pattern to test textbox you can simply enter text as Success or to verify the title of the page as Jmeter Tutorials or Assertions in Jmeter etc and you can select response Field to test as Text Response , Document(Text) , URL Sampled , Response Code (200 - ok ,404 - HTTP Error etc) , Response Message ,Response Headers and Ignore Status.As per above pattern you can verify the Response of samplers with Response Assertions.
Apply to : Main Sample Only
Response Field to Test : Text Response
Patterns Matching Rules : Contains - It will search entire web page and verify the response
Pattern to Test - Assertions in Jmeter examples
Note:You can add multiple assertions to any samples to verify the response.
Duration Assertion will have below options
1.Apply to : Main Sample and Sub-Samples , Main Sample Only and Sub-Sample Only
2.Duration to Assert : Duration in Milliseconds - The maximum number of milliseconds for each response should receive.
Equals to
Not Equal to
Greater than,
Less than,
Less than equal to
Greater than equal to for a given number of bytes.
In case bytes size is matches than it will Pass other wise assertion will fails.
Beanshell assertion window displays following details
Name - Name of the BeanShell Assertion
Comments - you can provide any comments regarding this assertion
Reset bsh.interpreter before each call - In case this option is selected, than the interpreter will be recreated for each samples and it is useful only when your scripts runs for longer time.
Parameters - Specified parameters to pass into your Beanshell script
Script File - In case you have script file ,you can run your assertion with the file with proper script in the file and path of the script file.
Script - This area provides to option to create a script to validate the response of samples.
Doctype : Doctype has omit,auto,strict and loose list items.
Format : It has HTML,XHTML and XML options
Error Only : Verifies only errors in HTML format as selected formats
Error threshold : No of errors allowed before alloting the particular request response as failed
Warning threshold : Number of warnings allowed before alloting the particular request response as failed
Filename : Name of the file to which report is to be write with results as below details written in txt file
line 2 column 1 - Warning: unknown attribute "xmlns:data"
line 2 column 1 - Warning: unknown attribute "xmlns:b"
line 16 column 1 - Warning: unknown attribute "property"
line 17 column 1 - Warning: unknown attribute "property"
line 18 column 1 - Warning: unknown attribute "property"
line 24 column 128 - Warning: Warning: unescaped & or unknown entity "&zx"
InputStream: Doctype given is ""
InputStream: Document content looks like XHTML 1.0 Transitional
212 warnings, 25 errors were found!
This document has errors that must be fixed before
using HTML Tidy to generate a tidied up version.
The table summary attribute should be used to describe
the table structure. It is very helpful for people using
non-visual browsers. The scope and headers attributes for
table cells are useful for specifying which headers apply
to each table cell, enabling non-visual browsers to provide
a meaningful context for each cell.
For further advice on how to make your pages accessible
see "http://www.w3.org/WAI/GL". You may also want to try
"http://www.cast.org/bobby/" which is a free Web-based
service for checking URLs for accessibility.
The XPath assertion in JMeter to verify the response of samples with the help of XPath,please read this post for clear understanding with real time examples,How to write XPath assertion to verify particular request response in Jmeter.
The XML schema assertion is able to validate XML scheme in particular request response to verify assertion is pass or fail.
Assertion in Jmeter |
Assertions in Jmeter examples
Apache JMeter providing different assertions lists to verify different samaplers as stated above,Following are the assertions are available in JMeter.Response Assertion
Duration Assertion
Size Assertion
XML Assertion
BeanShell Assertion
MD5Hex Assertion
HTML Assertion
XPath Assertion
XML Schema Assertion
BSF Assertion
JSR223 Assertion
Compare Assertion - The Compare Assertion can be used to compare sample results within its scope
SMIME Assertion
Assertions can be applied to Main samples or Sub samples and default is main samples or you can apply for both together i.e main sample and sub-samples options in assertion window.Let's see one by one assertions explanation in details.
How to Add Assertions
Please follow below steps to add different assertions to your Test plan or Thread Group.1.Open Apache Jmeter from apache jmeter 3.0/bin/ folder
2.Double click on jmeter.bat file
3.JMeter window opens
4.Now right click on Test plan - add-Threads - Thread Group
5.Right Click on Thread Group - Add - Assertions- here all available assertions will displays.
Response Assertions
Response Assertions allows you to verify the response of the samples with the help of different patterns as displaying below screenshot.Response Assertion Control Panel |
Patterns are
- Contains
- Matches
- Equals
- Substring
- Not
In Pattern to test textbox you can simply enter text as Success or to verify the title of the page as Jmeter Tutorials or Assertions in Jmeter etc and you can select response Field to test as Text Response , Document(Text) , URL Sampled , Response Code (200 - ok ,404 - HTTP Error etc) , Response Message ,Response Headers and Ignore Status.As per above pattern you can verify the Response of samplers with Response Assertions.
Example:
In application I want to verify the title then we will select options as below.Apply to : Main Sample Only
Response Field to Test : Text Response
Patterns Matching Rules : Contains - It will search entire web page and verify the response
Pattern to Test - Assertions in Jmeter examples
Note:You can add multiple assertions to any samples to verify the response.
Duration Assertion
As per Duration Assertion it will verify each response time whether sample response will receives within specified duration in milliseconds,in case response is not received for that particular request in specified assertion time then that request will get Failed.Duration Assertion Control Panel |
Duration Assertion will have below options
1.Apply to : Main Sample and Sub-Samples , Main Sample Only and Sub-Sample Only
2.Duration to Assert : Duration in Milliseconds - The maximum number of milliseconds for each response should receive.
Size Assertion
Size assertion in JMeter verifies what are the bytes it should have while complete that particular request.Size assertion control panel provides below types .Size Assertion Window |
Equals to
Not Equal to
Greater than,
Less than,
Less than equal to
Greater than equal to for a given number of bytes.
In case bytes size is matches than it will Pass other wise assertion will fails.
XML Assertion
The XML Assertion verify that the gives response data officially contains a correct XML document or not. It does not corroborate the XML based on a DTD or schema to do any additional validation process.XML Assertion window |
BeanShell Assertion
The Beanshell Assertion in jmeter is useful in validate the response of request with the help of BeanShell script,to learn Beanshell scripting please read Beanshell Tutorials.Bean Shell Assertion Panel |
Beanshell assertion window displays following details
Name - Name of the BeanShell Assertion
Comments - you can provide any comments regarding this assertion
Reset bsh.interpreter before each call - In case this option is selected, than the interpreter will be recreated for each samples and it is useful only when your scripts runs for longer time.
Parameters - Specified parameters to pass into your Beanshell script
Script File - In case you have script file ,you can run your assertion with the file with proper script in the file and path of the script file.
Script - This area provides to option to create a script to validate the response of samples.
HTML Assertion
The HTML Assertion validates the HTML syntax of the response data using JTidy option as below mention screenshot.The HTML assertion has below options to verify the response.HTML Assertion window |
Tiday Settings
Tidy settings has below optionDoctype : Doctype has omit,auto,strict and loose list items.
Format : It has HTML,XHTML and XML options
Error Only : Verifies only errors in HTML format as selected formats
Error threshold : No of errors allowed before alloting the particular request response as failed
Warning threshold : Number of warnings allowed before alloting the particular request response as failed
Filename : Name of the file to which report is to be write with results as below details written in txt file
Error HTML Assertion Results:
line 2 column 1 - Warning: unknown attribute "xmlns:expr"line 2 column 1 - Warning: unknown attribute "xmlns:data"
line 2 column 1 - Warning: unknown attribute "xmlns:b"
line 16 column 1 - Warning: unknown attribute "property"
line 17 column 1 - Warning: unknown attribute "property"
line 18 column 1 - Warning: unknown attribute "property"
line 24 column 128 - Warning: Warning: unescaped & or unknown entity "&zx"
InputStream: Doctype given is ""
InputStream: Document content looks like XHTML 1.0 Transitional
212 warnings, 25 errors were found!
This document has errors that must be fixed before
using HTML Tidy to generate a tidied up version.
The table summary attribute should be used to describe
the table structure. It is very helpful for people using
non-visual browsers. The scope and headers attributes for
table cells are useful for specifying which headers apply
to each table cell, enabling non-visual browsers to provide
a meaningful context for each cell.
For further advice on how to make your pages accessible
see "http://www.w3.org/WAI/GL". You may also want to try
"http://www.cast.org/bobby/" which is a free Web-based
service for checking URLs for accessibility.
XPath Assertion
The XPath assertion in JMeter to verify the response of samples with the help of XPath,please read this post for clear understanding with real time examples,How to write XPath assertion to verify particular request response in Jmeter.
XML Schema Assertion
The XML schema assertion is able to validate XML scheme in particular request response to verify assertion is pass or fail.
XML Schema Assertion |