//Get the test step name for each step in order to dynamically find the DataSource name. //Once the DataSource step is found, set the name value to a variable to be used to get the iteration. def dsName for(testStep in context.testCase.getTestStepList()) { stepName = testStep.getName() if (stepName ==~ /.*DataSource/) { dsName = stepName log.info dsName } } //Get the iteration of the DataSource loop and subtract one from it to account for the zero-based array used in filenames. //Set the iteration value to a string. //If the DataSource step does not exist, set the iteration value to zero. if (dsName != null) { iteration = ((testRunner.testCase.testSteps[dsName].getCurrentRow())-1).toString() log.info iteration } else { iteration = "0" } //Only display the Root Folder Input box if this is the first instance of the test run. //Write the input value given to a Project-level property. //For all subsequent test run iterations, get the resultsDir value from the Project property. if (iteration == "0") { //The following code displays an input box and assigns the data entered to a variable. //To enable the input box using the TestRunner, check the "Enables UI components in scripts" checkbox on the Basic tab. def ui = com.eviware.soapui.support.UISupport resultsDir = ui.prompt("Enter the TestRunner Root Folder Path","Results Output Directory") testRunner.testCase.testSuite.project.setPropertyValue("ResultsDirectory",resultsDir) log.info resultsDir } else { resultsDir = context.expand( '${#Project#ResultsDirectory}' ) } //Import Groovy IO to work with files in a directory import groovy.io.FileType //For every test step in the test case check if it's a JDBC step. //If it's a JDBC step and it's not disabled, get the SQL Query & Results and print them to the existing text file that was output for that step. for(testStep in context.testCase.getTestStepList()) { if((testStep instanceof com.eviware.soapui.impl.wsdl.teststeps.ProJdbcRequestTestStep) && !(testStep.isDisabled())) { stepName = testStep.getName() log.info stepName //Get the SQL query from the JDBC step instance. def sqlQuery = testStep.getQuery() log.info sqlQuery //Get the SQL query results from the JDBC step instance. def sqlResults = context.expand( '${' + stepName + '#ResponseAsXml#//Results[1]}' ) log.info sqlResults //Once a JBDC step is found, do the following to search the results directory for the corresponding output file to write the results to. //Skip this block if no value was entered for resultsDir. if (resultsDir != null) { //To match the filename that SoapUI outputs, remove all punctuation from testStep name and replace spaces with an underscore. removePunc = stepName.replaceAll(~/[\p{Punct}&&[^_]]/,"") log.info removePunc outputStepName = removePunc.replaceAll(" ","_") //Define a new directory as the value entered in the popup window for resultsDir. //Look for a filename that contains the modified testStep name concatenated with "-" + iteration value. //If a file match is found, then append the SQL Query & Results to the file. //Do this for each file found in the results directory and for every iteration of the test. def dir = new File(resultsDir) def fileName = outputStepName + "-" + iteration def pattern = ~/${fileName}/ def findFilenameClosure = { if (pattern.matcher(it.name).find()) { log.info it.name it.append('\r\n' + "The following are the " + stepName + " SQL Query & Results:" + '\r\n' + "-----------------------------------------------------------------------------------------" + '\r\n\r\n' + "SQL QUERY:" + '\r\n\r\n' + sqlQuery + '\r\n\r\n' + "-----------------------------------------------------------------------------------------" + '\r\n\r\n' + "SQL RESULTS:" + '\r\n\r\n' + sqlResults + '\r\n\r\n' + "-----------------------------------------------------------------------------------------") } } dir.eachFileRecurse(findFilenameClosure) } } }