I want to know what is the correct way of setting up a folder directory within SOAPUI. Should I use setup scripts within each testcase or testsuite level or should they be setup within a groovy script step whenever required?
Currently I decided to use the groovy script method only because if I use it in a setup script, it means I have to run the setup script first to get the folder directory before I can run the test case that contains a script assertion.
Below is an example of my folder directory set up in a groovy script (called test script):
def date = new Date()
def folderTime = date.format("yyyy-MM-dd HH-mm-ss")
//Create a folder directory for the responses
RootResultFolder = dataFolder + "\\Log Smoke Test Data" + "\\xxx" + "\\xxx - " + folderTime + "\\"
CreateResultFolder = new File(RootResultFolder)
CreateResultFolder.mkdir()
...
context.setProperty( "RootResultFolder", RootResultFolder )
Below is my script assertion within a test step that uses the above folder directory:
def date = new Date().format("yyyy-MM-dd")
def time = new Date().format("HH.mm.ss")
def dataFolder = context.getProperty("RootResultFolder")
def fileName = xxx+ ".txt"
def rootFolder = dataFolder + fileName
def logFile = new File(rootFolder)
logFile.write "TEXT: " + xxx + "\n\n" +
JsonOutput.prettyPrint
Thank you
You can use the Java File class to create directories if they don't already exists. The File class contains the method mkdir() and mkdirs() for that purpose. The mkdir() method creates a single directory if it does not already exist.
Call One Groovy Class from Another Groovy Class To create a class in SoapUI, right-click on TestStep and choose Groovy Script to open the editor. Save the class as MyClass and then write the following code, as shown below. Click on the run button to execute the Groovy script.
I suggest you place them relative to project with the following code
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
// define location relative to SOAPUI project.
String projectPath = groovyUtils.projectPath + "/destination/"
context.setProperty( "RootResultFolder", projectPath)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With