How can I use relative paths to external response files for soapUI MockService

北城余情 提交于 2019-12-04 06:38:34

I'm not familiar with Groovy, but I assume the File is a normal java.io.File instance.

Relative paths are interpreted as being relative to the application's current directory. Try something like the following to verify:

def defaultPathBase = new File( "." ).getCanonicalPath()
println "Current dir:" + defaultPathBase

If this is the case here, then you may want to use the new File(String parent, String child) constructor, passing your resource directory as the first argument and the relative path as the second.

For example:

// hardcoded for demonstration purposes
def pathbase = "/Users/chet"
def content = new File(pathbase, "Desktop/sample.txt").text

println content

Here's the result of executing the script:

Chets-MacBook-Pro:Desktop chet$ groovy sample.groovy 
This is a sample text file.

It will be displayed by a Groovy script.
Chets-MacBook-Pro:Desktop chet$ groovy sample.groovy 
This is a sample text file.

It will be displayed by a Groovy script.

Chets-MacBook-Pro:Desktop chet$ 

You could have also done the following to get the value of projectDir:

    def projectDir = context.expand('${projectDir}');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!