简体   繁体   English

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

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

I'm running testNG testcases in cmd. 我在cmd中运行testNG测试用例。 My batch file is as following: 我的批处理文件如下:

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

The xml file can be read by testNG, but the browser won't open up(I'm running three browsers in parallel, and all three have the same exception). 可以通过testNG读取xml文件,但是无法打开浏览器(我正在并行运行三个浏览器,并且所有三个都具有相同的例外)。 Testcases can be run using EclipseIDE. 可以使用EclipseIDE运行测试用例。

The second line of the code throws the exception : 代码的第二行引发异常:

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

The exe path is valid(I can copy the system.out.print to explorer and open the webdriver.exe) exe路径有效(我可以将system.out.print复制到资源管理器并打开webdriver.exe)

I had a look at the output file and get, 我看了一下输出文件并得到,

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)

Finally, after days of research, it is solved. 最后,经过几天的研究,终于解决了。 The testng library contains two guana related jar files, which are conflicted with the complete guana library that Selenium contains. testng库包含两个与鬣蜥相关的jar文件,这与Selenium包含的完整的guana库有冲突。 Remove two guana relate jar files in TestNG solves the problem. 在TestNG中删除两个与瓜纳相关的jar文件即可解决该问题。

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

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