1

在Maven項目中嘗試使用WebDriverManager打開ChromeDriver時出現異常。在maven項目中使用WebDriverManager運行ChromeDriver時出現異常

我在計劃的框架傾向於在添加pom.xml中的依賴關係後從WebDriverManager中提取ChromeDriver,並打算使用Gauge執行測試。

在運行測試時,當它嘗試爲ChromeDriver創建新實例時,會發生該錯誤。

這裏是個例外:

Error Message: java.lang.NoSuchMethodError: com.google.common.util.concurrent.SimpleTimeLimiter.create(Ljava/util/concurrent/ExecutorService;)Lcom/google/common/util/concurrent/SimpleTimeLimiter; 
    Stacktrace: 
    org.openqa.selenium.net.UrlChecker.<init>(UrlChecker.java:64) 
    org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187) 
    org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178) 
    org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78) 
    org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646) 
    org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:255) 
    org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:237) 
    org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:138) 
    org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:178) 
    org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:167) 
    org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124) 
    StepTests.setupTest(StepTests.java:26) 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    java.lang.reflect.Method.invoke(Unknown Source) 
    com.thoughtworks.gauge.execution.MethodExecutor.execute(MethodExecutor.java:38) 
    com.thoughtworks.gauge.execution.HooksExecutor$TaggedHookExecutor.executeHook(HooksExecutor.java:102) 
    com.thoughtworks.gauge.execution.HooksExecutor$TaggedHookExecutor.execute(HooksExecutor.java:88) 
    com.thoughtworks.gauge.execution.HooksExecutor.execute(HooksExecutor.java:45) 
    com.thoughtworks.gauge.processor.MethodExecutionMessageProcessor.executeHooks(MethodExecutionMessageProcessor.java:65) 
    com.thoughtworks.gauge.processor.SpecExecutionStartingProcessor.process(SpecExecutionStartingProcessor.java:32) 
    com.thoughtworks.gauge.connection.MessageDispatcher.dispatchMessages(MessageDispatcher.java:89) 
    com.thoughtworks.gauge.GaugeRuntime.dispatchMessages(GaugeRuntime.java:104) 
    com.thoughtworks.gauge.GaugeRuntime.access$100(GaugeRuntime.java:36) 
    com.thoughtworks.gauge.GaugeRuntime$2.run(GaugeRuntime.java:85) 
    java.lang.Thread.run(Unknown Source) 

運行此代碼:

import com.thoughtworks.gauge.*; 
import io.github.bonigarcia.wdm.ChromeDriverManager; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import com.thoughtworks.gauge.Step; 
import static org.junit.Assert.assertEquals; 


public class StepTests { 
//Holds the WebDriver instance 
private WebDriver webDriver; 

@BeforeSuite 
public static void initializeDriver(){ 
    ChromeDriverManager.getInstance().setup(); 
} 

@BeforeSpec 
public void setupTest(){ 
    webDriver = new ChromeDriver(); 
} 

--test code-- 



    @AfterSuite 
    public void closeDriver(){ 
     if (webDriver != null) { 
      webDriver.quit(); 
     } 
    } 
} 

請告訴我,如果有更多的東西,你需要知道找到一個解決方案。

回答

2

你在番石榴版本有衝突。 Selenium WebDriver(不是WebDriverManager)依賴於給定版本的Guava,看起來你正在項目中使用另一個版本。我會使用兩者的最新版本。

+0

當前版本的番石榴是guava-21.0.jar,如果這有幫助。 – Travsam

+0

有沒有一種解決方法,我會同時做?提前致謝。 – Travsam

相關問題