NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList()
Asked Answered
I

10

16

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
Inversely answered 21/2, 2018 at 19:28 Comment(7)
Could you post more code here? What do you have in this line PlaylistTest.Setup(PlaylistTest.java:39). Also list of libs you use would be helpful, too, cause it seems like libraries versions conflict.Knish
Thanks @SergeiSirik, I have added the lib directory listing and my code.Inversely
Try eliminating one of the two guava dependencies. You should only specify one.Afterdinner
@Afterdinner no, they're different. The Android one comes from browsermob which i need. However the issue was most probably caused by selenium-server-standalone-3.9.1.jarInversely
Try removing guava-23.6-jre.jar. See Guava: Google Core Libraries for Java.Afterdinner
well, the JRE one is needed for selenium-java and it uses the 23.6 version. Anyway, @MikeJRamsey56, like I said, I managed to get it to work, and both guava libraries are there. So the problem was caused by something else, most likely by the standalone driver.Inversely
Suit yourself. But you should avoid conflicts between multiple versions of Guava.Afterdinner
F
2

I faced the same issue while using TestNG 7.4.0, and solved it by specifying:

implementation 'com.google.guava:guava:30.1.1-jre' 
Falgoust answered 4/10, 2021 at 11:10 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Deaver
F
1

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

Fascinate answered 13/2, 2020 at 4:26 Comment(2)
I was facing the same issue, and your fixed worked for me thank you!Lobule
So the question itself is asking for someone using IntelliJ not Android Studio (and in my case I am also using IntelliJ and not Android studio)Pubes
C
1

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

Chukar answered 25/9, 2020 at 18:51 Comment(1)
Unfortunately I am getting the issue with Selenium 4.* (and both testng 7.3 and 7.1)Pubes
C
1

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 )

Concoct answered 26/5, 2021 at 20:40 Comment(0)
S
0

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

adding explicit selenium dependency

Suellensuelo answered 27/11, 2019 at 2:13 Comment(4)
Unfortunately this didn't work for me. I have both chromedriver and remote webdriver explicitly defined and I'm still getting the issuePubes
It was a long time since I did this but, have you confirmed what version of the Java and what versions (not only explicitly setting them but the right versions) of ChromeDriver and WebDriver you are using?Suellensuelo
Selenium is 4.1.3, chromedriver.exe is 100.0.4896.20. I started another project in my IDE and redid my config (in my case maven) with the same dependencies (and versions) and got it to work with just selenium and testng being specified (without specifying the chrome-driver maven dependency version). As far as I can tell something wasn't being cleaned up from an older build of the project leaving multiple guava versions around. Even doing a clean in the old broken project I still get the error but the new project that started with the same config is happy to run without issue.Pubes
@JoelleBoulet curious. It seems you are closing in on the issue though. Unfortunately, I'm no longer working in Java so I can't reproduce or anything here, even give much tips on how to troubleshoot. Perhaps the best you can do is to wipe the selenium setup completely and start clean as you got it to work in your other project?Suellensuelo
K
0

I fixed my issue by removing external JARS:

enter image description here

Kalagher answered 16/10, 2021 at 23:3 Comment(0)
S
0

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>
Sandra answered 18/12, 2021 at 15:34 Comment(1)
Is there a way to find out what guava version we'd need for what selenium and testng version?Pubes
B
0

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'
Bedight answered 17/3, 2022 at 10:19 Comment(0)
L
0

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

Lathing answered 14/7, 2022 at 21:45 Comment(0)
B
0

The issue is due to the libraries, I took guava 32 version with selenium 4.9.1. It worked for me. I was able to launch the chrome browser successfully.

Biathlon answered 5/6, 2023 at 13:33 Comment(1)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewCorry

© 2022 - 2024 — McMap. All rights reserved.