Forum Discussion

Kidsmoothy's avatar
Kidsmoothy
New Contributor
8 years ago

XPath assertions

I have a data source loop that loops through and excel sheet and has the expected results in it.  When this test was first made, it checks for the predicate of 1 for everything.  Over time, new data has been added to the database and now some of the data the tests are looking for are not in the first predicate.  Could be the second, third, etc.  Here is the XML:

 

<Organizations>
          <Organization>
                    <CompanyId>ABC</CompanyId>
                    <CompanyName>Central Texas </CompanyName>
                    <Address1>12 W 45th St</Address1>
                    <City>Austin</City>
                    <State>TX</State>
                    <Zip>78751</Zip>
                    <Phone></Phone>
                    <CompanyTypeParentCompanyTypeName>xxxxx</CompanyTypeParentCompanyTypeName>
                    <CompanyTypeName>eeeeeee</CompanyTypeName>
                    <SystemParentCompany>123456789</SystemParentCompany>
          </Organization>
          <Organization>
                    <CompanyId>cba</CompanyId>
                    <CompanyName>Physicians</CompanyName>
                    <Address1>545 W Ave</Address1>
                    <City>Smyrna</City>
                    <State>TN</State>
                    <Zip>37167</Zip>
                    <Phone></Phone>
                    <CompanyTypeParentCompanyTypeName>yyyyy</CompanyTypeParentCompanyTypeName>
                    <CompanyTypeName>987654321</CompanyTypeName>
                    <SystemParentCompany>This is the field I need.</SystemParentCompany>
          </Organization>
</Organizations>

 

I am looking for the <SystemParentCompany> that matches the expected result.  Here is my XPath Expression:

/Organizations[1]/Organization[1]/SystemParentCompany[1]

But I am not sure how to change this to check all "Parent elements" to see if the test finds the results.  I cannot just change it to /Organizations[1]/Organization[2]/SystemParentCompany[1] because it could be in the third one and so on.  This expression is used for many different tests.  And I run into the same issues.  Any help would be greatly appreciated.  Sorry if i have not used the terms correctly as I am new to this. 

1 Reply

  • nmrao's avatar
    nmrao
    Champion Level 3

    Since you know the expected value in this case, below xpath can be used and expect result "1"

     

    count(//*:SystemParentCompany[. ='This is the field I need.'])