我有一个groovy脚本,它从文件中读取文本并将其作为响应返回
我必须阅读如下
text = new File("D:/text.xml")
Run Code Online (Sandbox Code Playgroud)
现在问题是我想使用相对路径..所以我很想知道
如果我只是说
text = new File("text.xml")
Run Code Online (Sandbox Code Playgroud)
Soap UI/Groovy默认情况下从哪里开始搜索文件?这当前抛出"java.io.FileNotFoundException".
我如何更改它,以便它使用相对于project.xml文件的路径?
这就是我最终解决了我的要求
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;
Run Code Online (Sandbox Code Playgroud)
添加
System.out.println(System.getProperty("user.dir"));
Run Code Online (Sandbox Code Playgroud)
或者
System.out.println(text.getAbsolutePath());
Run Code Online (Sandbox Code Playgroud)
到你的脚本来找出答案。
| 归档时间: |
|
| 查看次数: |
6437 次 |
| 最近记录: |