-
Notifications
You must be signed in to change notification settings - Fork 99
4. XmlHttpTest Examples
Fried Hoeben edited this page Jan 4, 2015
·
1 revision
This page contains sample wiki content and output of Fitnesse tests using XmlHttpTest
Wiki page content describing test:
Send a HTTP POST supplying the content to post in a variable so the script table does not have newlines in its cells.
!define POST_BODY { {{{ <s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"> <s11:Body> <ns1:GetCityWeatherByZIP xmlns:ns1="http://ws.cdyne.com/WeatherWS/"> <ns1:ZIP>90210</ns1:ZIP> </ns1:GetCityWeatherByZIP> </s11:Body> </s11:Envelope> }}} }
|script |xml http test | |post |${POST_BODY} |to |${URL} | |check |response status|200 | |show |response | |register prefix|weather |for namespace |http://ws.cdyne.com/WeatherWS/| |check |xPath |//weather:City/text()|Beverly Hills |
A snapshot of what is shown after executing the page with the table above.
Wiki content:
!2 Body via scenario
Using a scenario allows us to generate multiple request, only changing certain values.
!*> Scenario definition !define POST_BODY_2 { {{{ <s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"> <s11:Body> <ns1:GetCityWeatherByZIP xmlns:ns1="http://ws.cdyne.com/WeatherWS/"> <ns1:ZIP>@{zip}</ns1:ZIP> </ns1:GetCityWeatherByZIP> </s11:Body> </s11:Envelope> }}} }
|script|xml http test|
|table template |send request | |post |${POST_BODY_2} |to |${URL} | |check |response status|200 | |show |response | |register prefix|weather |for namespace |http://ws.cdyne.com/WeatherWS/| |check |xPath |//weather:City/text()|@{City} | *!
|send request | |zip |City | |10007|New York | |94102|San Francisco|
A partial view of what is shown after running the test (we manually clicked the row in the last table to see the script that was executed after inserting the parameters in the ‘table template’ scenario).
Sample test wiki content of test using a Freemarker template to define what to post:
!2 Body from template
By using a Freemarker template we can have more dynamic body content.
!define GLOBAL_WEATHER_URL {http://www.webservicex.com/globalweather.asmx} !define GLOBAL_WEATHER_TEMPLATE_NAME {samplePost.ftl.xml}
!3 Don't send a cityName element: error
The Freemarker template will not send a cityName element if no value is supplied (the whole element will be omitted, as can be seen in the request below). The service will not like this. Omitting the element on a null value could not be done when the body was in the scenario content.
|script |xml http test | |template |${GLOBAL_WEATHER_TEMPLATE_NAME} | |set value |http://www.webserviceX.NET/GetWeather|for header|SOAPAction | |set value |Canada |for |countryName| |post template to|${GLOBAL_WEATHER_URL} | |check |response status |500 | |show |request | |show |response |
!3 Send a cityName element: success
When a cityName value is set the enclosing element is sent by the Freemarker template (as visible in the shown request content below), and the SOAP call will succeed.
|script |xml http test | |template |${GLOBAL_WEATHER_TEMPLATE_NAME} | |set value |http://www.webserviceX.NET/GetWeather |for header |SOAPAction | |set value |Canada |for |countryName | |set value |Vancouver International Air-Port, B. C.|for |cityName | |post template to|${GLOBAL_WEATHER_URL} | |check |response status |200 | |show |request | |show |response | |register prefix |wsX |for namespace|http://www.webserviceX.NET| |show |xPath |!-//wsX:GetWeatherResult/text()-! |
What was in samplePost.ftl.xml:
<s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/">
<s11:Body>
<ns1:GetWeather xmlns:ns1="http://www.webserviceX.NET">
<#if cityName??>
<ns1:CityName>${cityName}</ns1:CityName>
</#if>
<ns1:CountryName>${countryName}</ns1:CountryName>
</ns1:GetWeather>
</s11:Body>
</s11:Envelope>
What is shown in browser after running test: