Forum Discussion

minoseah629's avatar
minoseah629
Occasional Contributor
8 years ago

Assertions with XPATH

Sorry if this is in wrong area, but I am new to SOAP UI os.  

 

I am currently trying to achieve a simple test case where if I call a service with no parameters, the response should not provide me any information back.  Super simple. 

 

With that, I am trying to get an understanding of xpath assertions. 

 

I used xpath in selenium tests.  

 

But I do not understand what I am doing wrong on the Xpath match configuration screen. 

 

I see that when I click Declare, it provides me namespaces in XPath Expression box. 

 

It provides this: 

declare namespace soap='http://www.w3.org/2003/05/soap-envelope';
declare namespace ns1='https://ForceDevelopmentServices.ServiceCode.DCPDS.EducationData.DataContracts';
declare namespace ns2='http://schemas.microsoft.com/2003/10/Serialization/';
declare namespace ns3='http://tempuri.org/';
declare namespace ns4='https://USAF.A1.Personnel.ForceDevelopment.DAL.Services.Base';

Under Assertions, 

 

I used a online xpath tester http://www.freeformatter.com/xpath-tester.html#ad-output to get this xpath expression:

 //for1:SSAN/text()

 

I would expect to place a ? in the expected results box, but when I click on Select from current I get an error message saying "Missing content to select from".  I then tried to click on the 'Test' to see what happens, I get another error message saying "Missing Content"

 

I looked over Query/Match, I did not get much from this view since it does not seem to do anything when I put in xpath query or Matching Value

 

Any assistance would be greatly appreciated.  Thanks in advance.

 

alex

 

<soap:Envelope 
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:for="https://ForceDevelopmentServices.ServiceCode.DCPDS.EducationData.Interfaces"
xmlns:for1="https://ForceDevelopmentServices.ServiceCode.DCPDS.EducationData.DataContracts"> <soap:Header/> <soap:Body> <for:GetAcquisitionsCertificationsBySSANResponse> <!--Optional:--> <for:GetAcquisitionsCertificationsBySSANResult> <!--Zero or more repetitions:--> <for1:DCPDSAcquisitionsCertification> <!--Optional:--> <for1:SSAN>?</for1:SSAN> <!--Optional:--> <for1:ACQ_DT_CAREER_LVL_ACHVD>?</for1:ACQ_DT_CAREER_LVL_ACHVD> <!--Optional:--> <for1:ACQ_CAREER_LEVEL_ACHVD_DESC>?</for1:ACQ_CAREER_LEVEL_ACHVD_DESC> <!--Optional:--> <for1:ACQ_CAREER_LVL_APPR_AUTH>?</for1:ACQ_CAREER_LVL_APPR_AUTH> <!--Optional:--> <for1:ACQ_CAREER_LVL_APPR_AUTH_DESC>?</for1:ACQ_CAREER_LVL_APPR_AUTH_DESC> <!--Optional:--> <for1:ACQ_CERT_CAREER_FIELD>?</for1:ACQ_CERT_CAREER_FIELD> <!--Optional:--> <for1:ACQ_CERT_CAREER_FIELD_DESC>?</for1:ACQ_CERT_CAREER_FIELD_DESC> </for1:DCPDSAcquisitionsCertification> </for:GetAcquisitionsCertificationsBySSANResult> </for:GetAcquisitionsCertificationsBySSANResponse> </soap:Body> </soap:Envelope>

 

4 Replies

  • kondasamy's avatar
    kondasamy
    Regular Contributor

    Your XPATH should be 

    \\for:GetAcquisitionsCertificationsBySSANResponse\for:GetAcquisitionsCertificationsBySSANResult\for1:DCPDSAcquisitionsCertification\for1:SSAN\text()

    and you should have declared namespaces for 'for' and 'for1'

     

    Thanks,

    Kondasamy

  • nmrao's avatar
    nmrao
    Champion Level 3

    minoseah629,

     

    Namespaces can be confusing, once you get how they work, then it should be easy.

     

    Regarding Namespaces:
    #1 Elements GetAcquisitionsCertificationsBySSANResponse, GetAcquisitionsCertificationsBySSANResult are belong to namespace "https://ForceDevelopmentServices.ServiceCode.DCPDS.EducationData.Interfaces"

     

     

    #2 And rest of the elements are belong to namespace "https://ForceDevelopmentServices.ServiceCode.DCPDS.EducationData.DataContracts"

     

    Note that one needs to be aware of namespaces.

     

    If you see the actual response, elements of #1 have prefix "for", but in the xpath below, the same namespace is mapped to prefix "ns1".

     

    Similarly, elements of #2 have prefix "for1", but in the xpath, the same namespace is mapped to prefix "ns2".

     

    In the XPath assertion, you have to use the same prefixes that you declare ( and should not concern about prefix that is actually present in the response.)

     

    XPath Assertion:

     

    declare namespace ns1='https://ForceDevelopmentServices.ServiceCode.DCPDS.EducationData.Interfaces';
    declare namespace ns2='https://ForceDevelopmentServices.ServiceCode.DCPDS.EducationData.DataContracts';
    //ns1:GetAcquisitionsCertificationsBySSANResponse/ns1:GetAcquisitionsCertificationsBySSANResult/ns2:DCPDSAcquisitionsCertification/ns2:SSAN/text()

     

     

    Also there is another way for the same xpath, to use any namespace using "*"

     

    //*:GetAcquisitionsCertificationsBySSANResponse/*:GetAcquisitionsCertificationsBySSANResult/*:DCPDSAcquisitionsCertification/*:SSAN/text()

     

     

    In the above full xpath is mentioned. You can also use the short xpath, like you tried, only if that element is unique in the response.

     

    declare namespace ns2='https://ForceDevelopmentServices.ServiceCode.DCPDS.EducationData.DataContracts';
    //ns2:SSAN

     

     

  • raptor's avatar
    raptor
    Occasional Contributor

    Hi,

    I am also getting the same "Missing content to select from" popup when I click on Select from Current button for XQuery Match Assertion.

     

    Xquery Expression is as below

     

    declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/';
    declare namespace ns1='http://www.webservicex.net/';

    <MyResult>
    {
    for $x in //ns1:GetSupplierByCityResponse/ns1:SupplierDataLists/ns1:SupplierDatas/ns1:SupplierData
    return <SupplierNumber>{data($x/ns1:SupplierNumber)}</SupplierNumber>
    }
    </MyResult>

     

     

    Please help me fix this as I am using SOAP UI for the first time. I am just using the tutorial below to learn

    https://www.guru99.com/assertions-soapui-complete-tutorial.html

     

  • JHunt's avatar
    JHunt
    Community Hero

    It just means you are trying to test your assertion, but you haven't yet got a webservice response to test against. (When you click 'Test' or 'Select From Current', it only runs the assertion against the last response you received. It doesn't send the request.)

     

    All you need to do is send your Test Request (green play button). If you've saved your assertion, it will run automatically now. Then, if you need to edit the assertion, you can open the assertion editor now and you will be able to test it.