gpt4 book ai didi

java - WebDriverException : java.net.ConnectException:无法在 MacOS 上使用 Selenium 3 和 chromedriver 连接到本地主机错误

转载 作者:行者123 更新时间:2023-12-01 23:00:55 25 4
gpt4 key购买 nike

嗨,我有一个奇怪的问题。我无法在 Mac 上使用 chromedriver 运行测试。我已经搜索了这里的每一个可能的角落,但似乎没有一个有帮助。我的浏览器已启动,但在 driver.get(url) 之前卡住了被调用。

我的环境:MacOS High Sierra、截至 2018 年 3 月 12 日的最新 chromedriver、最新 selenium 3.10、最新 TestNG 6.14

我的代码:

public class Temp {

@Test()
public void test1() {
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver");
ChromeOptions options = new ChromeOptions();
options.addArguments("--test-type");
options.addArguments("ignore-certificate-errors");
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();

driver.get("https://www.google.co.in/");
driver.quit();
}
}

我得到的异常是:

[RemoteTestNG] detected TestNG version 6.14.2 Starting ChromeDriver (v2.9.248307) on port 34979 [warn] kq_init: detected broken kqueue; not using.: Undefined error: 0 Mar 12, 2018 7:06:13 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS FAILED: test1 org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:34979 Build info: version: '3.10.0', revision: '176b4a9', time: '2018-03-02T19:03:16.397Z' System info: host: 'sandeep-MacBook-Pro.local', ip: '192.168.0.100', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.3', java.version: '1.8.0_101' Driver info: driver.version: RemoteWebDriver at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658) at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.maximize(RemoteWebDriver.java:892) at com.pareek.framework.tests.Temp.test1(Temp.java:22) 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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:580) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:34979 at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:240) at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:158) at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256) at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134) at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113) 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:125) at okhttp3.internal.http.RealInterceptorChain.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:101) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:157) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) ... 29 more Caused by: java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at okhttp3.internal.platform.Platform.connectSocket(Platform.java:125) at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:238) ... 49 more

===============================================

Default test

> Tests run: 1, Failures: 1, Skips: 0

================================================== 默认套件

运行的测试总数:1,失败:1,跳过:0

编辑:如果我删除注释 driver.manage().window().maximize();函数,异常日志如下:

[RemoteTestNG] detected TestNG version 6.14.2 Starting ChromeDriver (v2.9.248307) on port 22528 [warn] kq_init: detected broken kqueue; not using.: Undefined error: 0 Mar 12, 2018 7:29:29 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS FAILED: test1 org.openqa.selenium.WebDriverException: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"8045B2382F1BD52FB2B8744951B53B43","isDefault":true},"id":1,"name":"","origin":"://"} (Session info: chrome=65.0.3325.146) (Driver info: chromedriver=2.9.248307,platform=Mac OS X 10.13.3 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: '3.10.0', revision: '176b4a9', time: '2018-03-02T19:03:16.397Z' System info: host: 'sandeep-MacBook-Pro.local', ip: '192.168.0.100', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.3', java.version: '1.8.0_101' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {acceptSslCerts: true, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {userDataDir: /var/folders/3t/p4sy21xx2cb...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, javascriptEnabled: true, locationContextEnabled: true, nativeEvents: true, platform: MAC, platformName: MAC, rotatable: false, takesHeapSnapshot: true, takesScreenshot: true, version: 65.0.3325.146, webStorageEnabled: true} Session ID: 2301d210d1a4f56bab558a8111d856c4 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166) at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601) at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:325) at com.pareek.framework.tests.Temp.test1(Temp.java:24) 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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:580) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

===============================================

Default test

> Tests run: 1, Failures: 1, Skips: 0

================================================== 默认套件

运行的测试总数:1,失败:1,跳过:0

附加信息: 我尝试使用旧版本的 chromedriver、旧版本的 TestNG、旧版本的 selenium 进行回归,但似乎都不起作用。

提前致谢。

最佳答案

错误说明了一切:

[RemoteTestNG] detected TestNG version 6.14.2 Starting ChromeDriver (v2.9.248307) on port 34979 
[warn] kq_init: detected broken kqueue; not using.: Undefined error: 0 Mar 12, 2018 7:06:13 AM
org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS FAILED: test1
org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:34979
Build info: version: '3.10.0', revision: '176b4a9', time: '2018-03-02T19:03:16.397Z'
System info: host: 'sandeep-MacBook-Pro.local', ip: '192.168.0.100', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.3', java.version: '1.8.0_101'

您的主要问题是您正在使用的二进制文件之间的版本兼容性,如下所示:

  • 您正在使用chromedriver=v2.9
  • chromedriver=2.9 的发行说明明确提到以下内容:

Supports Chrome v31-34

  • 我们不知道您的 Chrome 浏览器版本。 (假设 Chrome 浏览器已更新至 v65.x 级别)
  • 您的 Selenium 客户端版本是 3.10.0
  • 您的JDK版本1.8.0_101,这是相当古老的。

因此,JDK v8u101Selenium Client v3.10.0ChromeDriver 版本(v2.9 )和当前的 Chrome 浏览器版本 (v65.0)

解决方案

  • JDK 升级到最新级别 JDK 8u162 .
  • 将 Selenium 含量保持在当前水平 Version 3.10.0 .
  • 将 ChromeDriver 升级至稳定版 ChromeDriver v2.36级别。
  • Chrome 版本保持在 Chrome v65.x 级别。 (as per ChromeDriver v2.36 release notes)
  • 通过IDE清理您的项目工作区,并仅使用所需的依赖项重建项目。
  • 使用CCleaner工具可以清除执行测试套件之前和之后的所有操作系统杂务。
  • 如果您的基本 Chrome 版本太旧,请通过 Revo Uninstaller 卸载它并安装 Chrome 的最新 GA 和发布版本。
  • 执行您的@Test

关于java - WebDriverException : java.net.ConnectException:无法在 MacOS 上使用 Selenium 3 和 chromedriver 连接到本地主机错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49227055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com