Interview Questions

An example for Implementing Groovy DataSources and DataSink

SoapUI FAQ


(Continued from previous question...)

An example for Implementing Groovy DataSources and DataSink

Here's an example Groovy DataSource to get you going:

01.def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
02.def projectPath = groovyUtils.projectPath
03.def folderName = projectPath + "/testData"
04.def row = testRunner.testCase.testSteps["DataSource"].currentRow
05.def allFiles = []
06.new File( folderName ).eachFile() { file ->
07. if( file.name =~ /.txt/ )
08. {
09. allFiles.add( file.name ) }
10. }
11.
12.if ( (row + 1) <= allFiles.size )
13.{
14. // output to the TestStep property called inputData
15. result["inputData"] = new File( folderName + "/" + allFiles[row] ).text
16.}

Here's an example Groovy DataSink :

1.// Write the response from the "Test Request: login" TestStep to a file
2.def currentUser = context.expand( '${#TestCase#currentUser}' )
3.def response = context.expand( '${Test Request: login#Response}' )
4.new File( "C:/Users/eviware/" + currentUser + "_response.txt" ).write( response )
5.
6.// To use another charset than the default, do this instead:
7.// new File( "C:/Users/eviware/" + currentUser + "_response.txt" ).write( response, "UTF-8" )

(Continued on next question...)

Other Interview Questions