如何使用 Java 执行 Allure 命令
How to execute Allure command using Java
我想在各自的文件夹中生成测试用例报告。因此,例如,如果我 运行 登录测试用例,那么 html 报告应该保存在 /reports/login.
中
我可以在测试执行完成后手动执行以下命令轻松完成。我使用的命令是:
allure generate allure-results -o E:\project\target\reports\loginReport --clean
但这里的困难是我每次都必须手动执行命令来生成报告。
所以我决定从 java 执行这个 allure 命令,我尝试了以下代码:
String cmd = "allure generate allure-results -o E:\project\target\reports\loginReport --clean";
Process process = Runtime.getRuntime().exec(cmd);
process.waitFor();
我调用上面的代码作为我代码中的最后一个测试。但是出现错误:
java.io.IOException: Cannot run program "allure": CreateProcess error=2, The system cannot find the file specified
所以问题是如何从我的 java 代码执行上述命令。我正在使用 Java、selenium、TestNG 和 maven。
注意:我已经为 allure 包设置了 class 路径。
下面的代码对我来说工作得很好。我在 mac machine 上安装了 Java 1.8。
String[] cmd = {"allure", "serve","/Users/kireeti/IdeaProjects/testautomationframeworkshaft/allure-results"};
Runtime.getRuntime().exec(cmd);
Thread.sleep(90000);
我想在各自的文件夹中生成测试用例报告。因此,例如,如果我 运行 登录测试用例,那么 html 报告应该保存在 /reports/login.
中我可以在测试执行完成后手动执行以下命令轻松完成。我使用的命令是:
allure generate allure-results -o E:\project\target\reports\loginReport --clean
但这里的困难是我每次都必须手动执行命令来生成报告。
所以我决定从 java 执行这个 allure 命令,我尝试了以下代码:
String cmd = "allure generate allure-results -o E:\project\target\reports\loginReport --clean";
Process process = Runtime.getRuntime().exec(cmd);
process.waitFor();
我调用上面的代码作为我代码中的最后一个测试。但是出现错误:
java.io.IOException: Cannot run program "allure": CreateProcess error=2, The system cannot find the file specified
所以问题是如何从我的 java 代码执行上述命令。我正在使用 Java、selenium、TestNG 和 maven。
注意:我已经为 allure 包设置了 class 路径。
下面的代码对我来说工作得很好。我在 mac machine 上安装了 Java 1.8。
String[] cmd = {"allure", "serve","/Users/kireeti/IdeaProjects/testautomationframeworkshaft/allure-results"};
Runtime.getRuntime().exec(cmd);
Thread.sleep(90000);