java.lang.NoClassDefFoundError: com/google/common/collect/Im



我的测试用例包有以下代码

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();
}
}

我的对象存储库包在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,并且导入了所有必要的库

当我开始工作时,我也有同样的问题。我选择的解决方案是首先删除所有引用的Selenium文件,然后下载新的文件,然后将它们分配到一个文件夹并添加它们的引用,然后它将开始正常工作。

相关内容

  • 没有找到相关文章

最新更新