[英]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.