How to solve java.lang.NoClassDefFoundError? Selenium

The error says it all :

java.lang.NoClassDefFoundError: com/google/common/base/Function
at MainTest.openGoogle(MainTest.java:15)

While working with Selenium v3.x you have to download geckodriver.exe from mozilla/geckodriver and place it in your system. Next you have to set the system property through the line System.setProperty() as follows and provide the absolute path of the GeckoDriver binary within your system as follows :

@Before
public void openGoogle()
{
    System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
    wd = new FirefoxDriver();
    urll = "https://google.com";
}

Finally Instead of mentioning import org.junit.*; as per best practices mention the distinct exports as follows :

  • import org.junit.Before;
  • import org.junit.Test;
  • import org.junit.After;

Here you can find a detailed discussion on NoClassDefFoundError

Leave a Comment