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

标签 java macos selenium geckodriver selenium-firefoxdriver

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


我已将以下文件下载到 Eclipse 中的项目中

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


Java file

Geckodriver



所以我认为上面的这些文件应该是最新的?


但是当我运行下面的小 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 在 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 X El Capitan (10.11.6)



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


我是否错过了向我的项目添加一些内容?

非常感谢所有帮助和建议

最佳答案

阅读此内容 trouble ticket 。您的 Guava 版本已过时。

更新 Guava here .

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

关于java - 如何在 Mac OS 和 Eclipse 中使用 FireFox 运行简单的 Selenium 自动化测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58383754/

相关文章:

javascript - Selenium鼠标滚轮下拉加载所有页面

java - java中如何读取这种文本文件

Java树形图仅保存最后插入的项目

linux - 为什么我在 git clone 上询问密码?

swift - 在 Swift 的 NSTextfield 中设置最大字符数(为一个)

javascript - 清理 Protractor 堆栈跟踪

java - 尝试对 "Deck"类进行洗牌,但似乎没有进行洗牌

java - JTable 列名称

SVN errorcode=2 无法打开请求的 SVN 文件系统

python - 无法使用 ghostdriver 启动 phantomjs