NoSuchMethodError:com.google.common.collect.ImmutableList.toImmutableList()

Nic*_*sky 7 java webdriver intellij-idea selenium-chromedriver

guava-23.6-jre.jar 使用IntelliJ IDEA进行所有操作时,始终收到上述错误(以下为全文),因此我项目中的任何地方都没有pom.xml。我的代码没有什么特别的,第39行是setProperty()调用:

    @Before
    public void Setup(){
        System.setProperty("webdriver.chrome.driver", "/Users/xxxxx/Documents/Java/end2endtests/chromedriver");
        _driver = new ChromeDriver();
        _helper = new WebDriverHelper(_driver);
        _wait = new WebDriverWait(_driver, Constants.SPIN_WAIT_TIMEOUT);
}
Run Code Online (Sandbox Code Playgroud)

错误是

java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;

at org.openqa.selenium.chrome.ChromeOptions.asMap(ChromeOptions.java:306)
at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:107)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at PlaylistTest.Setup(PlaylistTest.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Run Code Online (Sandbox Code Playgroud)

这是我已安装的软件包的列表:

animal-sniffer-annotations-1.14.jar jackson-databind-2.8.9.jar
bcpkix-jdk15on-1.58.jar         jcl-over-slf4j-1.7.25.jar
bcprov-jdk15on-1.58.jar         jsr305-1.3.9.jar
browsermob-core-2.1.5.jar       junit-4.12.jar
byte-buddy-1.7.9.jar            jzlib-1.1.3.jar
checker-compat-qual-2.0.0.jar       littleproxy-1.1.0-beta-bmp-17.jar
commons-codec-1.10.jar          mitm-2.1.5.jar
commons-exec-1.3.jar            netty-all-4.0.51.Final.jar
commons-lang3-3.5.jar           okhttp-3.9.1.jar
commons-logging-1.2.jar         okio-1.13.0.jar
dnsjava-2.1.8.jar           selenium-api-3.9.1.jar
error_prone_annotations-2.0.18.jar  selenium-chrome-driver-3.9.1.jar
error_prone_annotations-2.1.3.jar   selenium-edge-driver-3.9.1.jar
gson-2.8.2.jar              selenium-firefox-driver-3.9.1.jar
guava-23.0-android.jar          selenium-ie-driver-3.9.1.jar
guava-23.6-jre.jar          selenium-java-3.9.1.jar
hamcrest-core-1.3.jar           selenium-opera-driver-3.9.1.jar
httpclient-4.5.3.jar            selenium-remote-driver-3.9.1.jar
httpcore-4.4.6.jar          selenium-safari-driver-3.9.1.jar
j2objc-annotations-1.1.jar      selenium-server-standalone-3.9.1.jar
jackson-annotations-2.8.9.jar       selenium-support-3.9.1.jar
jackson-core-2.8.9.jar          slf4j-api-1.7.25.jar
Run Code Online (Sandbox Code Playgroud)

Alm*_*und 0

使用我安装的任何默认版本的 selenium lib 都遇到了同样的问题。显式定义依赖关系解决了这个问题:

添加显式的硒依赖