如何在文本文件中同时使用groovy设置两个属性值
我想测试GetWeather Web服务如何在文本文件中同时使用groovy设置两个属性值,groovy,soapui,Groovy,Soapui,我想测试GetWeather Web服务 http://www.webservicex.com/globalweather.asmx 我有一个包含以下内容的文本文件: 蒙特利尔 加拿大 卡尔加里 加拿大 我的要求是: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET"> <soap:Header/&g
http://www.webservicex.com/globalweather.asmx
我有一个包含以下内容的文本文件:
蒙特利尔
加拿大
卡尔加里
加拿大
我的要求是:
<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>
但我没在看文件。
请提供任何帮助,谢谢Groovy简化了文本文件的读取。在您的情况下,由于记录由两行组成,请尝试以下操作:
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")
}
工作原理
假设输入文件包含以下行:
New York
USA
Istanbul
Turkey
1号线和2号线为城市,2号线和4号线为国家。语句f.readLines()
返回文件内容列表,如下所示:
[
'New York',
'USA',
'Istanbul',
'Turkey'
]
为了使数据更易于处理,我将其转换为城市和国家对的列表。这就是collate(2)
所做的:
[
['New York', 'USA'],
['Istanbul', 'Turkey]'
]
在这个新列表中,each(Closure)
用于遍历这些对
records.each {
// it[0] is the city
// it[1] is the country
}
谢谢,它正在读txt文件,但是如果我想读每一行,我应该怎么读呢?因为我有多行不同的城市和国家名称。不幸的是,我不明白你在问什么。我对我的回答作了解释。也许它能回答你的问题。现在我明白了,谢谢你的解释。它对我有用
records.each {
// it[0] is the city
// it[1] is the country
}