Showing posts with label xpath Assertion in jmeter. Show all posts
Showing posts with label xpath Assertion in jmeter. Show all posts

Jmeter SOAP/REST Web Services Testing

Jmeter SOAP/REST Web Services Testing plan creation,in this lesson you will learn web services testing using Jmeter performance testing.Web Services is a client server application component using for communication between multiple systems or applications. Web Services transferring the data between different system with the help of Protocols example http protocols.In order to understand here i am using simple flight web services URL to create web services test plan in Jmeter. Let's create Web Services Test plan in jmeter.

Jmeter SOAP/REST Web Services Testing

Before creating web services test plan in jmeter we should require following details.

1.Web Service URL.
2.Web Service input parameters
3.Web Service Response details

Must Read

Generate Jmeter Report Dashboard
Xpath Assertion in Jmeter
Apache Jmeter Web Test Plan


Steps to Create Web Services Test Plan

1.Open Apache Jmeter from F:\apache-jmeter-3.0\bin folder by double click on jmeter.bat file in windows.
2.Right click on Test Plan Add - Threads - Thread Group,Enter following details

  • Number of Threads(Users):
  • Ramp up Period(in Seconds)
  • Loop Count
Jmeter Web Services Testing
Thread Group


3.Right click on Thread Group - Add - Sampler - SOAP/XML-RPC Request,it will display below details

Jmeter Web Services Testing


  • URL : Web Service url ex : http://localhost:24240/HPFlights_SOAP
  • Send SOAP Action
  • Soap/XML - RPC Data : This text area useful in writing SOAP input parameters in SOAP request as below.
Jmeter SOAP Testing



4.Now add Response Assertion to verify the web services response,Right click on SOAP/XML-RPC Request - Add - Assertions - Response Assertion.

Web Services testing using Jmeter

5.Click on Add in Pattern to Test and enter pattern to verify from Web Service Response as below.

Web Services Response Testing
Response Assertion - Pattern to Test


6.Add View Result Tree from Listeners, Right click on Thread Group - Add - Listeners - View Result Tree.
Apache Jmeter Web Services Testing


7.Save your script.
8.Now run your script and verify View Result Tree window whether it is pass or fail.

View Result Tree - PASS

Apache Jmeter Web Services Testing



View Result Tree - FAIL

Apache Jmeter Soap/Rest web services testing


What have you learn?

1.What is web services?
2.How to create web services test plan
3.How to add web services in jmeter
4.How to verify the web services response with assertions.


Assertions in Jmeter examples

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.

Assertions in Jmeter examples
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
Response Assertion Control Panel

Patterns are

  1. Contains
  2. Matches
  3. Equals
  4. Substring
  5. 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
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
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
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.
BeanShell Assertion
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
HTML Assertion window


Tiday Settings

Tidy settings has below option

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

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
XML Schema Assertion

xpath assertion in jmeter example

Apahe JMeter assertions is very useful and amazing components in JMeter to validate whether request is pass or fail ,in my previous post you learned about Transaction Controller in JMeter to create nested HTTP Samples.In this post you will learn how to use XPath assertion in JMeter with real example to verify the response of HTTP request as per designed Test plans.Please visit w3c tutorials for XPath tutorials.

What is XPath Assertion?

Xpath Assertion in Jmeter tests a response of particular request which will validate the xpath as defines,in case xpath exists in response then that Asseertion is true,if that xpath does not exist's then Assertion is false means fails.

xpath assertion in jmeter example

XPath Assertion examples:

//title[text()='Selenium']- Which will matches the Selenium text anywhere in the response for that request.
/return/message='Success' - Which will matches the Success message in a root level response.

XPath Assertion in Jmeter example

XXPathassertion is useful in validating the response in case unable to find the root element directly in the response or document.Please follow below steps to create Xpath Assertions in your test plan for requests.
1.Open Jmeter from bin folder.
2.Add ThreadGroup.
3.Add Samples may be it could be HTTP Samples/SOAP Request Samples.

xpath assertion in jmeter example

4.Now add Xpath Assertion from Assertions menu to validate the response.
For SOAP response you can write xpath assertion as below to validate particular tag text as <message>Success</message>


Response is


<soap Envelope xmlns:soap="http://schemes:xmlsoap.org/soap/etc"/>
<soap:body>
<ns2:customerdetails xmlns:ns2="http://xmlns:...">
<return>
<code>1</code>
<message>Success</message>
<customerdetails>
<custName>Rajesh kuchana</custName>
<dob>10-01-1986</dob>
<title>Mr</title>
</customerdetails>
</return>
</ns2:customerdetails>
</soap:Body>
</soap:Envelope>

You can write Xpath Assertion to validate the response of request is as below.

First Example:

//retunr/message='Success'

Second Example:

//return/code='1'
/return/customerdetails/title='Mr'

Third Example:

//return[text()='Success']
//return/customerdetails/custName[text()='Rajesh Kuchana']

For Web Applications:

You can prepare Xpath Assertions to validate the web applications also ,please check below examples to clear understansing.

<html>
<head>
<title>Learn Jmeter Tutorials</title>
</head>
<body></body>
</html>

You can write xpath assertion as below to verify title text.
//head/title/text()='Selenium Tutorials'


xpath assertion in jmeter example


Please check Use Tidy(tolerant parser) check box on,it will automatically hide the error while running your script to identify the response and validate it with xpath assertion as below.


xpath assertion in jmeter example



Now check your Summary Report and View Results Tree.

View Result Tree

xpath assertion in jmeter example

Summary Report


What have you learned?

1.XPath Assertion in Jmeter
2.How to write XPath Assertion for Soap Response and Web applications.
3.How to check results using Assertion Results in Listeners.
4.How to prepare XPath assertion to Particular Response.