I have a folder structure situation I would like to require advice on. Below is a screen shot of a particular project I have:
Now the currently I have a piece of code where it runs a set up script from test suite level where it creates a 'Test Run' folder directory and within there all of the files created within test case level assertions go into that 'Test Run' folder. Below are the code of the test suite setup script and the code for placing files in that folder:
Test Suite setup script where it creates the 'Test Run' folder. (Each Suite has the same code but a different directory it falls under which is shown later). In this example the 'Test Run' folder falls under 'HotelAvail' folder. For the other suite, it falls under 'HotelAvailCalendar' folder:
// define properties required for the script to run. def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) def dataFolder = groovyUtils.projectPath def date = new Date() def folderTime = date.format("yyyy-MM-dd HH-mm-ss") //Create a folder directory for the responses RootResultTestFolder = dataFolder + "\\HotelAvail\\Test Run " + folderTime + "\\" CreateResultTestFolder = new File(RootResultTestFolder) CreateResultTestFolder.mkdir() context.setProperty( "RootResultTestFolder", RootResultTestFolder )
Within each test case, they contain a 'ReadData' groovy script step to create folders within the relevant 'Test Run' folder and then each test case contains a soap request to their relevant service and in their assertions, they contain the code below where it puts the file in the folder set within the folder created within Read Data:
In ReadData groovy script:
// define properties required for the script to run. def testFolder = context.getProperty( "RootResultTestFolder") def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) def date = new Date() //def folderTime = date.format("yyyy-MM-dd HH-mm-ss") RootResultFolder = testFolder + testRunner.testCase.name + "\\" CreateResultFolder = new File(RootResultFolder) CreateResultFolder.mkdir() context.setProperty( "RootResultFolder", RootResultFolder)
In a soap request script assertion:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) def currentRow = context.getProperty("currentRow") def dataFolder = context.getProperty("RootResultFolder") def hotelCode = messageExchange.modelItem.testStep.testCase.getPropertyValue("HotelCode") def hotelCodeTrim = hotelCode.toString().replace("|", "") def serviceRequest = context.expand( '${GetHotelAvailability#Request}' ) def serviceResponse = context.expand( '${GetHotelAvailability#Response}' ) def date = new Date().format("yyyy-MM-dd") def time = new Date().format("HH.mm.ss") def fileName = dataFolder + hotelCodeTrim + " Extranet_GetHotelAvailability.txt" log.info "TestRecord: " + fileName def logFile = new File(fileName) //--- assert code goes here ---- def testResult = new StringBuffer() testResult.append "Test run on DateTime Stamp: " +date+ " " + time testResult.append "\n\nService Request:\n\n" testResult.append(serviceRequest.toString()) testResult.append "\n\nService Response:\n\n" testResult.append(serviceResponse.toString()) // Now create and record the result file logFile.write(testResult.toString())
So the folder directory for when i run a test at project or test suite level looks like this (example using 'HotelAvail'):
The folders below is for each test case.
Within each folder is their relevant file, example of a file within a relevant folder:
So the reason I thought of this set up is that it's nice and clean per test run that instead of creating all the folders in area, it creates it within a 'Test Run' folder which belongs per test suite folder 'HotelAvail' or 'HotelAvailCalendar'.
Now more test suites will go into this project but the problem i am going to face is that if the user decides to not run at test suite level and wants to run at test case level, then the 'Test Run' folder will not be created as it is within the 'Test suite' set up script and that means the assertion will fail as it cannot find 'Test Run'. But if i put the 'Test Run' folder in all test case level setup scripts, if i run a test at test suite level, multiple 'Test run' folders will be created. If I don't have a 'Test Run' folder, then all test folders will be bunched up into one.
You can see my dilemma and I want to know what would actually be the best approach in this scenario. If somebody can provide me an example code or project it's much appreciated.
Thank you,
1 Answers
Answers 1
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)
0 comments:
Post a Comment