katalon系列十四:執行Windows命令&獲取專案路徑
阿新 • • 發佈:2018-12-27
Katalon Studio中也可以執行Windows命令執行一些系統操作。
根據官方文件,在test case中輸入命令:
cmd = 'del E:\\shot\\*.xlsx E:\\shot\\*.zip'
Runtime.getRuntime().exec(cmd)
執行報錯
網上搜到解決方案,修改cmd如下
cmd = 'cmd.exe /c del E:\\shot\\*.xlsx E:\\shot\\*.zip'
執行成功
除了直接執行cmd命令,也可以執行.bat檔案,程式碼示例如下
import com.kms.katalon.core.configuration.RunConfiguration
/**
* Execute a batch file situated in the KS project directory.
* @param batchFile (String) e.g. "myfile.bat"
*/
static void runBatchFile(String batchFile) {
String bf = RunConfiguration.getProjectDir() + '/' + batchFile
comment("Running batch file: " + bf)
Runtime.runtime.exec(bf)
}
RunConfiguration.getProjectDir()即為獲取專案路徑,記得要匯入相應的包
參考https://docs.katalon.com/katalon-studio/docs/execute-windows-commands.html