Table of content

Xpath Assertion in JMeter

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

XPath assertion is useful in validating the response in case unable to find the root element directly in the response or document.

The following Example Demonstrates the Extracting Xpath from the Given Link and validates the Xpath.

  • Launch JMeter, and add Thread Group to the Test Plan.
  • Next, add HTTP Request sampler to the thread Group and then enter the Server address and path.
    http-request-with-orange-hrm-address-jmeter
  • In this example, I am using the given link: https://orangehrm-opensource-demo.orangehrmlive.com/ to extract the Xpath.
  • I am going to verify whether this logo is present in the XPath or not.
  • Once the page has been opened, right-click on the logo and then select Inspect.
    select-inspect-option-jmeter
  • The source page will open as below.
    copy-the-xpath-of-the-logo-jmeter
  • Try to copy the Xpath of the Logo and then paste it in the editor for future use.
    copied-xpath-in-editor-jmeter
  • Next, add XPath Assertion to the HTTP Request.(Right-click on HTTP Request-->Add-->--Assertions--Xpath Assertion).
    add-xpath-assertion-to-request-sampler-jmeter
  • Next, Enter the copied XPath inside the Xpath Assertion and select the Use Tidy(tolerant parser) option as below.
    enetr-copied-xpath-jmeter
  • Now add View Result Tree and Assertion Result Listener to the Thread Group to see the Result.
  • Save and run the Thread Group. After the Execution, the request will be passed without any error.
    executing-xpath-assertion-jmeter
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions