Mori
Mori

Reputation: 2574

XML Path Assertion in Jmeter

I want to Assert a value (ActualCode) in XPath Assertions. I am experienced with JSON Path Assertion but totally new to XML one. How could I assert the 'ActualCode' value here?

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
 <S:Body>
  <ns2:CreateValidCode xmlns:ns2="http://www.example.net/lmsglobal/ws/v1/extint/types" xmlns="http://www.example.net/lmsglobal/xsd/v1/types" xmlns:ns3="http://www.example.net/lmsglobal/ws/v1/extint/notification/types">
     <ns2:ValidCode>ActualCode</ns2:ValidCode>
     <ns2:State>1</ns2:State>
  </ns2:CreateValidCode>

Upvotes: 0

Views: 802

Answers (1)

Dmitri T
Dmitri T

Reputation: 168227

  1. Create a .properties file, i.e. namespaces.properties somewhere, for example in JMeter.s "bin" folder.
  2. Add the following lines to the namespaces.properties file

    S=http://schemas.xmlsoap.org/soap/envelope/
    ns2=http://www.example.net/lmsglobal/ws/v1/extint/types
    
  3. Add the next line to user.properties file, it lives under JMeter "bin" folder as well

    xpath.namespace.config=namespaces.properties
    
  4. Restart JMeter to pick the property up
  5. Add XPath Assertion as a child of the request which returns above XML
  6. Tick Use Namespaces box
  7. Put the following query into the "XPath Assertion" input:

    //ns2:ValidCode/text()='ActualCode'
    

That should be it.

Useful material:

Demo:

XPath Namespaces Demo

Upvotes: 1

Related Questions