在以下示例中,我们使用不同的输入数据执行5次请求。 例如,是否可以在同一时间保存每个请求的令牌号并在属性中设置 token1 =来自request1的令牌 token2 =来自request2的令牌
这是groovy代码:
import groovy.json.JsonSlurper
def MAX_LIMIT = 2
def countries = new Object[MAX_LIMIT]
countries[0] = "India"
countries[1] = "US"
// Invoke Method
GetCountries(countries);
// Method Definition
void GetCountries(Object[] countries)
{
for(int i=0; i<2; i++)
{
// Assign values to the global properties and call the servive
com.eviware.soapui.SoapUI.globalProperties.setPropertyValue("CountryName", countries[i] )
// Call GetCitiesByCountry service to run
def testStep=testRunner.testCase.testSteps['GetCities'];
testStep.run(testRunner,context);
}
}
我的groovy为一个请求保存令牌是:
def response = context.expand( '${GetCities#Response#declare namespace ns1=\'https://info.io/ns/20140618\'; //ns1:GetCities_resp[1]/ns1:item[1]/ns1:response[1]}' )
def slurper = new JsonSlurper()
def result = slurper.parseText(response)
testRunner.testCase.testSuite.project.setPropertyValue ( "token", result.data.token )
答案 0 :(得分:0)
也许我不明白你的问题,但只是改变:
k[1] = 'k';
为:
.setPropertyValue ( "token", result.data.token )