Forum Discussion

Leonidaas's avatar
Leonidaas
New Contributor
15 years ago

Need to save to Temp-file for another GroovyStep?

Hi,
i hope some more experienced soapUi Users are able to help me.
I have an "Optimisation" Issue for my working Test, especially for steps 1-2 where i have to save data into a temp-file to be able to use 2 different Values from one .csv-File for Request.
Is there any way NOT to go this way via making a Temp-File, and doing this directly in soapui?

Goal was to read random rows(with 2 columns) from a huge File, transfering this values into a Request and Saving the Response into File.
I Created a Testsuite with 5 TestSteps.

1.Step: read Data from a .csv File which has 2 columns

//Load Input.csv
def properties = new java.util.Properties();
properties.load( new java.io.FileInputStream("C:/input.csv" ));

// Transformign data into Array
Random r = new Random();
def randomIndex = r.nextInt(properties.size());
def valueFromFile = (String)properties.entrySet().toArray()[randomIndex].toString();

valueFromFile = valueFromFile.toString().replaceAll("=","")

// Split Array, to be able to select only the Needed Information
def parts = valueFromFile.split(";");

//need to Save parts[0] into temp, to be able to work with it later
def getFilename() {"temp.xml"}
def filepath = "C:/Temp/"
def location = context.expand( filepath )
def makedir= new File ("$filepath")
makedir.mkdirs()
def file = new PrintWriter (location + getFilename())
file.println(parts[0])
file.flush()
file.close()

//need to use return, to be able to use PropertieTransfer from Result of this Groovy
log.info(parts[1]);
log.info(parts[0]);
return parts[1];
// using return deletes cached information

2.Step

// 2.Step read input from Temp
def properties = new java.util.Properties();
properties.load( new java.io.FileInputStream("C:/Temp/Temp.xml" ));
Random r = new Random();
def randomIndex = r.nextInt(properties.size());
def valueFromFile = (String)properties.entrySet().toArray()[randomIndex].toString();
log.info(valueFromFile);
return valueFromFile;

3.Step
PropertyTransfer TestStep with 2 TransferValues for transfering 1.Column to "xxx" and 2.Column to "zzz" from .csv into Request.
Sources are the results from above GroovyScript from Step 1 and 2, and Target is the Request in Step4.

declare namespace typ="http://example/types";
//typ:ABC/typ:xxx

and

declare namespace typ="http://example/types";
//typ:CABC/typ:zzz

4.Step is the Request (working fine)
5.Step is the groovyScriptStep for Saving the Response into File. (working fine)

I use soapUI 3.6.1 nonPro.

1 Reply

  • Leonidaas's avatar
    Leonidaas
    New Contributor
    After having Lunch i got the Idea for solving this.
    Its very simple...
    Just use Properties

    Delete Step 2.
    Change Step 1 last part of Code. Delete all the Code for Saving to temp-file:

    .....
    ...
    targetStep = testRunner.testCase.getTestStepByName( "Properties" )
    targetStep.setPropertyValue( "ABC", parts[0])
    targetStep.setPropertyValue( "CABC", parts[1])

    log.info("ABC:"+parts[0]);
    log.info("CABC:"+parts[1]);

    And change Step3 Sources.
    Thats it.