我是SoapUI和Groovy的新手,所以請原諒這篇文章,因爲它已經在Stackoverflow中發佈了很多次,但是我找不到修復程序。在SoapUI中執行Java jar文件groovy腳本不能正常工作
了SoapUI版本:4.5.2
我有2個問題,如果你們不介意的話:
- 我有我已經把在的\ bin \分機可執行的JAR文件目錄以及另一個被認爲是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代碼中,我將這些文件放在什麼路徑中?
這裏是我的罐子代碼:
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'選項卡上看到了什麼? – albciff 2014-08-29 08:09:58
感謝您的回覆。正如我所說的,我對groovy瞭解不多,但是我正在閱讀代碼,log.info命令將採用參數「output」,該參數定義在這行代碼的上方。這是不正確的?再次感謝。 – Melinda 2014-08-29 18:35:41
我沒有說代碼是錯的。爲了幫助你,我想知道groovy腳本執行時打印的日誌。 'log.info'將信息打印在'Log Output'選項卡中,該選項卡位於SOAPUI中的groovy測試步驟窗口的後面。有人可以幫助你的其他可能性是你分享'.jar'代碼。 – albciff 2014-08-29 22:15:37