Forum Discussion
TNeuschwanger
Champion Level 3
17 years agoHello,
I use two Groovy script files, both included here. The first reads a csv file of properties and updates a Test Suite property variable that a subsequent script with evaluate... That subsequent script writes to a new file...
Read a .csv file Groovy script...
def lineIndx = 0
def tmpIndx = Integer.parseInt(testRunner.testCase.testSuite.properties["globalIndx"].value)
def inFileData = 'H:/DATA/SoapUI Projects/Test Data Functionality/DEV Benefit BE Input.csv'
inFileData = 'C:/SoapUI/DataIn/DEV Benefit BE Input.csv'
new File(inFileData).splitEachLine(',')
{
fields ->
if (lineIndx == tmpIndx)
{
def propBaseRead = testRunner.testCase.getTestStepByName( "Properties In" );
propBaseRead.setPropertyValue("UserId", fields[1]);
log.info("=======");
log.info("dT = " + fields[0] + " ### " + fields[1] + " ### " + fields[2] );
}
lineIndx++
}
tmpIndx++
testRunner.testCase.testSuite.properties["globalIndx"].value = tmpIndx
In between these two scripts are:
Properties In --> holds properties from read in .csv file
Test Request --> use the properties in a request
Property Transfer --> transfer properties from invoked request response as needed
Properties Out -->properties from invoked request response as needed
Write a response file Groovy script...
// get holder for response...
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "Request getMembershipInstances#Response" )
log.info(holder.xml);
def userIdInStep = testRunner.testCase.getTestStepByName( "Properties In" );
def userIdStr = userIdInStep.getPropertyValue( "UserId" );
// Output the response to a file...
//new File('c:/temp/' + userIdStr + '.txt').write(holder.prettyXml)
new File('C:/SoapUI/DataOut/DEV ' + userIdStr + '.txt').write(holder.prettyXml)
def tmpIndx = Integer.parseInt(testRunner.testCase.testSuite.properties["globalIndx"].value)
def tmpCount = Integer.parseInt(testRunner.testCase.testSuite.properties["globalCount"].value)
//log.info("=======");
//log.info(" = " + tmpIndx + " ### " + tmpCount );
if (tmpIndx >= tmpCount)
{
// testRunner.gotoStepByName( "Groovy Script Exit" );
log.info("= End of Run =");
}
else
{
// go back to the beginning of test case steps to step named "Groovy Script" to loop again...
testRunner.gotoStepByName( "Groovy Script" );
}
Regards,
Todd
I use two Groovy script files, both included here. The first reads a csv file of properties and updates a Test Suite property variable that a subsequent script with evaluate... That subsequent script writes to a new file...
Read a .csv file Groovy script...
def lineIndx = 0
def tmpIndx = Integer.parseInt(testRunner.testCase.testSuite.properties["globalIndx"].value)
def inFileData = 'H:/DATA/SoapUI Projects/Test Data Functionality/DEV Benefit BE Input.csv'
inFileData = 'C:/SoapUI/DataIn/DEV Benefit BE Input.csv'
new File(inFileData).splitEachLine(',')
{
fields ->
if (lineIndx == tmpIndx)
{
def propBaseRead = testRunner.testCase.getTestStepByName( "Properties In" );
propBaseRead.setPropertyValue("UserId", fields[1]);
log.info("=======");
log.info("dT = " + fields[0] + " ### " + fields[1] + " ### " + fields[2] );
}
lineIndx++
}
tmpIndx++
testRunner.testCase.testSuite.properties["globalIndx"].value = tmpIndx
In between these two scripts are:
Properties In --> holds properties from read in .csv file
Test Request --> use the properties in a request
Property Transfer --> transfer properties from invoked request response as needed
Properties Out -->properties from invoked request response as needed
Write a response file Groovy script...
// get holder for response...
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "Request getMembershipInstances#Response" )
log.info(holder.xml);
def userIdInStep = testRunner.testCase.getTestStepByName( "Properties In" );
def userIdStr = userIdInStep.getPropertyValue( "UserId" );
// Output the response to a file...
//new File('c:/temp/' + userIdStr + '.txt').write(holder.prettyXml)
new File('C:/SoapUI/DataOut/DEV ' + userIdStr + '.txt').write(holder.prettyXml)
def tmpIndx = Integer.parseInt(testRunner.testCase.testSuite.properties["globalIndx"].value)
def tmpCount = Integer.parseInt(testRunner.testCase.testSuite.properties["globalCount"].value)
//log.info("=======");
//log.info(" = " + tmpIndx + " ### " + tmpCount );
if (tmpIndx >= tmpCount)
{
// testRunner.gotoStepByName( "Groovy Script Exit" );
log.info("= End of Run =");
}
else
{
// go back to the beginning of test case steps to step named "Groovy Script" to loop again...
testRunner.gotoStepByName( "Groovy Script" );
}
Regards,
Todd