11

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

BruceyBandit
  • 3,978
  • 19
  • 72
  • 144
  • 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 May 15 '17 at 01:25
  • 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 May 15 '17 at 05:36
  • 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 May 15 '17 at 05:40
  • More over, if tests are executed using `SOAPUI_HOME/bin/testrunner`, then no such thing is needed, you can look at the [documentation](https://www.soapui.org/test-automation/running-from-command-line/functional-tests.html) which accepts one directory to store all the results which is fine I believe. – Rao May 15 '17 at 06:02
  • I will discuss with my colleague and manager on running using command line – BruceyBandit May 15 '17 at 08:59
  • Using command line you can generate html reports in free edition of SoapUI, take a look at this [docker image](https://hub.docker.com/r/nmrao/soapui/) – Rao May 15 '17 at 09:02
  • Yes the test run can be created multiple times in the day. I think the problem is that if I move the code into test case level, lets say I run via test suite level, I'm going to get a test run folder per test case and within each test run folder, there would be the test case folder and within the file. i don't know if that's just an overload of test run folders if that does occur – BruceyBandit May 15 '17 at 09:02
  • @Rao I personally think the command line is really good. Just depends if manager is ok with this. Can we continue this discussion in chat? – BruceyBandit May 15 '17 at 09:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144233/discussion-between-bruceybandit-and-rao). – BruceyBandit May 15 '17 at 09:05
  • That is the standard way. I am unsure why would someone object the standard approach. – Rao May 15 '17 at 09:05

1 Answers1

4

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)
Martin Spamer
  • 5,437
  • 28
  • 44
  • so I should just place this code in each testcase groovy script and if I run allfolders will go in there? Will I not get an overload of folders when ran multiple times at different levels or does this not matter?like i said the reason for the test run folder was to separate folders per test run, but if I take test run folder out, I will get an overload of folders in the project path folder – BruceyBandit May 14 '17 at 17:11
  • You should be able to do that once, then just use "RootResultFolder" property from the context to give you the project root folder. – Martin Spamer May 14 '17 at 19:36