在SoapUI中将值从Groovy脚本传递到DataSync
我有一个脚本,它在数据集X中循环,对于该数据集中的每个记录,X在另一个数据集Y中循环,并检索一些结果。如何将这些结果传递给数据链路 有很多关于使用属性的建议,但是在我的groovy脚本中,我有一个接收结果的循环,如果我用每个结果填充属性,我想我只能看到属性中的最后一个结果,而我的DataSink只能找到最后一个结果 我的代码如下:在SoapUI中将值从Groovy脚本传递到DataSync,groovy,soapui,Groovy,Soapui,我有一个脚本,它在数据集X中循环,对于该数据集中的每个记录,X在另一个数据集Y中循环,并检索一些结果。如何将这些结果传递给数据链路 有很多关于使用属性的建议,但是在我的groovy脚本中,我有一个接收结果的循环,如果我用每个结果填充属性,我想我只能看到属性中的最后一个结果,而我的DataSink只能找到最后一个结果 我的代码如下: def goodWeather = context.expand( '${#TestCase#goodWeather}' ) as String if (goodW
def goodWeather = context.expand( '${#TestCase#goodWeather}' ) as String
if (goodWeather.equals("false"))
{
def response = context.expand( '${CityWeatherRequest#Response#declare namespace ns1=\'http://tempuri.org/\'; //ns1:GetCityWeatherResponse[1]/ns1:GetCityWeatherResult[1]/ns1:Weather[1]}' )
def cityinfo_City = context.expand( '${GetCitiesDS#cityinfo_City}' )
def cityinfo_Country = context.expand( '${GetCitiesDS#cityinfo_Country}' )
//Keep count to restrict number of returns. CountSuggestedCities is a property.
def count = context.expand( '${#TestCase#countSuggestedCities}' ) as Integer
assert count instanceof Integer
//Suggest some cities if skies are clear
if (response.contains("clear sky"))
{
if (count == 0) log.info("Making suggestions")
count ++
testRunner.testCase.setPropertyValue("countSuggestedCities", count.toString());
log.info(cityinfo_City + " located in: " + cityinfo_Country);
}
//Check property maxSuggestedCities to see if maximum suggestes required as been reached.
if (count == (context.expand( '${#TestCase#maxSuggestedCities}' ) as Integer))
{
testRunner.testCase.setPropertyValue("countSuggestedCities", "0");
testRunner.testCase.setPropertyValue("goodWeather", "true");
testRunner.gotoStepByName("SeperatorScript");
}
}
else
{
testRunner.gotoStepByName("SeperatorScript");
}
我想要的是替换
log.info(cityinfo_City+”位于:“+cityinfo_Country”)使用DataSink将信息保存到数据库。我认为soapui文档没有提供有关DataSink与groovy和数据库的示例。但您始终可以使用来执行插入。下面是示例代码:
def driverName = "com.mysql.jdbc.Driver"
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(driverName)
def user = "root" // change this , password, and jdbc url
def password = ""
def con = groovy.sql.Sql.newInstance("jdbc:mysql://localhost:3306/test_for_so",
user, password, driverName)
def cityinfo_City = 'London'
def cityinfo_Country = 'England'
con.execute("INSERT INTO cityinfo (cityinfo_City, cityinfo_Country) VALUES (?, ?)",
[cityinfo_City, cityinfo_Country])
con.close()
您好@Aristtl我正在使用mysql driverYep谢谢@Aristtl,我按照您的建议做了,找不到通过DataSink做我想做的事情的方法,我觉得很奇怪。