Testing 可以在Katalon中运行命令吗?

Testing 可以在Katalon中运行命令吗?,testing,cmd,integration,katalon-studio,Testing,Cmd,Integration,Katalon Studio,Katalon在自动化测试中很受欢迎。我已经在我们的项目中使用了它,它的效果令人惊讶 现在,我想要实现的是创建一个测试用例,在其中打开一个终端(使用mac)并键入一些命令来运行它,例如: cd /documents/pem/key.pem connect to -my server via SSH@method sudo su yum install php7 yum install mysql 我做了一些研究。我没有发现任何资源或任何人正在寻找与我相同的东西。我认为这是正式的,不。答案是,这

Katalon在自动化测试中很受欢迎。我已经在我们的项目中使用了它,它的效果令人惊讶

现在,我想要实现的是创建一个测试用例,在其中打开一个终端(使用mac)并键入一些命令来运行它,例如:

cd /documents/pem/key.pem
connect to -my server via SSH@method
sudo su
yum install php7
yum install mysql

我做了一些研究。我没有发现任何资源或任何人正在寻找与我相同的东西。我认为这是正式的,不。答案是,这是不可能的。

从网络上运行Katalon Studio是可能的

有一个简短的教程

从v5.10(目前为beta版)开始,可以通过命令行执行模式覆盖概要文件变量。 有关的示例如下:

只需使用以下命令行传递参数:
-g_XXX=XXX

下面是覆盖URL变量的示例:

-g_URL=http://demoaut.katalon.com

你并不孤单,通过自定义关键字,你可以实现你想要的。下面是一个显示命令行应用程序测试的示例。您可以做同样的事情来调用任何您想要的命令行脚本。考虑一个runCmd关键字,或者一个runCmdWithOutput来获取输出并对其运行各种断言

@Keyword
def pdfMetadata(String input) {
    KeywordUtil.logInfo("input: ${input}")

    def csaHome = System.getenv("CSA_HOME")
    def cmd = "cmd /c ${csaHome}/bin/csa -pdfmetadata -in \"${projectPath}${input}\"";
    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())
    }
}
然后,您可以在测试用例中使用它:

CustomKeywords.'CSA.pdfMetadata'('/src/pdf/empty.pdf')

这里是另一个自定义关键字!它接受文件名和路径,如果您不给它一个路径,它将在项目根目录中搜索该文件。它将批处理文件的输出导出到项目文件夹中的“批处理报告”文件夹中,您需要提前创建该文件夹

@Keyword
    def runPostmanBatch(String batchName , String batchPath){


        // source: https://www.mkyong.com/java/how-to-execute-shell-command-from-java/

        String firstParameter = "cmd /c " + batchName;
        String  secondParameter =  batchPath;

        if (batchPath == ""){
            secondParameter = RunConfiguration.getProjectDir();
            }

        try {
            KeywordUtil.logInfo("Executing " + firstParameter + " at " +  secondParameter)
                Process process = Runtime.getRuntime().exec(
                        firstParameter , null, new File(secondParameter));

                StringBuilder output = new StringBuilder();

                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(process.getInputStream()));

                String line;

                while ((line = reader.readLine()) != null) {
                    output.append(line + "\n");
                }

                int exitVal = process.waitFor();

                Date atnow = new Date()
                String now = atnow.format('yy-MM-dd HH-mm-ss')
                String report_path = RunConfiguration.getProjectDir() + "/postman_reports/" + RunConfiguration.getExecutionSourceName() + "_" + now + ".txt"
                BufferedWriter writer = new BufferedWriter(new FileWriter(report_path));
                writer.write(output.toString());
                writer.close();
                KeywordUtil.logInfo("postman report at: " + report_path)
                if (exitVal == 0) {

                    println("Success!"); 
                    println(output); 
                    KeywordUtil.markPassed("Ran successfully")                  
                } else {
                KeywordUtil.markFailed("Something went wrong")
                    println(exitVal);
                }



            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }               
    }

不,我想做的是在katalon内部运行命令行哦,我明白了。我不知道,我认为打开终结者是一种桌面应用程序自动化。不幸的是,卡塔隆还没有支持。