【发布时间】:2014-08-28 18:32:55
【问题描述】:
我是 SoapUI 和 Groovy 的新手,所以请原谅这篇文章,因为它已经在 Stackoverflow 中发布了很多次,但是我找不到修复方法。
SoapUI 版本:4.5.2
如果你们不介意,我有两个问题:
- 我有一个可执行的 jar 文件,我将它放在 \bin\ext 目录中,还有另一个 jar,它被认为是 jar 中代码中的依赖 jar,所以我希望它会在那里引用。我在 Stackoverflow 中找到的应该执行这个 jar 的 groovy 代码如下,但由于我在 SoapUI 目录中的任何地方都看不到任何输出,所以它不起作用。
代码如下:
def command = "java -jar UpdateAppIdXMLRequest.jar file.xml"
def process = command.execute()
process.waitFor()
def output = process.in.text
log.info output
- 这个 jar 创建了 25 个 xml 文件,这些文件应该能够被 SoapUI 拾取,并将它们作为 TestSteps 放入同一个项目中。在我的 java 代码中,我将这些文件放在什么路径中?
这是我 jar 中的代码:
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
class UpdateAppIdXMLRequest {
static main(args) {
try {
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("c:\\file.xml");
Document doc = (Document) builder.build(xmlFile);
Element rootNode = doc.getRootElement();
// Create loop to create 25 testStepApps
for (int i = 1; i < 26; i++) {
// Get current AppID, incrementAppID and update the ApplicationNumber attribute value for next test script.
int appID = Integer.parseInt(rootNode.getAttributeValue("ApplicationNumber"));
appID++;
String appIDValue = Integer.toString(appID);
rootNode.getAttribute("ApplicationNumber").setValue(appIDValue);
XMLOutputter xmlOutput = new XMLOutputter();
// Create new XML file with next AppID
xmlOutput.setFormat(Format.getPrettyFormat());
xmlOutput.output(doc, new FileWriter("c:\\testStepApp" + i + ".xml"));
// xmlOutput.output(doc, System.out);
// System.out.println("File updated!");
}
} catch (IOException io) {
io.printStackTrace();
} catch (JDOMException e) {
e.printStackTrace();
}
}
}
任何帮助/指导将不胜感激。
谢谢。
【问题讨论】:
-
我不知道您的 jar 在做什么,所以当您执行 groovy 测试步骤时,您在打印
log.info output时在此测试步骤的Log Output选项卡中看到了什么? -
感谢您的回复。正如我所说,我对 groovy 了解不多,但是,我正在阅读 log.info 命令采用“输出”参数的代码,该参数定义在这行代码的正上方。这不正确吗?再次感谢。
-
我没有说代码错了。为了帮助您,我想知道 groovy 脚本在执行时打印的日志。
log.info打印Log Output选项卡中的信息,该选项卡就在 SOAPUI 内常规测试步骤窗口的后面。有人可以帮助您的其他可能性是您分享.jar代码。 -
感谢您的回复。在 SOAPUI 日志输出中,我得到了以下信息:Tue Sep 02 06:55:22 CDT 2014:INFO:我在上面的原始帖子中将代码包含在我的 jar 中。再次感谢您提供的任何帮助。问候。
-
嗨@Melinda,您可以直接使用 groovy 测试步骤完成所有这些操作,并且不需要使用 .jar(您可以避免在 /bin/ext 库中包含 jar 代码,重新编译代码如果您进行一些更改等...)。我会在几分钟内准备并解释一个帖子作为答案。