简体   繁体   中英

Running Selenium TestNG in command line - nosuchmethod exception

I'm running testNG testcases in cmd. 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). Testcases can be run using 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)

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. Remove two guana relate jar files in TestNG solves the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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