java.lang.NoClassDefFoundError:执行测试文件时com / google / common / collect / ImmutableMap

时间:2018-08-31 15:00:34

标签: java selenium selenium-chromedriver

我的Testcases软件包具有以下代码

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("sample@gmail.com");
        fb.Password().sendKeys("Password");
        fb.Login().click();
    }
}

我的Objectrepository包在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);
    }
}

我的Testng.xml文件具有以下代码

<?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 -->

当我执行Testcases1.java文件时,出现以下错误

[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

尝试使用更新的chromedriver,但问题仍然存在。我正在使用Eclipse IDE,并且导入了所有必需的库

0 个答案:

没有答案