无法 运行 testng.xml 使用 shell,无法找到或加载主 class

Can't run testng.xml using shell, could not find or load main class

我在 Eclipse 中有一个使用 Selenium 和 TestNG 的普通项目(不是 Maven 或 Gradle)。 我想通过 Jenkins 开始测试 运行 测试,我意识到我可以使用 TestNG 提供的 XML 文件来完成。

所以我做到了,我导出了它,当 运行通过 Eclipse 连接它时,一切正常。 在线搜索如何通过 CMD\PowerShell 运行 并看到命令应该是: java -cp "在项目的 bin 上的位置以及 selenium 和 TestNG 罐子的位置" org.testng.TestNG testng.xml

我当然有一个 Eclipse 构建的 bin 文件夹,我创建了一个名为 lib 的文件夹来将 jar 文件放在那里。所以这是我的命令: java -cp "C:\Git\WebTesting\Bin;C:\Git\WebTesting\lib*" org.testng.TestNG testng.xml

马上它给了我这个错误:

然后我意识到我没有把TestNG jar放在那里,所以我把它放在那里。 同样的错误。

然后上网查了下发现还需要放shellbean和Jcommander的jar,所以我的做法是: java -cp "C:\git\webtesting\bin;C:\Users\User1.p2\pool\plugins\org.testng_7.3.0.r202008060316.jar;C:\Users\User1.p2\pool\plugins\com.beust.jcommander_1.78.0.jar;C:\Users\User1.p2\pool\plugins\org.apache-extras.beanshell.[=60= .0.0.b6.jar;C:\Users\User1.p2\pool\plugins\org.yaml.snakeyaml_1.21.0.jar;" org.testng.testngtestng.xml

它仍然给我找不到 Testng 的相同错误 class!

我已经很沮丧了,不知道该怎么办。

有什么帮助吗?想法?

谢谢

我解决了这个问题!

我所要做的就是将项目的位置放在 $env:ProjectPath 或 %ProjectPath 中,具体取决于您使用的是 PowerShell 还是 CMD。然后将带*的link文件夹和项目的bin文件夹放在$env:Classpath/%ClassPath%中。 最后在命令末尾输入 $env:ProjectPath\testng.xml 。所以:

$env:ProjectPath = the path of the project (not the bin folder)
$env:ClassPath = the lib folder/*;the bin folder of the project
Java org.testng.testng $env:ProjectPath\testng.xml