从命令行运行时,我收到 Testng FileNotFoundException
,以下是我正在使用的命令行参数
java -cp MyTestAutomation-06252019.jar org.testng.TestNG ZaleniumMiniRegression.xml
以下是堆栈跟踪:
[SuiteHTMLReporter] [ERROR] test-output\testng.css (The system cannot find the path specified)
java.io.FileNotFoundException: test-output\testng.css (The system cannot find the path specified)
at java.base/java.io.FileOutputStream.open0(Native Method)
at java.base/java.io.FileOutputStream.open(FileOutputStream.java:292)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:235)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:185)
at org.testng.internal.Utils.writeResourceToFile(Utils.java:263)
at org.testng.reporters.HtmlHelper.generateStylesheet(HtmlHelper.java:32)
at org.testng.reporters.SuiteHTMLReporter.generateReport(SuiteHTMLReporter.java:55)
at org.testng.TestNG.generateReports(TestNG.java:1062)
at org.testng.TestNG.run(TestNG.java:1005)
at org.testng.TestNG.privateMain(TestNG.java:1326)
at org.testng.TestNG.main(TestNG.java:1294)
最佳答案
假设您在 XML 文件中正确设置了类,您可以尝试以下操作:
- 下载 TestNG 库存档 http://dl.bintray.com/testng-team/testng-eclipse-release/zipped/ (我认为 7.0.0 是最新的)。
解压到 C:\目录中名为 TestNG 的文件夹
设置类路径环境(TestNG 文件夹和您的项目文件夹)
将目录(cd)更改为您的项目文件夹,然后编写以下命令:
set classpath=C:\eclipse-2018\Tests\bin;C:\TestNG\plugins\*
java -classpath %classpath% org.testng.TestNG ZaleniumMiniRegression.xml
就是这样。
如果您已经使用 main 方法创建了一个可运行的 jar 文件,您可以简单地执行以下操作:
java -jar <Your runnable jar file>.jar
如果您在从命令行运行网络驱动程序时遇到问题,请在此处查看我的答案: https://stackoverflow.com/a/60172758/1843452
关于java - 从命令行运行时测试 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59820626/