Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create correct folder directory to output files from script assertion

Tags:

groovy

soapui

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

like image 357
BruceyBandit Avatar asked May 12 '17 13:05

BruceyBandit


People also ask

How do you create a directory if it does not exist in Java?

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.

How to create Groovy script in Soap ui?

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.


1 Answers

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)
like image 76
Martin Spamer Avatar answered Nov 16 '22 02:11

Martin Spamer