WebDriverException:java.net.ConnectException:无法在MacOS上使用Selenium 3和chromedriver连接到localhost错误

时间:2018-03-12 01:46:46

标签: java selenium selenium-webdriver webdriver selenium-chromedriver

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

我的环境: MacOS High Sierra,最新的chromedriver,截至2018年3月12日,最新硒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]检测到TestNG版本6.14.2   在端口34979上启动ChromeDriver(v2.9.248307)   [warn] kq_init:检测到破碎的kqueue;不使用:未定义错误:0   2018年3月12日上午7:06:13 org.openqa.selenium.remote.ProtocolHandshake createSession   信息:检测到的方言:OSS   失败:test1   org.openqa.selenium.WebDriverException:java.net.ConnectException:无法连接到localhost / 0:0:0:0:0:0:0:1:34979   构建信息:版本:' 3.10.0',修订版:' 176b4a9',时间:' 2018-03-02T19:03:16.397Z'   系统信息:主持人:' 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.version:RemoteWebDriver     在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)     在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)     在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)     在org.openqa.selenium.remote.RemoteWebDriver $ RemoteWebDriverOptions $ RemoteWindow.maximize(RemoteWebDriver.java:892)     在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)     在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)     在org.testng.TestRunner.privateRun(TestRunner.java:648)     在org.testng.TestRunner.run(TestRunner.java:505)     在org.testng.SuiteRunner.runTest(SuiteRunner.java:455)     在org.testng.SuiteRunner.run顺序(SuiteRunner.java:450)     在org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)     在org.testng.SuiteRunner.run(SuiteRunner.java:364)     在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)     在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)     at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)     在org.testng.TestNG.runSuitesLocally(TestNG.java:1137)     在org.testng.TestNG.runSuites(TestNG.java:1049)     在org.testng.TestNG.run(TestNG.java:1017)     at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)     在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)     在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)   引起:java.net.ConnectException:无法连接到localhost / 0:0:0:0:0:0:0:1:34979     在okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:240)     在okhttp3.internal.connection.RealConnection.connect(RealConnection.java:158)     在okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)     在okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)     在okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)     在okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)     在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)     在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)     在okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)     在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)     在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)     在okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)     在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)     在okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)     在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)     在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)     在okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)     在okhttp3.RealCall.execute(RealCall.java:77)     在org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:101)     在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:157)     在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)     ......还有29个   引起:java.net.ConnectException:连接被拒绝     at java.net.PlainSocketImpl.socketConnect(Native Method)     在java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)     at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)     在java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)     在java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)     在java.net.Socket.connect(Socket.java:589)     在okhttp3.internal.platform.Platform.connectSocket(Platform.java:125)     在okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:238)     ......还有49个

     

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

     
    

默认测试

         

>测试运行:1,失败:1,跳过:0

  
     

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

     

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

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

  

[RemoteTestNG]检测到TestNG版本6.14.2   在端口22528上启动ChromeDriver(v2.9.248307)   [warn] kq_init:检测到破碎的kqueue;不使用:未定义错误:0   2018年3月12日上午7:29:29 org.openqa.selenium.remote.ProtocolHandshake createSession   信息:检测到的方言:OSS   失败:test1   org.openqa.selenium.WebDriverException:未知错误:Runtime.executionContextCreated包含无效的':{" auxData":{" frameId":" 8045B2382F1BD52FB2B8744951B53B43& #34;" ISDEFAULT":真}" ID":1,"名称":"""来源& #34;:"://"}     (会话信息:chrome = 65.0.3325.146)     (驱动程序信息:chromedriver = 2.9.248307,platform = Mac OS X 10.13.3 x86_64)(警告:服务器未提供任何堆栈跟踪信息)   命令持续时间或超时:0毫秒   构建信息:版本:' 3.10.0',修订版:' 176b4a9',时间:' 2018-03-02T19:03:16.397Z'   系统信息:主持人:' 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'   驱动程序信息: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,rotate:false,takesHeapSnapshot:true,takesScreenshot:true,version:65.0.3325.146,webStorageEnabled:true}   会议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)     在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)     在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)     在org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)     在org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)     在org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)     在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160)     在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)     在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)     在org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:325)     在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)     在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)     在org.testng.TestRunner.privateRun(TestRunner.java:648)     在org.testng.TestRunner.run(TestRunner.java:505)     在org.testng.SuiteRunner.runTest(SuiteRunner.java:455)     在org.testng.SuiteRunner.run顺序(SuiteRunner.java:450)     在org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)     在org.testng.SuiteRunner.run(SuiteRunner.java:364)     在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)     在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)     at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)     在org.testng.TestNG.runSuitesLocally(TestNG.java:1137)     在org.testng.TestNG.runSuites(TestNG.java:1049)     在org.testng.TestNG.run(TestNG.java:1017)     at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)     在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)     在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

     

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

     
    

默认测试

         

>测试运行:1,失败:1,跳过:0

  
     

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

     

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

     

其他信息:   我试图通过使用较旧版本的chromedriver,旧版本的TestNG,旧版本的selenium来进行回归,但似乎没有一个工作。

提前致谢。

1 个答案:

答案 0 :(得分:5)

错误说明了一切:

[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的发行说明明确提及以下内容:
  

支持 Chrome v31-34

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

因此 JDK v8u101 Selenium Client v3.10.0 ChromeDriver 版本( 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将其卸载并安装最新的GA和已发布的Chrome版本。
  • 执行@Test