【发布时间】:2023-03-10 18:05:01
【问题描述】:
您好,我有这个奇怪的问题。我无法在我的 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] 检测到 TestNG 版本 6.14.2 在端口 34979 上启动 ChromeDriver (v2.9.248307) [警告] kq_init:检测到损坏的 kqueue;未使用。:未定义错误:0 2018 年 3 月 12 日上午 7:06:13 org.openqa.selenium.remote.ProtocolHandshake createSession 信息:检测到的方言:OSS 失败:测试1 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) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 在 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) 在 org.testng.internal.Invoker.invokeMethod(Invoker.java:580) 在 org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716) 在 org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988) 在 org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) 在 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.runSequentially(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) 在 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) 在 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:连接被拒绝 在 java.net.PlainSocketImpl.socketConnect(本机方法) 在 java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) 在 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) [警告] kq_init:检测到损坏的 kqueue;未使用。:未定义错误:0 2018 年 3 月 12 日上午 7:29:29 org.openqa.selenium.remote.ProtocolHandshake createSession 信息:检测到的方言:OSS 失败:测试1 org.openqa.selenium.WebDriverException:未知错误:Runtime.executionContextCreated 具有无效的“上下文”:{“auxData”:{“frameId”:“8045B2382F1BD52FB2B8744951B53B43”,“isDefault”:true},“id”:1,“name” :““,“起源”:”://”} (会话信息: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 功能 {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,平台:MAC,platformName:MAC,可旋转:false,takesHeapSnapshot:true,takeScreenshot:true,版本:65.0.3325.146,webStorageEnabled:true} 会话 ID:2301d210d1a4f56bab558a8111d856c4 在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在 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) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 在 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) 在 org.testng.internal.Invoker.invokeMethod(Invoker.java:580) 在 org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716) 在 org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988) 在 org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) 在 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.runSequentially(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) 在 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) 在 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 来进行回归,但似乎都没有工作。
提前致谢。
【问题讨论】:
标签: java selenium selenium-webdriver webdriver selenium-chromedriver