1

I am using this code and it is giving me this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
        at org.openqa.selenium.firefox.FirefoxDriver.<clinit>FirefoxDriver.java:108)
        at Selenium_1.main(Selenium_1.java:13)
    Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 2 more

Unable to solve it. I am working in eclipse, could you please help me out.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//comment the above line and uncomment below line to use Chrome
//import org.openqa.selenium.chrome.ChromeDriver;

public class Selenium_1 {
        public static void main(String[] args) {
            // declaration and instantiation of objects/variables
            System.setProperty("webdriver.firefox.marionette","C:\\Program Files\\Java\\jre1.8.0_231\\lib\\ext\\geckodriver.exe");
            //System.setProperty("webdriver.chrome.driver", "/path/to/chrome driver");
            WebDriver driver = new FirefoxDriver();
            //comment the above 2 lines and uncomment below 2 lines to use Chrome
            //System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
            //WebDriver driver = new ChromeDriver();

            String baseUrl = "http://demo.guru99.com/test/newtours/";
            String expectedTitle = "Welcome: Mercury Tours";
            String actualTitle = "";

            // launch Fire fox and direct it to the Base URL
            driver.get(baseUrl);

            // get the actual value of the title
            actualTitle = driver.getTitle(); 

            /*
             * compare the actual title of the page with the expected one and print
             * the result as "Passed" or "Failed"
             */
            if (actualTitle.contentEquals(expectedTitle)){
                System.out.println("Test Passed!");
            } else {
                System.out.println("Test Failed");
            }



            //close Fire fox
            driver.close();
        }
    }

Please let me know if you need to know anything else... i am totally stuck... HELP! HELP! HELP!

1 Answer 1

2

This error message...

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
    at org.openqa.selenium.firefox.FirefoxDriver

...implies that the file com/google/common/collect/ImmutableMap 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:

  • In the System.setProperty() line you need to change webdriver.firefox.marionette to webdriver.gecko.driver. So effectively, the line of code will be:

    System.setProperty("webdriver.gecko.driver","C:\\Program Files\\Java\\jre1.8.0_231\\lib\\ext\\geckodriver.exe");
    
  • Incase you are using deleting the corrup/incompatible .m2 folder can solve your issue.

  • Upgrade JDK to recent levels JDK 8u222.

  • Upgrade Selenium to current levels Version 3.141.59.

  • Upgrade GeckoDriver to GeckoDriver v0.26.0 level.

  • GeckoDriver is present in the desired location.

  • GeckoDriver is having executable permission for non-root users.

  • Upgrade Firefox version to Firefox v70.0 levels.

  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.

  • (WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.

  • (LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.

  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.

  • Take a System Reboot.

  • Execute your Test as a non-root user.

  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.


Reference

You can find a relevant discussion in:

Sign up to request clarification or add additional context in comments.

5 Comments

Tried but still the same issue :(
Update the question with the complete error stack trace
Done plz check now
@Gur Checkout the updated answer and let me know the status.
i will try this and udpate u... Thank you so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.