All about SOAP UI and Groovy in it

Assertions are generally the simple and most sought validations that can be enforced in SOAP UI.

For SOAP response we have an assertion step called ‘XPath Match‘, which validates the value yielded by the specified xpath with the one provided staticly.

When we add ‘XPath Match’ assertion using the Add Assertion button, we see the below window.

XPath Match Assertion

XPath Match Assertion

There is a button called ‘Declare‘ (present in free version of SOAP UI also), it automatically declares all the namespaces of SOAP response. After declaring the namespaces using this ‘Declare’, mention the xpath of the node whose value is to be validated. Here the xpath could start from the node which comes just after the <soap:Body> node (i.e., <soap:Body> node’s immediate child). For example, if say the response xml is:

Sample Response

Sample Response

then to validate on the value of ‘Status‘ node, the xpath that should be present in XPath Expression blockalong with all the declared namespaces is

//p77:GetReportResponse/p77:GetReport/ReportResponse/Status

And, now we need to provide some expected value, inside ‘Expected Result’ block which shall validated against the corresponding node value. There is an option called ‘Select from current‘, which actually fetches the value of that xpath, from the current response. Another option called ‘Test‘, is used to test right away.

 

(Please feel free to get back if u have any trouble…as i am just a mail away…leave a comment otherwise)

Comments on: "Using XPath Assertion in SOAP UI" (41)

  1. Hi…I have a small question.

    Suppose for the given below response I want to get value of “returnedItems” using Xpath. How I will get that value.

    SOAP-ENV:Envelope xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/”>

    Item1

    • Hi Sandeep,

      Might be an oversight or misapprehension by the site, I see an incomplete SOAP response in your comment above.
      Could you send me that response again, so that I can help.

      Thanks
      Devakara

  2. Budi Wibowo said:

    I have a question,

    I use SoapUI 2.5. After I added XPath match Assertion step and just let SoapUI automatically declared all namespaces from the response XML, I kept getting the assertion error:

    RuntimeException:net.sf.saxon.trans.XPathException: XPath syntax error at char 0 in {}: Unexpected token “” in path expression.

    Do you know why? Thx.

  3. Decalare required namespaces there, issue will be resolved

  4. Hi,

    After declaring the Name space by using the declare option from tool and from the expected result i i selected the option ” select from current” than i got below mentioned error message..

    “java.lang.RuntimeException: net.sf.saxon.trans.XPathException: XPath syntax error at char 0 in {}: Unexpected token ” ” in path expression”

    Thanks in Advance

    • Hi,

      After declaring the Name space by using the declare option from tool and from the expected result i i selected the option ” select from current” than i got below mentioned error message..

      “java.lang.RuntimeException: net.sf.saxon.trans.XPathException: XPath syntax error at char 0 in {}: Unexpected token ” ” in path expression”

      Thanks in Advance

  5. Emilia Ipate said:

    Clear explanation. Put on practice (took only 5 minutes).

    Thanks a lot,
    Emilia

    • Thank You, Emilia Ipate.

      Cheers,
      Devakara

    • Hi,
      I am learning soapUI,Please explain the Xpath Match assertion and XQury assertion with right example.(i mean free WSDL available from the net).

      I tried the following example.
      WSDL:http://www.webservicex.net/globalweather.asmx?wsdl

      Request
      ————–


      India

      Response
      —————-

      <![CDATA[

      British Indian Ocean Territory
      Diego Garcia

      India
      Ahmadabad

      India
      Akola

      India
      Aurangabad Chikalthan Aerodrome

      India
      Bombay / Santacruz

      Could ypu please explain how to apply Xpath and Xquery assertion the given WSDL.

      Thanks

    • SOAP begineer said:

      RuntimeException:net.sf.saxon.trans.XPathException: XPath syntax error at char 0 in {}: Unexpected token ” ” in path expression

      can some please help me to remove this error while doing xpath match

    • Hi

      Having the same issue as Mahesh. He said ““java.lang.RuntimeException: net.sf.saxon.trans.XPathException: XPath syntax error at char 0 in {}: Unexpected token ” ” in path expression”

      Emilia Ipate then replied saying “Clear explanation. Put on practice (took only 5 minutes).
      Thanks a lot,
      Emilia

      After having through the rest of the page, please can you explain where the explanation is that Emilia is referring to so I too can put this in practice within 5 minutes.

      Thanks

      Chas

  6. NarayanSwamy said:

    Hi can anybody help me how to create dummy logins and password using groovy and vlidate them using xquery assertions,
    Thanks in advance

  7. Is it possible to select nested XML using XPath? I have the following that I need to play with:

    <![CDATA[

    … and so on.

    I’m tried //ReplyXML/xml
    //ReplyXML/?xml
    //ReplyXML/ CDATA

    and many others.

  8. I am currently facing the same problem…
    basically tag means “Content Data”
    that will be ignore by XPath,
    so the only way seems to be trim them by program…

  9. Hi ,

    I need to take out a value from a Node in Response and Compare it against value from the request. I am able to use XPATH assertion to get to value from Response . How can i take out the value from the request to comapre with this ? what is syntax for pointing to request in the XPATH assertion expression?

    • Hi Praveen,

      You want to compare a request node value to response node value, for which instead of XPath Match/Assertion try using Script assertion.

      In Script assertion, using messageExchange and context variables we can get hold of request/response xml and thus comapring the required node values with assert statement would do your job.

      Hope this helps.

      Thanks,
      Devakara.

  10. Praveen said:

    Pls let me know what is the basic differnce between XPath and Xquery assertions?

  11. jimkitsos said:

    In the sample response you have provided in the example, is it possible to get the ‘RefNum’ only if the ‘Status’ is ‘OPERATION SUCCESSFUL’?

    • devakara said:

      Hi,

      XPath Assertion doesn’t return you any Value; it just validated your response, with the provided XPath and value – results an Assertion success/failure.

      If you want to do some operations with the RefNum, based on some conditions, you should instead use Script Assertion – that would provide you more control.

      Hope this helps.

      Thanks,
      Devakara.

      • jimkitsos said:

        Hi Devakara,

        Thank you for the reply. I used a groovy script to do what I needed.

  12. SOAP begineer said:

    Hi,
    Can someone please tell me what will be the Xpath expression for the following response
    I used this to validate tag last name
    ProvServices:SubmitProvisioning/ProvServices:ProvisioningReqType/ProvTypes:customerName/CSCTypes:lastName

    but i recieved the following error can u please help me using X pathmatch
    soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>

    MONTAGUE
    Mr
    SPENCER

    215
    MODIFY
    Generic CM

    227
    MODIFY
    False

    213
    MODIFY
    {cstDevModel}_silver{TB25}_{cstCPENumberAllowed}

    228
    MODIFY
    1

    54559282E5E8BB86E7F1
    PENDING
    ADD
    8000094
    0
    8F9ECB0C7D2883339966
    HIGH_SPEED_DATA
    CMS

    13045994

    E3F3D4FE2F4FF3890554
    MODIFY

    CM
    00:15:CF:0B:D3:20

    2010-11-10T00:00:00+05:30
    0

    5023
    MODIFY
    0386

    5028
    MODIFY
    0386

    5007
    MODIFY
    D

    5031
    MODIFY
    1

    5006
    MODIFY
    Y

    213
    MODIFY
    {cstCMSCallAgentId}_{cstDevModel}mta_silver_t1

    227
    MODIFY
    False

    215
    MODIFY
    Generic MTA

    5024
    MODIFY
    Y

    5029
    MODIFY
    Y

    5010
    MODIFY
    A

    214
    MODIFY
    5

    8C626A330CAA81AF5969
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000086
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    5025
    MODIFY
    7656811369

    5032
    MODIFY
    false

    2C8631D43889C35BFB77
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8100
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS
    0

    0001
    7656811369

    13045994

    E3F3D4FE2F4FF3890554
    MODIFY

    MTA
    00:15:CF:0B:D3:21

    0

    DCE6B036906AC07E77E6
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000005
    Feature Code Added, 3
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    5063
    MODIFY
    LML

    5041
    MODIFY
    S

    5042
    MODIFY
    1542

    5038
    MODIFY
    Peru

    5064
    MODIFY
    46970

    5067
    MODIFY
    False

    5039
    MODIFY
    R

    5043
    MODIFY
    Montague

    5058
    MODIFY
    Forbes Ave

    5057
    MODIFY
    IN

    C6E01FCA7B5C261D43EF
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000065
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    E875526A241124EDE244
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000002
    Feature Code Added, 2
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    1DAE77554206A4F3E05A
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000007
    Feature Code Added, 4
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    87524853A26B566C6A3C
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000006
    Feature Code Added, 6
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    F15E4390674966461167
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000003
    Feature Code Added, 1
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    7CBC11A447AC73AC8FED
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000052
    Feature Code Added, 7
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    9878256268EF44F233CD
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000110
    Feature Code Added, 201
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    A30480B674836A17F687
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000053
    Feature Code Added, 0
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    B749F5D5132F3203ACAA
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000001
    Feature Code Added, 5
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    5AB040E992672A6AB345
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000004
    Feature Code Added, 8
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    BA4234AC6B35BD7FB468
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000064
    Feature Code Added, 403
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    5002
    MODIFY
    5

    5C236EA9E2AC736DA08B
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000111
    Feature Code Added, 202
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    0B3199D9A3E75F83ABA6
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000112
    Feature Code Added, 203
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    1
    2010-11-10T00:00:00+05:30
    0

    5023
    MODIFY
    0386

    5028
    MODIFY
    0386

    5007
    MODIFY
    D

    5031
    MODIFY
    0

    5006
    MODIFY
    Y

    214
    MODIFY
    5

    5024
    MODIFY
    Y

    5029
    MODIFY
    Y

    5010
    MODIFY
    A

    213
    MODIFY
    {cstCMSCallAgentId}_{cstDevModel}mta_silver_t1

    227
    MODIFY
    False

    215
    MODIFY
    Generic MTA

    BF4186A09C9F09FCD03E
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000086
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    5025
    MODIFY
    2159649386

    5032
    MODIFY
    false

    FDACE6816CCA539ABA88
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8100
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS
    0

    0001
    2159649386

    13045994

    10CF1AB1AD62CB218E3D
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000004
    Feature Code Added, 8
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    FDDBC2058EAF172FB9FF
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000003
    Feature Code Added, 1
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    7E8F78EDC3F484F81FF5
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000053
    Feature Code Added, 0
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    FC38B6EA2AFA918B1145
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000002
    Feature Code Added, 2
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    1C6898AAC616DC69F0EA
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000113
    Feature Code Added, 204
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    DA11562B69A584771414
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000007
    Feature Code Added, 4
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    6536068E974B2C5D907F
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000006
    Feature Code Added, 6
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    45226B8E5A56F2B75CAD
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000001
    Feature Code Added, 5
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    5039
    MODIFY
    R

    5041
    MODIFY
    Sai

    5042
    MODIFY
    415

    5038
    MODIFY
    Avondale

    5064
    MODIFY
    19311

    5063
    MODIFY
    LML

    5061
    MODIFY
    Mr

    5043
    MODIFY
    Cdv Flight

    5058
    MODIFY
    Glen Willow Rd

    5057
    MODIFY
    PA

    5067
    MODIFY
    False

    7E09CA66D185F6335D8D
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000065
    2C65D8F1D9325E3A173E93589C847629
    B02E95A80F3177165E9B
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000063
    Feature Code Added, 402
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    9C384B2D7BDD6309A290
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000059
    Feature Code Added, 401
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    3DC66AE417EB9AA55908
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000064
    Feature Code Added, 403
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    F0203A55D3AB0060DE03
    PENDING
    ADD
    7BBBA9ECDB9155B261E9
    8000110
    Feature Code Added, 201
    2C65D8F1D9325E3A173E93589C847629
    0
    4BBA3D5D77CB65A8C5F2
    VO_IP
    CMS

    1
    2010-11-10T00:00:00+05:30
    0

    51761198A61B02E93D9C
    HOME

    FORBES AVE
    1542
    46970
    PERU
    IN
    US

    24089
    2011-07-01T18:38:58+05:30
    5ADC099F9CDD5D9199F8

    0
    0
    RESI
    35AE5D096A869CB2E49D61C80957BC00
    001493

    9999900149316
    9999900149316-8

    225
    MODIFY
    CABLE MODEM

    E3F3D4FE2F4FF3890554
    PENDING
    ADD
    22321
    0
    5835B75B416E8EF188CB
    VO_IP
    CMS
    0

    0001
    0
    Thomson
    00730736203750
    dhg535

    CM
    00:15:CF:0B:D3:20

    MTA
    00:15:CF:0B:D3:21

    PROFESSIONAL_INSTALL
    13045994

    13045994
    9999900149316

    • devakara said:

      Hi,

      I am afraid I can’t understand your XML and I know its not your fault.
      But anyway could you use some online notepads to share your XML (maybe something like http://shrib.com/). From there we can all have a look at the XML and help find a solution for your problem.

      Hope this helps.

      Thanks,
      Devakara.

  13. rinita modak said:

    Hi Devakara,
    I am new to soapUI. I need to do a simple thing – set a value for username and validate different scenarios through soapUI. I have set a value through a property: ‘username’, now in property transfer step, selected the property name as source and ‘username’ for the property. And for the target selected the soap request and ‘request’ for the property. I have not entered anything in the Xpath. Now when I am running the steps:property,property transfer,soap request…then the total soap request is getting replaced by the property value.

    What should I need to do to change only the required attrobute value in the soap request with the property value?
    please help…

  14. Hi,

    After declaring the Name space by using the declare option from tool and from the expected result i i click on the “Test” botton…I didn’t get any response..it shows some error…
    Help me how to solve this problem.

  15. http://www.webservicex.net/globalweather.asmx?wsdl

    I am getting the error for above wsdl when iam using the Xpath assertion…

    XPathContains assertion failed for path [declare namespace ns1=’http://www.webserviceX.NET’; declare namespace soap=’http://www.w3.org/2003/05/soap-envelope’;] : RuntimeException:net.sf.saxon.trans.XPathException: XPath syntax error at char 0 in {}: Unexpected token ” ” in path expression

    • Hi Nani,

      If I’m not wrong, it seems you didn’t mention any XPath itself, so as to match it with your expected result.
      Do declare an XPath, probably like

      //ns1:GetCitiesByCountryResponse/ns1:GetCitiesByCountryResult

      for the XPath assertion in GetCitiesByCountry test request and check the expected result.

      Hope this helps.

      Thanks,
      Devakara

  16. How to compare the response values and the database values.plz send the code to me along with some example.

  17. Hi Devakar,

    thank u for reply..but the xpath is not working for above example what u explain.When i click on declare button and select some path after that i click on test botton it is showing some error…
    The declare code is

    declare namespace ns1=’http://www.webserviceX.NET’;
    //ns1:GetCitiesByCountryResponse[1]/ns1:GetCitiesByCountryResult[1]

    after click on test button the error code is :

    XPathContains assertion failed for path [declare namespace ns1=’http://www.webserviceX.NET’; //ns1:GetCitiesByCountryResponse[1]/ns1:GetCitiesByCountryResult[1]] : Exception:org.custommonkey.xmlunit.Diff [different] Expected namespace URI ‘null’ but was ‘http://www.webserviceX.NET’ – comparing at /NewDataSet[1] to at /GetCitiesByCountryResult[1]

    Tell me the difference between the test and select button in Xpath.

  18. Hi Devakar,
    Still you didn’t give any reply to my question.Plz tell me what are the possible ways to compare the database values any the response values.
    Send the code and example. The above given reply code also not working.

  19. Wonderful and simple explanation thanks a lot

  20. How to parameterise the valueexpected value in the XPATH match assertion?

  21. Hi

    I would like to validate in my response whether at least one parameter with right value exists. How can achieve this .

    Eg: Trying to create a user with emailid. In my tests i am using an email id and for the first time user will be created and tests pass as the assertion is against only the status is ok or not. from 2nd time onwords, the assertion fails as the out put is duplicate user. I want to assert this as success as well irrespetive of 1st attempt or nth attempt. So , i wanted to check for status is ok or error msg is ‘Duplicate’.
    ls some one help in achieving this.

    Thanks
    Raj

    • Hi Raj,

      When there are multiple node values to be validated in the response, you could use Script assertion.
      In Script assertion, you could fetch all the node values you want and validate them against the string constants (‘Success’ or ‘Duplicate’).
      Do look at this post for more help on Script assertion.

      Hope this helps.

      Thanks,
      Devakara.

  22. Hi
    Does the namespaces are nessessary in assertion?
    I tried to declare namespaces by using button “Declare” in XPath Match but nothing was happen. There are no tag ‘xmlns’ in my response. Can I use my assertion without namespaces?

    • Hi Yulka,

      I think your response will atleast have the xmlns for soap tags. And if the parent node in the response body is not associated with any namespace, then you should be able to create the XPath Match assertion without namespaces.

      Do let us know, what worked for you.

      Hope this helps.

      Thanks,
      Devakara.

  23. I have a problem here, I need to check a message for certain contents, but I get 5 messages and the sequence of those are not Always the same. I tried to get xpath, but all get get is a blank window, I can’t put in an xpath. I also tried a conditional goto, but can’t read the correct contents as well.

  24. […] Using XPath Assertion in SOAP UI | Groovy in SOAP UI – Oct 03, 2008 · Assertions are generally the simple and most sought validations that can be enforced in SOAP UI. For SOAP response we have an assertion step called ‘XPath …… […]

  25. […] Using XPath Assertion in SOAP UI | Groovy in SOAP UI – Oct 03, 2008 · There is a button called ‘Declare‘ (present in free version of SOAP UI also), it automatically declares all the namespaces of SOAP response…. […]

Leave a reply to SOAP begineer Cancel reply