0

My Testcases package has the below code

package Testcases;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import Objectrepository.FBloginpage;

public class Testcase1 {

    @Test
    public void login() {
        System.setProperty("webdriver.chrome.driver", "C:\\Work\\chromedriver.exe"); 
        WebDriver driver=new ChromeDriver();
        driver.get("https://www.facebook.com");

        FBloginpage fb= new FBloginpage(driver);
        fb.Email().sendKeys("[email protected]");
        fb.Password().sendKeys("Password");
        fb.Login().click();
    }
}

My Objectrepository package has the below code in FBloginpage.java

package Objectrepository;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class FBloginpage {

    WebDriver driver;
    By username = By.id("email");
    By password = By.name("pass");
    By login = By.xpath("//input[@type='submit']");


    public FBloginpage (WebDriver driver) {
        this.driver= driver;
    }


    public WebElement Email() {
        return driver.findElement(username);
    }

    public WebElement Password() {
        return driver.findElement(password);
    }

    public WebElement Login() {
        return driver.findElement(login);
    }
}

My Testng.xml file has the below code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test thread-count="5" name="Test">
    <classes>
      <class name="Testcases.Testcase1"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

When i execute the Testcases1.java file i am getting the below error

[RemoteTestNG] detected TestNG version 6.14.2
FAILED: login
java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
    at org.openqa.selenium.remote.service.DriverService$Builder.<init>(DriverService.java:249)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.<init>(ChromeDriverService.java:96)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at Tescases.Testcase1.login(Testcase1.java:14)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    ... 30 more

Tried using updated chromedriver but still the problem persist.I am using Eclipse IDE and i imported all the necessary libraries

5
  • 1. Try to import com/google/common/collect/ImmutableMap in your FBloginpage class.2 Check if you have import libraries for guava Commented Aug 31, 2018 at 15:35
  • Check the respective library in your classpath. Make sure that the desired lib is present as dependency. Commented Aug 31, 2018 at 17:43
  • How does your POM file or import library look? I ran your code and it works perfect. It should be an issue with the import. Commented Aug 31, 2018 at 17:54
  • Possible duplicate of java.lang.NoClassDefFoundError: com/google/common/collect/Maps - Selenium Commented Aug 31, 2018 at 21:49
  • also stackoverflow.com/questions/12237153/… Commented Aug 31, 2018 at 21:50

1 Answer 1

0

I too have same issue when I started working. The solution I opted was to first delete all the referenced Selenium files and then download new ones and then assigned them to a folder and added their reference and then it will start working properly.

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

1 Comment

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.

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.