如何在Mac OS和Eclipse中使用FireFox运行简单的Selenium自动化测试



我在Firefox中使用Selenium运行自动化测试时遇到问题,将Geckodriver添加到我下载的Java项目中。无论我添加什么 jar 文件,我都会在 Eclipse 控制台中收到相同的错误消息。


我已经将以下这些文件下载到我在 Eclipse 中的项目中,从

https://www.seleniumhq.org/download/:


爪哇文件

壁虎司机



所以我假设上面的这些文件应该是最新的吗?


但是,当我运行下面的小型Java程序时:

public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "/Users/myName/Desktop/geckodriver");
System.setProperty("webdriver.firefox.bin", "/Applications/Firefox.app/Contents/MacOS/firefox-bin");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");

}


。我收到以下错误:

线程"main"中的异常 java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;(V at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:146( at org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:44( at org.openqa.selenium.firefox.GeckoDriverService$Builder.usingFirefoxBinary(GeckoDriverService.java:160( at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:187( at org.openqa.selenium.firefox.FirefoxDriver.(火狐驱动.java:147( at org.openqa.selenium.firefox.FirefoxDriver.(火狐驱动.java:125( 在测试中。SeleniumTest.main(SeleniumTest.java:14(


这些是我的构建路径中的 jar:Eclipse 中的构建路径


My Eclipse 版本:Oxygen.3a 版本 (4.7.3a( My Firefox版本:Firefox Quantum (69.0.34,64 位( My Mac OS 版本:OS X El Capitan (10.11.6(



我仍然很困惑为什么,因为我只是遵循了很多教程来解释如何实现自动化测试。


我只是错过了向我的项目添加一些东西吗?

所有帮助和建议将不胜感激

阅读此故障单。你有一个过时的番石榴版本。

在此处更新番石榴。

您应该能够通过右键单击项目名称并选择"构建路径>库">"添加外部 JAR",将 guava JAR 文件添加到 Eclipse 项目中。

最新更新