简体   繁体   English

从Selenium RemoteWebDriver与Selenium Docker Firefox容器连接时,如何解决“拒绝连接”错误?

[英]How to fix “Connection Refused” error while connecting with Selenium Docker Firefox container from Selenium RemoteWebDriver?

I have been trying to learn Docker by creating a Docker container for Standalone-Firefox browser and connecting it using Selenium RemoteWebDriver. 我一直在尝试通过为Standalone-Firefox浏览器创建Docker容器并使用Selenium RemoteWebDriver将其连接来学习Docker。

I have installed a docker image and made sure it is running. 我已经安装了docker映像并确保其正在运行。 I am trying to access Google.com and print the title. 我正在尝试访问Google.com并打印标题。

However, I am getting "Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure." 但是,我收到“线程“主”中的异常” org.openqa.selenium.remote.UnreachableBrowserException:无法启动新的会话。可能的原因是远程服务器的地址无效或浏览器启动失败。 error. 错误。

Docker Image is correctly setup Docker Image已正确设置

https://github.com/SeleniumHQ/docker-selenium https://github.com/SeleniumHQ/docker-selenium

![Docker image is running successfully](E:\\Udemy Courses\\SDET Architect\\Successful Docker Running.JPG) ![Docker映像成功运行](E:\\ Udemy Courses \\ SDET Architect \\ Successful Docker Running.JPG)

package dockerValidation;

import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class ChromeStandAloneTest {
    public static void main(String[] args) throws MalformedURLException {
        // TODO Auto-generated method stub

        URL url = new URL("http://localhost:4444/wd/hub");      
        // Static Class named DesiredCapabilities is used. No need to create object
        DesiredCapabilities capabilities = DesiredCapabilities.firefox();

        // RemoteWebDriver to run test on Cloud, Docker, etc
        RemoteWebDriver rwd = new RemoteWebDriver(url, capabilities);

        rwd.get("http://google.com");
        System.out.println(rwd.getTitle());
    }
}

Expected Result (Eclipse Console) 预期结果(Eclipse控制台)

May 15, 2019 6:36:39 PM org.openqa.selenium.remote.DesiredCapabilities firefox INFO: Using new FirefoxOptions() is preferred to DesiredCapabilities.firefox() May 15, 2019 6:36:55 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected Dialect: OSS Google 2019年5月15日,下午6:36:39 org.openqa.selenium.remote.DesiredCapabilities firefox信息:使用new FirefoxOptions()优于DesiredCapabilities.firefox() 2019年5月15日,下午6:36:55 org.openqa.selenium .remote.ProtocolHandshake createSession INFO:检测到的方言:OSS Google

Actual Result 实际结果

May 15, 2019 6:36:39 PM org.openqa.selenium.remote.DesiredCapabilities firefox INFO: Using new FirefoxOptions() is preferred to DesiredCapabilities.firefox() Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. 2019年5月15日下午6:36:39 org.openqa.selenium.remote.DesiredCapabilities firefox信息:使用DesiredCapabilities.firefox()首选使用new FirefoxOptions()线程“ main”中的org.openqa.selenium.remote.UnreachableBrowserException :无法开始新的会话。 Possible causes are invalid address of the remote server or browser start-up failure. 可能的原因是远程服务器的地址无效或浏览器启动失败。 Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'DESKTOP-QJQOV4L', ip: '192.168.99.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131' Driver info: driver.version: RemoteWebDriver at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:573) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:144) at dockerValidation.ChromeStandAloneTest.main(ChromeStandAloneTest.java:20) Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:4444 at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:247) at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:165) at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java 构建信息:版本:'3.141.59',修订版本:'e82be7d358',时间:'2018-11-14T08:17:03'系统信息:主机:'DESKTOP-QJQOV4L',ip:'192.168.99.1',os .name:'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version:'1.8.0_131'驱动程序信息:driver.version:org.openqa.selenium.remote上的RemoteWebDriver。 org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:131)上的org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)上的RemoteWebDriver.execute(RemoteWebDriver.java:573)。 dockerValidation.ChromeStandAloneTest.main(ChromeStandAloneTest.java:20)处的openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:144)原因:java.net.ConnectException:无法连接到localhost / 0:0:0:0 :0:0:0:1:4444,位于okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:247),位于okhttp3.internal.connection.RealConnection.connect(RealConnection.java:165),位于okhttp3.internal.connection .StreamAllocation.findConnection(StreamAllocation.java :257) at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135) at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) at okhttp3.internal.http.RealIntercepto :257),位于okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135),位于okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114),位于okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor。 okhttp3.internal.http.RealInterceptorChain.java.147处的Java:42)(okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)处的okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor .java:93),位于okhttp3.internal.http.RealInterceptorChain.java(147),位于okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121),位于okhttp3.internal.http.BridgeInterceptor.intercept(位于okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)的BridgeInterceptor.java:93)位于okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)处于okhttp3.internal.http.RealIntero rChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200) at okhttp3.RealCall.execute(RealCall.java:77) at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:105) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) ... 4 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.A okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)上的rChain.proceed(RealInterceptorChain.java:147)okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)上的网址http://okhttp3.RealCall.execute(RealCall.java) :77),位于org.openqa.selenium的org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:105)的org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103)。 org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)上的remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) ... 4更多原因:java.net.ConnectException:拒绝连接:在java.net处以java.net.DualStackPlainSocketImpl.waitForConnect(本机方法)进行连接。在java.net处以DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)进行连接。 java.net.A上的AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) bstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at okhttp3.internal.platform.Platform.connectSocket(Platform.java:129) at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:245) ... 26 more java.net.bstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)在java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)在java.net.SocksSocketImpl.connect(SocksSocketI .java:392),位于okhttp3.internal.platform.Platform.connectSocket(Platform.java:129),位于okhttp3.internal.connection.RealConnection.connectSocket(RealConnection。 java:245)...还有26个

I had the same, restarting docker helped me. 我也一样,重启docker帮助了我。 Not the best solution, but it works. 不是最好的解决方案,但它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接到 jmeter 从站 docker 容器时出现连接被拒绝错误 - Connection refused error while connecting to jmeter slave docker container Gitlab ci selenium 测试与 docker 未连接到 RemoteWebDriver - Gitlab ci selenium testing with docker not connecting to RemoteWebDriver 硒连接拒绝错误 - Selenium connection refused error 连接拒绝从 docker 连接到 Elasticsearch docker 容器 - Connection Refused connecting from docker to Elasticsearch docker container org.openqa.selenium.TimeoutException:在使用 AutoCloseable 在 Ubuntu 中运行无头 firefox 浏览器时连接被拒绝错误 - org.openqa.selenium.TimeoutException: connection refused error while running headless firefox browser in Ubuntu using AutoCloseable 硒RemoteWebDriver Firefox产生NullPointerException - selenium RemoteWebDriver firefox producing NullPointerException 从 docker 容器连接到主机 mysql db 时连接被拒绝 - Connection refused when connecting to host mysql db from docker container 如何解决:连接到本地主机时出错:Java中的连接被拒绝 - How to fix: Error connecting to localhost: Connection Refused in Java 接受不受信任的SSL证书FireFox Selenium RemoteWebDriver - Accepting Untrusted SSL Cert FireFox Selenium RemoteWebDriver 如何在docker-compose中修复Jedis中的拒绝连接错误? - How to fix connection refused error in Jedis in docker-compose?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM