Passing value from Groovy script to DataSync in SoapUI -


i have script loops through dataset x , each record in dataset x loops in dataset y , retrieves results. how can pass results datasink?

a number of suggestions around have been use properties in groovy script have loop within receive results , if populate property every result guess able see last result in property, , datasink find last result.

my code below:

def goodweather = context.expand( '${#testcase#goodweather}' ) 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 restrict number of returns.  countsuggestedcities property.   def count = context.expand( '${#testcase#countsuggestedcities}' ) integer   assert count instanceof integer    //suggest cities if skies 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 see if maximum suggestes required been reached.   if (count == (context.expand( '${#testcase#maxsuggestedcities}' ) integer))   {     testrunner.testcase.setpropertyvalue("countsuggestedcities", "0");       testrunner.testcase.setpropertyvalue("goodweather", "true");     testrunner.gotostepbyname("seperatorscript");   } } else {     testrunner.gotostepbyname("seperatorscript"); } 

what want replace log.info(cityinfo_city + " located in: " + cityinfo_country); saving information database using datasink.

i don't think soapui doc provides examples datasink groovy , database. can use groovy sql insertion. here example code:

def drivername = "com.mysql.jdbc.driver" com.eviware.soapui.support.groovyutils.registerjdbcdriver(drivername) def user = "root" // change , password, , 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 cityinfo (cityinfo_city, cityinfo_country) values (?, ?)",         [cityinfo_city, cityinfo_country]) con.close() 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -