i want to test the GetWeather webservice
http://www.webservicex.com/globalweather.asmx
I have a text file with this content: montreal canada calgary canada
My request is:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET">
<soap:Header/>
<soap:Body>
<web:GetWeather>
<!--Optional:-->
<web:CityName>${#Project#City}</web:CityName>
<!--Optional:-->
<web:CountryName>${#Project#Country}</web:CountryName>
</web:GetWeather>
</soap:Body>
</soap:Envelope>
My Groovy code is:
def f = new File("c:\\temp\\Data.txt")
def fr= new FileReader(f)
def br = new BufferedReader(fr)
def s = br.readLine()
def x = br.readLine()
while(s && x !=null)
{
testRunner.testCase.setPropertyValue("City",s)
testRunner.testCase.setPropertyValue("Country",x)
testRunner.runTestStepByName("GetWeather - Request 1")
s = br.readLine()
x = br.readLine()
}
But i's not reading the file. Any help please, thank you
Groovy simplifies reading lines of text files. In your case since a record consists of two lines, try this:
def f = new File('c:\temp\Data.txt')
def records = f.readLines().collate(2)
records.each {
testRunner.testCase.setPropertyValue("City",it[0])
testRunner.testCase.setPropertyValue("Country",it[1])
testRunner.runTestStepByName("GetWeather - Request 1")
}
Lets assume the input file contains the following lines:
New York
USA
Istanbul
Turkey
Lines 1 and 2 are cities and lines 2 and 4 are countries. The statement f.readLines()
returns a list of the file contents, like this:
[
'New York',
'USA',
'Istanbul',
'Turkey'
]
To make the data easier to work with, I turned it into a list of city and country pairs. That's what collate(2)
does:
[
['New York', 'USA'],
['Istanbul', 'Turkey]'
]
With this new list, each(Closure)
is used to iterate through the pairs.
records.each {
// it[0] is the city
// it[1] is the country
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments