0

Currently all groovy scripts i run in soap UI seems to be using "...\SoapUI-5.2.1\bin" as the working directory. From one of the answers to this question I tried setting the Resource Root property of my project, however this has no effect on the working directory that the groovy scripts use.

Example

Create a new project in SoapUI. Add a testsuite, testcase and a groovy script test step. In the test script simply put:

log.info new File("").getAbsolutePath()

Click on the green arrow to run the script. For me this will always return a path to the bin folder of the SoapUI installation.

What I'm looking for

In tools like for example IntelliJ it's possible to specify a working directory in the run configurations for a script. This allows the tool to start the process from any path. In addition to this most other tools will default the working directory to the project folder and not the tools installation folder like SoapUI seems to do.

My current workaround

I'm currently using a working directory variable that I pass to all relevant path strings in my scripts. Using the example above this would look like:

String workingDir = "C:/somedir/"
log.info new File(workingDir  + "somepath").getAbsolutePath()

While this works it's not as elegant as what I can do with other tools like mentioned above.

Community
  • 1
  • 1
EJS
  • 1,011
  • 5
  • 14
  • 28
  • what are you trying to achieve? provide some context please? – Rao Jan 26 '17 at 16:42
  • @Rao I just think it's a more elegant way to handle relative paths than using a variable that must be added to every path string. This can be done in other tools like IntelliJ/Eclipse so I'm wondering if this is possible in SoapUI as well? – EJS Jan 26 '17 at 17:46
  • So what **exactly** does not satisfy your requirement in the answer that you link to? Can you provide [mcve] of your script? – SiKing Jan 26 '17 at 19:44
  • @SiKing Like I already explained: The answer I linked to suggests setting the Resource Root property in SoapUI which seems to have no effect on the working directory used by groovy in SoapUI. I don't think my question has any connection to any specific script, it would apply to any groovy script run in SoapUI. I'll remove the groovy tag from the question to avoid any future confusion. – EJS Jan 26 '17 at 20:15
  • 1
    @EJS, not sure of the issue still. Are you looking for `Resource Root` value of soapui project? May be you show the script you have. Also you may explain with with example- what you are expecting and what you are getting? – Rao Jan 27 '17 at 04:14
  • @EJS, have you got chance to look at the solution? – Rao Jan 27 '17 at 19:53
  • @Rao I have updated the question with more details to try and make it more clear what I'm looking for. I also added an explanation of my current workaround since I'm suspecting that SoapUI simply does not have the functionality I'm looking for here. – EJS Jan 30 '17 at 12:17

2 Answers2

8

Working directory is something which is related to context. And it may vary depending on how / from which directory the respective process is invoked.

For instance, SoapUI can be invoked from command line from different directories.

  • user go to %SOAPUI_HOME%\bin directory and run soapui.bat command.
  • user opens command prompt, and directly run soapui.bat(it requires %SOAPUI_HOME%\bin to be in %PATH%)

The working directory may be different in both the cases.

Well, how do I find it in Groovy Script?

Here you go:

def pwd = new File('.').absolutePath
log.info "Current working directory is ${pwd}"

I would also like to clarify about SoapUI's project property Resource Root. SoapUI allows to have either ${projectDir} or ${workspaceDir} or user can provide his preferred path.

  • ${projectDir} - this is nothing but the parent directory of current soapui project.

If you want to get this location thru Groovy Script? Use one of the below two:

def project = context.testCase.testSuite.project
log.info context.expand(project.resourceRoot)

or

def projectPath = new com.eviware.soapui.support.GroovyUtils(context).projectPath //gets the path of the project root
log.info projectPath
Rao
  • 20,781
  • 11
  • 57
  • 77
  • Here too you can see the `Resource Root` project property and set the value what you want other than available in dropdown. By the way, have tried the above suggested ways? – Rao Jan 30 '17 at 12:19
2

according to here, you can change the working directory using two methods:

def processBuilder=new ProcessBuilder("ls")
processBuilder.redirectErrorStream(true)
processBuilder.directory(new File("Your Working dir"))  
def process = processBuilder.start()

or

"your command".execute(null, new File("your working dir")) 
Payam
  • 1,068
  • 12
  • 15