简体   繁体   中英

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

I keep getting the above error (full text below) with guava-23.6-jre.jar I'm doing everything with IntelliJ IDEA so I don't have pom.xml anywhere in my project. My code does nothing special, the line 39 is the setProperty() call:

    @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);
}

The error is

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)

and here is the list of the packages I have installed:

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

I got the same issue using whatever default version of selenium lib I had installed. Explicitly defining the dependency solved it:

添加显式硒依赖

Do not run your RemoteWebDriver selenium tests from AndroidStudio unless you know how to remove guava conflicts in the IDE. After cleaning up guava dependencies in my gradle file as in:

testImplementation "com.google.guava:guava:28.2-jre" testImplementation ('org.seleniumhq.selenium:selenium-chrome-driver:4.0.0-alpha-4'){ exclude group: "com.google.guava", module:"guava" }

I executed my tests from IntelliJ community edition and they worked!!. It seems that Android Studio forces its own version of guava

I faced the same issue as my testng version updated to 7.3 from 7.1, while selenium was on 3.141.59.

Reverting testng version or updating selenium should resolve the issue

I faced the same issue as my testng version updated to 7.3 from 7.0.0, while selenium was on 3.141.59. "Project was Maven" and Issue resolved ( chrome browser was launched )

我在使用 TestNG 7.4.0 时遇到了同样的问题,并通过指定:

implementation 'com.google.guava:guava:30.1.1-jre' 

I fixed my issue by removing external JARS:

在此处输入图像描述

Just Add a dependency in your Pom.xml file, issue will resolve

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>24.0-jre</version>
</dependency>

I got the same exception for Selenium dependency and I have solved this by changing the dependency from testCompile to compile in build.gradle file.

testCompile compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
     ------->>>
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'

In case some has a mess of a project like my self...

If you are mixing a lot of libraries com.google.guava:guava can be override by another dependency, the solution is check the dependency tree from the application, then delete/modify/override the dependencies to avoid conflicts between libs

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