Search code examples
fitnesse

FitNesse: How to correctly configure XmlHttpTest to read web service results


I've been trying to configure XmlHttpTest in FitNesse to create a basic SOAP web service test.

I just can't quite seem to nail down the required syntax/config for the test.

My test page looks like this:

!path fixtures
!path fixtures/*.jar

!define slim.port {0}
!define TEST_SYSTEM {slim}

!define URL {http://localhost:55088/GetEmployee.asmx}

!define POST_BODY_4 { {{{
<s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/">
  <s11:Body>
    <ns1:GetEmployees xmlns:ns1="http://someorg.co.uk/">
    </ns1:GetEmployees>
  </s11:Body>
</s11:Envelope>
}}} }

|Import|
|nl.hsac.fitnesse.fixture|
|nl.hsac.fitnesse.fixture.slim|

|script|xml http test|

|table template |send request                                  |
|post           |${POST_BODY_4} |to           |${URL}          |
|check          |response status|200                           |
|show           |response                                      |
|$Name=         |xPath          |//Employee[1]/FirstName/text()|

|send request|
|Name?       |
|Fred        |

The web service method returns the following (visible in the show response):

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <GetEmployeesResponse xmlns="http://someorg.co.uk/">
            <GetEmployeesResult>
                <Employee>
                    <FirstName>Fred</FirstName>
                    <LastName>Bloggs</LastName>
                    <id>123</id>
                    <FacilityName>London</FacilityName>
                </Employee>
            </GetEmployeesResult>
        </GetEmployeesResponse>
    </soap:Body>
</soap:Envelope>

My test fails (null is the actual result). I guess I'm getting the xPath part wrong but I'm not sure why. There is no namespace prefix so I guess I don't need to use register prefix.


Solution

  • You do need a namespace for http://someorg.co.uk/ the fact that the response uses it as default for all elements below GetEmployeesResponse does not change the fact that it is present.

    Assuming you register an 'a' namespace for 'http://someorg.co.uk/' your xPath becomes: //a:Employee[1]/a:FirstName/text() (and since there is only one Employee, and no other children of FirstName, you could also write //a:Employee/a:FirstName