Soap UI在默认情况下在新File()Groovy Script中查找文件的位置?我如何改变这一点? [英] Where does Soap UI look for a file in new File() Groovy Script by default? How do i change this?

查看:137
本文介绍了Soap UI在默认情况下在新File()Groovy Script中查找文件的位置?我如何改变这一点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个groovy脚本,它从文件中读取文本并将其作为响应返回。



我必须阅读它,如下所示:

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

现在问题是我想使用相对路径..所以我想知道如果我只是说



>

  text = new File(text.xml)

Soap UI / Groovy默认开始搜索文件的位置在哪里?它目前会抛出一个java.io.FileNotFoundException。

我如何改变它以便它使用相对于project.xml文件的路径?



这是我终于解决了我的要求的方式

  def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils.projectPath //获取项目根目录
def response = new File (projectPath,/test.xml\").text;


解决方案

您可以设置资源根目录在soapUI中的项目属性。



$ {projectDir} 指向您的项目文件夹。




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;

解决方案

You can set the Resource Root Project Property in soapUI.

${projectDir} points to your project folder.

这篇关于Soap UI在默认情况下在新File()Groovy Script中查找文件的位置?我如何改变这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆