java.lang.NoSuchMethodError: ‘com.google.common.collect.ImmutableMap error when trying to execute tests using Chromedriver and Maven

We Are Going To Discuss About java.lang.NoSuchMethodError: ‘com.google.common.collect.ImmutableMap error when trying to execute tests using Chromedriver and Maven. So lets Start this Java Article.

java.lang.NoSuchMethodError: ‘com.google.common.collect.ImmutableMap error when trying to execute tests using Chromedriver and Maven

How to solve java.lang.NoSuchMethodError: ‘com.google.common.collect.ImmutableMap error when trying to execute tests using Chromedriver and Maven

I’m using maven and downgraded Version 4.1.2 to 4.1.1 solved my problem
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.1.1</version> </dependency>

java.lang.NoSuchMethodError: ‘com.google.common.collect.ImmutableMap error when trying to execute tests using Chromedriver and Maven

I’m using maven and downgraded Version 4.1.2 to 4.1.1 solved my problem
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.1.1</version> </dependency>

Solution 1

I’m using maven and downgraded Version 4.1.2 to 4.1.1 solved my problem

<dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.1.1</version>
</dependency>

Original Author Alex Boghda Of This Content

Solution 2

The issue comes from conflicting Guava (transitive dependency) versions.

It should be fixed with the WebDriverManager version 5.1.0.

As an alternative, you can also use the <dependencyManagement> section of your pom.xml to force a resolution of the latest Guava version:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>31.0.1-jre</version>
    </dependency>
  </dependencies>
</dependencyManagement>

or exclude the Guava dependency from the WebDriverManager (no longer required for >= 5.1.0):

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.0.3</version>
    <exclusions>
        <exclusion>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </exclusion>
    </exclusions>
</dependency>

PS: To ensure dependency convergence for your Maven project, consider adding the Maven Enforcer Plugin to detect multiple versions of the transitive dependency early on.

Original Author rieckpil Of This Content

Solution 3

I also faced the above issue after adding below dependency it worked fine. I am using Chrome 98 version

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

Original Author Upasana Of This Content

Solution 4

This error message…

java.lang.NoSuchMethodError: 'com.google.common.collect.ImmutableMap com.google.common.collect.ImmutableMap.of(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)'

…implies that there is NoSuchMethod as com.google.common.collect.ImmutableMap which indicates it might be corrupted or there is some incompatibility between the version of the binaries you are using specifically with the guava version / dependency (maven).


You need to take care of a couple of things as follows:

  • You need to add the System.setProperty():

    System.setProperty("webdriver.gecko.driver","C:\\Program Files\\Java\\jre1.8.0_231\\lib\\ext\\geckodriver.exe");
    
  • Use only a single instance of WebDriver, either from the class scope or from the method scope.

  • Effectively, you line of code will be;

    public class TestYoutubeClass {
        WebDriver driver;
        @Before
        public void runDriver(){
            System.setProperty("webdriver.chrome.driver","/path/to/chromedriver");
            driver = new ChromeDriver();
            driver.get("http://www.kabum.com.br");
    
  • Incase you are using deleting the corrupt/incompatible .m2 folder can solve your issue.

Original Author undetected Selenium Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment