11
votes

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

1
Do you want separate directories for each suite? Only change you need is to be able to create directory when any of the test case is run? what if different test cases run at different times of the same day? - Rao
Yes i prefer a directory of each test suite and within a directory for test cases. I wanted a separate folder for each time the run button is clicked for a test case so no new file overwrites an old file. But to be honest I will go for the best option so whichever you think is the best option I will trust - BruceyBandit
Ok. But am asking about Test Run xxxx directory. Can be created multiple times even for the same day? If so, have you tried moving your current suite level setup script to test case level or script assertion itself? - Rao
More over, if tests are executed using SOAPUI_HOME/bin/testrunner, then no such thing is needed, you can look at the documentation which accepts one directory to store all the results which is fine I believe. - Rao
I will discuss with my colleague and manager on running using command line - BruceyBandit

1 Answers

4
votes

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)