我在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");
}
...我收到以下错误:
线程“主”中的异常java.lang.NoSuchMethodError:com.google.common.base.Preconditions.checkState(ZLjava / lang / String; Ljava / lang / Object;)V在org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:146)在org.openqa.selenium.firefox.GeckoDriverService.access $ 000(GeckoDriverService.java:44)在org.openqa.selenium.firefox.GeckoDriverService $ Builder.usingFirefoxBinary(GeckoDriverService.java:160)在org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:187)在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:147)在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:125)在test.SeleniumTest.main(SeleniumTest.java:14)
这些是我的构建路径中的jar:Build path in Eclipse
我的Eclipse版本:Oxygen.3a发行版(4.7.3a)我的Firefox版本:Firefox Quantum(69.0.34,64位)我的Mac OS版本:OS X El Capitan(10.11.6)
我仍然感到困惑,原因是因为我刚刚遵循了很多教程,以说明如何实现自动化测试。
我是否只是错过了向项目中添加某些内容?
[所有帮助和建议,我们将不胜感激
阅读此trouble ticket。您有一个过时的番石榴版本。
更新番石榴here。
通过右键单击项目名称,然后选择构建路径>库>添加外部JAR,您应该能够将guava JAR文件添加到Eclipse项目中。