Selenium Firefox 57 无法连接到二进制/本地主机
Posted
技术标签:
【中文标题】Selenium Firefox 57 无法连接到二进制/本地主机【英文标题】:Selenium Firefox 57 failed to connect to binary / localhost 【发布时间】:2018-05-15 13:22:24 【问题描述】:我使用的是 Firefox 57、geckodriver 0.19.1 和 selenium 3.8.0。 (Java gradle 项目) 顺便说一句:Chrome 做得很好。我的测试有效。
Firefox 启动,但没有任何反应。两三秒后,Intellij 显示异常。
我知道这可能是重复的,但我找不到任何显示每个“组合”的兼容版本的资源。
这是我的异常输出:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
[...]
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:113)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:128)
at com.bilsteingroup.css.pf2.seleniumtests.ConfigTests.<init>(ConfigTests.java:43)
at com.bilsteingroup.css.pf2.seleniumtests.ConfigTests.Start(ConfigTests.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
还有:
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7055; process output follows:
[...]
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:125)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:128)
at com.bilsteingroup.css.pf2.seleniumtests.ConfigTests.<init>(ConfigTests.java:43)
at com.bilsteingroup.css.pf2.seleniumtests.ConfigTests.Start(ConfigTests.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
这是我的测试类:
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
public class ConfigTests
enum Browser CHROME, FIREFOX, IE
private WebDriver webDriver;
public ConfigTests()
private ConfigTests(Browser browser) throws URISyntaxException
URL chromeURL = getClass().getResource("../../../../../../resources/driver/win/chromedriver_32.exe");
System.setProperty("webdriver.chrome.driver", Paths.get(chromeURL.toURI()).toFile().getAbsolutePath());
URL firefoxURL = getClass().getResource("../../../../../../resources/driver/win/geckodriver_32_v0-19-1.exe");
System.setProperty("webdriver.gecko.driver", Paths.get(firefoxURL.toURI()).toFile().getAbsolutePath());
/*URL ieURL = getClass().getClassLoader().getResource("driver" + File.separator + "IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", Paths.get(ieURL.toURI()).toFile().getAbsolutePath());*/
switch (browser)
case CHROME:
webDriver = new ChromeDriver();
break;
case FIREFOX:
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
/*webDriver = new FirefoxDriver(capabilities);
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);*/
break;
case IE:
webDriver = new InternetExplorerDriver();
break;
private void goToLocalPartsfinder()
webDriver.get("http://localhost:8080");
WebElement searchFieldElement = webDriver.findElement(By.id("search-input-field"));
searchFieldElement.sendKeys("08900");
searchFieldElement.sendKeys(Keys.ENTER);
private void quit()
webDriver.quit();
@Test
public void Start() throws URISyntaxException
// Test for each browser definition
for (Browser browser : Browser.values())
ConfigTests configTests = new ConfigTests(browser);
configTests.goToLocalPartsfinder();
configTests.quit();
谁能给我一个提示? 我已经使用过其他 geckodriver 和 selenium 版本。由于IT限制,我不允许更改FF版本...
我也尝试了一堆 FirefoxOptions 都没有成功。
我想知道为什么 chrome 工作正常,但 firefox 什么也没做。
更新:
//build.gradle
dependencies
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.8.0'
compile "org.seleniumhq.selenium:selenium-chrome-driver:3.8.0"
compile "org.seleniumhq.selenium:selenium-firefox-driver:3.8.0"
更新2:
更改 build.gradle 添加驱动依赖后,我得到这个异常:
java.lang.NoClassDefFoundError: org/openqa/selenium/MutableCapabilities
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at com.bilsteingroup.css.pf2.seleniumtests.ConfigTests.<init>(ConfigTests.java:38)
at com.bilsteingroup.css.pf2.seleniumtests.ConfigTests.Start(ConfigTests.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
所以我猜还是缺少一个依赖,不是吗?
【问题讨论】:
它是否适用于 selenium3.7.1
或 3.5
?
我试过 3.7.1 但没有。我也可以检查3.5。
3.5 没有FirefoxDriver
类,因此我不知道如何使用它。有什么提示吗?
FirefoxDriver
从 2.0 开始存在。但如果它不适用于 3.7.1,那么我们必须考虑另一种方法。
是否存在gradle依赖错误?我将更新我的问题以显示我的 build.gradle 文件
【参考方案1】:
您的问题是由于缺少依赖项引起的
下载所有相关的 Selenium 依赖项。
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.8.0'
compile 'org.seleniumhq.selenium:selenium-java:3.8.0'
compile 'org.seleniumhq.selenium:selenium-server:3.8.0'
compile 'org.seleniumhq.selenium:selenium-api:3.8.0'
compile 'org.seleniumhq.selenium:selenium-support:3.8.0'
compile 'org.seleniumhq.selenium:selenium-remote-driver:3.8.0'
compile 'org.seleniumhq.selenium:selenium-chrome-driver:3.8.0'
compile 'org.seleniumhq.selenium:selenium-firefox-driver:3.8.0'
【讨论】:
谢谢拉法拉斯科夫斯基。你帮了我很多!以上是关于Selenium Firefox 57 无法连接到二进制/本地主机的主要内容,如果未能解决你的问题,请参考以下文章
Selenium 2.50 无法在 Firefox 45 上运行
Selenium 2.53 或 2.48 在 Firefox 48.0 中不起作用