我正在使用这段代码,它给了我这个错误:
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
无法解决。我正在 eclipse 中工作,你能帮我一下吗?
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();
}
}
如果您需要了解其他信息,请告诉我...我完全陷入困境...帮助!帮助!帮助!
这个错误信息...
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
at org.openqa.selenium.firefox.FirefoxDriver
...意味着该文件com/google/common/collect/ImmutableMap
可能已损坏,或者您专门使用的二进制文件版本与guava version / 依赖性(行家)。
您需要注意以下几件事:
-
In the System.setProperty()
你需要改变的线路webdriver.firefox.marionette
to webdriver.gecko.driver
。因此,有效地,该行代码将是:
System.setProperty("webdriver.gecko.driver","C:\\Program Files\\Java\\jre1.8.0_231\\lib\\ext\\geckodriver.exe");
-
如果您正在使用maven /questions/tagged/maven删除损坏/不兼容的.m2
文件夹可以解决您的问题。
-
Upgrade JDK到最近的水平JDK 8u222 https://www.oracle.com/technetwork/java/javase/downloads/index.html.
-
Upgrade Selenium到目前的水平版本 3.141.59 https://docs.seleniumhq.org/download/.
-
Upgrade Gecko驱动程序 to Gecko驱动程序 v0.26.0 https://github.com/mozilla/geckodriver/releases/tag/v0.26.0 level.
-
GeckoDriver 位于所需位置。
-
GeckoDriver 对非 root 用户具有可执行权限。
-
Upgrade Firefox版本为火狐浏览器 v70.0 levels.
-
Clean your 项目工作区通过你的IDE and Rebuild您的项目仅具有所需的依赖项。
-
(仅限 Windows 操作系统) Use CCleaner https://www.ccleaner.com/ccleaner工具可以清除执行之前和之后的所有操作系统杂务测试套件.
-
(仅限 Linux 操作系统) 释放 Ubuntu/Linux Mint 中未使用/缓存的内存 http://www.yourownlinux.com/2013/10/how-to-free-up-release-unused-cached-memory-in-linux.html在执行你的之前和之后测试套件.
-
如果你的基地网页客户端版本太旧,然后通过卸载雷沃卸载程序 https://www.revouninstaller.com/revo_uninstaller_free_download.html并安装最新的 GA 和发布版本网页客户端.
-
Take a 系统重启.
-
执行你的Test
作为非 root 用户。
-
始终调用driver.quit()
within tearDown(){}
方法关闭并销毁网络驱动程序 and 网页客户端优雅地实例。
参考
您可以在以下位置找到相关讨论:
- org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList;使用 Selenium 3.5.3 Chrome 76 https://stackoverflow.com/questions/57634492/org-openqa-selenium-remote-service-driverservicebuilder-createargslcom-google/57658406#57658406
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)