[英]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.我一直在尝试在 FitNesse 中配置XmlHttpTest来创建一个基本的 SOAP Web 服务测试。
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
): Web 服务方法返回以下内容(在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).我的测试失败(null 是实际结果)。 I guess I'm getting the xPath
part wrong but I'm not sure why.我想我把xPath
部分弄错了,但我不知道为什么。 There is no namespace prefix so I guess I don't need to use register prefix
.没有命名空间前缀,所以我想我不需要使用register prefix
。
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.您确实需要http://someorg.co.uk/
的命名空间,因为响应使用它作为GetEmployeesResponse
下所有元素的默认值并不会改变它存在的事实。
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
假设您为“ http://someorg.co.uk/ ”注册了一个“a”命名空间,您的 xPath 将变为: //a:Employee[1]/a:FirstName/text()
(并且由于只有一个 Employee,并且没有名字的其他孩子,你也可以写//a:Employee/a:FirstName
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.