Where does Soap UI look for a file in new File() Groovy Script by default? How do i change this?

你说的曾经没有我的故事 提交于 2019-12-06 03:32:08

问题


I have a groovy script which reads the text from a file and returns it as a response

i have to read it as follows

text = new File("D:/text.xml")

now the problem is i'd like to use relative paths.. so i was wondering

If i just say

text = new File("text.xml")

Where does Soap UI / Groovy start searching for the file by default? This currently throws a "java.io.FileNotFoundException".

How do i change this so that it uses paths relative to the project.xml file?

This is how i finally solved my requirement

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils.projectPath //gets the path of the project root
def response = new File(projectPath, "/test.xml").text;

回答1:


You can set the Resource Root Project Property in soapUI.

${projectDir} points to your project folder.




回答2:


Add

System.out.println(System.getProperty("user.dir"));

or

System.out.println(text.getAbsolutePath());

to your script to find out.



来源:https://stackoverflow.com/questions/14039514/where-does-soap-ui-look-for-a-file-in-new-file-groovy-script-by-default-how-d

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!