亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Groovy 腳本中執行 .jar

在 Groovy 腳本中執行 .jar

瀟瀟雨雨 2022-07-06 18:39:33
我正在使用腳本模式(一種 groovy 腳本)使用 Katalon Studio 創建一個測試用例。我需要那個 groovy 腳本來執行一個.jar位于 Katalon 項目文件夾中的腳本。出于測試目的,我創建了一個 .jar,它創建了一個名為“the-file-name”的文件并在控制臺中打印了一條消息。我找到了一種在 Groovy 中執行命令的方法:def command = "git --version"def proc = command.execute()proc.waitFor()println proc.in.text這會在 Katalon 控制臺中打印 git 的版本。所以我猜想放“java -jar test.jar”就足夠了,但即使執行似乎正確結束,.jar 似乎也沒有做任何事情??梢钥隙ǖ氖?,我使用 de Windows 命令行執行了相同的 .jar,它運行良好。文件被創建并且消息被寫入控制臺。執行時,Katalon 控制臺就像正確執行一樣。沒有錯誤消息,并且執行被標記為成功,但是找不到測試文件“the-file-name”,并且我沒有.jar像在 git 命令中那樣在 Katalon 控制臺中獲得控制臺輸出。
查看完整描述

1 回答

?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

找到了一種方法來做到這一點。


public class CustomKeywords {


    @Keyword

    def runBatch(String path) {

        def cmd = "cmd /c \"java -jar \"" + path + "\"\"";

        runCmd(cmd)

    }


    def runCmd(String cmd) {

        KeywordUtil.logInfo("cmd: ${cmd}")


        def proc = cmd.execute();

        def outputStream = new StringBuffer();

        def errStream = new StringBuffer()

        proc.waitForProcessOutput(outputStream, errStream);

        println(outputStream.toString());

        println(errStream.toString())


        if(proc.exitValue() != 0){

            KeywordUtil.markFailed("Out:" + outputStream.toString() + ", Err: " + errStream.toString())

        }

    }


}


查看完整回答
反對 回復 2022-07-06
  • 1 回答
  • 0 關注
  • 254 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號