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

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!