繁体   English   中英

在命令行中运行Selenium TestNG-nosuchmethod异常

[英]Running Selenium TestNG in command line - nosuchmethod exception

我在cmd中运行testNG测试用例。 我的批处理文件如下:

cd C:\..\eclipse-workspace\Project

set ProjectPath=C:\..\eclipse-workspace\Project
set classpath=%ProjectPath%\bin;%ProjectPath%\test-util\testng\*;%ProjectPath%\test-util\testrail-api\*;%ProjectPath%\test-util\selenium-java-3.5.0\*;%ProjectPath%\test-util\json-simple\*;

java org.testng.TestNG test1.xml

pause

可以通过testNG读取xml文件,但是无法打开浏览器(我正在并行运行三个浏览器,并且所有三个都具有相同的例外)。 可以使用EclipseIDE运行测试用例。

代码的第二行引发异常:

System.setProperty("webdriver.chrome.driver", userDir + prefixPathDriver + chromeDriverExe);
chromeDriver = new ChromeDriver();

exe路径有效(我可以将system.out.print复制到资源管理器并打开webdriver.exe)

我看了一下输出文件并得到,

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
    at utilities.Utilities.getChromeDriver(Utilities.java:129)
    at testcases.EngagementPageSEOFooter.init(EngagementPageSEOFooter.java:56)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

最后,经过几天的研究,终于解决了。 testng库包含两个与鬣蜥相关的jar文件,这与Selenium包含的完整的guana库有冲突。 在TestNG中删除两个与瓜纳相关的jar文件即可解决该问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM