当前位置: 首页 > 知识库问答 >
问题:

持续获取SessionNotCreatedException:无法创建新服务:ChromeDriverService错误

马淇
2023-03-14

无论我尝试什么;最新的chrome浏览器,最新的chromedriver,最新的selenium服务器,等等。但是当我在Mac OSX上运行测试时,我不断得到上面的错误。我研究过其他类似的问题,甚至尝试过那里提出的解决方案,但似乎没有任何效果。我错过了什么或做错了什么??

以下是我的设置:

  • Chrome版本:75.0.3770.100(最新版本)
  • Chromedriver版本:75.0.3770.90也尝试了76
  • Selenium Server单机版:3.141.59
  • Java JDK版本:1.8.0131

我正在初始化我的集线器和节点,如下所示

java-jarselenium-server-standalone-3.141.59.jar角色集线器端口9999

节点:java-jar-selenium-server-standalone-3.141.59。jar-角色节点-中心http://localhost:9999/grid/register

下面是我初始化远程WebDriver实例的方式。

java prettyprint-override">String absolutePath = Config.TEST_RESOURCES_PATH;
        if(Platform.isWin()){
        absolutePath = absolutePath + "chromedriver.exe"; // "C:\user\...\src\test\resources\chromedriver.exe"
        } else if (Platform.isMac()){
        absolutePath = absolutePath + "chromedriver";// "/Users/.../src/test/resources/chromedriver"
        }

        System.setProperty("webdriver.chrome.driver", absolutePath);
        ChromeOptions cap = new ChromeOptions();
        cap.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
        String url = "http://" + Config.MACHINE_IP + ":" + Config.WEB_PORT_NUMBER + "/wd/hub";
        try {
            DriverAgent.setWebDriver(new RemoteWebDriver(new URL(url), cap));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

当我在windows 10机器上运行此代码时,它运行得非常好,即浏览器打开,测试运行平稳;然而,在mac计算机上,它会不断出现以下堆栈跟踪消息

org.openqa.selenium.SessionNotCreatedException: Unable to create new service: ChromeDriverService
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'xxx', ip: 'xxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.5', java.version: '1.8.0_131'
Driver info: driver.version: unknown
Command duration or timeout: 127 milliseconds
    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.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
    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)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
    at com.automation.core.driver.DriverFactory.webDriverInit(DriverFactory.java:35)
    at com.automation.test.listeners.TestListeners.onTestStart(TestListeners.java:77)
    at org.testng.internal.Invoker.runTestListeners(Invoker.java:1904)
    at org.testng.internal.Invoker.runTestListeners(Invoker.java:1879)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:685)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
    at org.testng.TestNG.run(TestNG.java:1031)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new service: ChromeDriverService
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'xxx', ip: 'xxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.5', java.version: '1.8.0_131'
Driver info: driver.version: unknown
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'xxx', ip: 'xxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.5', java.version: '1.8.0_131'
Driver info: driver.version: unknown
    at org.openqa.selenium.grid.session.remote.ServicedSession$Factory.lambda$get$0(ServicedSession.java:135)
    at org.openqa.selenium.grid.session.remote.ServicedSession$Factory.apply(ServicedSession.java:152)
    at org.openqa.selenium.remote.server.ActiveSessionFactory.lambda$apply$12(ActiveSessionFactory.java:180)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:373)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.server.ActiveSessionFactory.apply(ActiveSessionFactory.java:183)
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$2(NewSessionPipeline.java:66)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
    at java.util.Collections$2.tryAdvance(Collections.java:4717)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$3(NewSessionPipeline.java:69)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.stream.DistinctOps$1$2.accept(DistinctOps.java:175)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
    at java.util.stream.Streams$StreamBuilderImpl.tryAdvance(Streams.java:405)
    at java.util.stream.Streams$ConcatSpliterator.tryAdvance(Streams.java:728)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession(NewSessionPipeline.java:72)
    at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute(BeginSession.java:65)
    at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:235)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)

selenium hub withdebug标志在我尝试运行测试失败后显示以下内容

12:41:19.848 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
12:41:19.930 INFO [GridLauncherV3.lambda$buildLaunchers$5] - Launching Selenium Grid hub on port 9999
2019-07-02 12:41:20.291:INFO::main: Logging initialized @648ms to org.seleniumhq.jetty9.util.log.StdErrLog
12:41:20.445 INFO [Hub.start] - Selenium Grid hub is up and running
12:41:20.445 INFO [Hub.start] - Nodes should register to http://<ip>:9999/grid/register/
12:41:20.446 INFO [Hub.start] - Clients should connect to http://<ip>:9999/wd/hub
12:41:25.521 DEBUG [RegistrationServlet.process] - getting the following registration request  : {
  "class": "org.openqa.grid.common.RegistrationRequest",
  "configuration": {
    "browserTimeout": 0,
    "capabilities": [
      {
        "browserName": "firefox",
        "marionette": true,
        "maxInstances": 5,
        "platform": "MAC",
        "platformName": "MAC",
        "seleniumProtocol": "WebDriver",
        "server:CONFIG_UUID": "7d957d2e-e91a-40ea-aa49-2090126a7e50"
      },
      {
        "browserName": "chrome",
        "maxInstances": 5,
        "platform": "MAC",
        "platformName": "MAC",
        "seleniumProtocol": "WebDriver",
        "server:CONFIG_UUID": "724f2847-bd46-43cb-8952-7f3aa19a70e5"
      },
      {
        "browserName": "safari",
        "maxInstances": 1,
        "platform": "MAC",
        "platformName": "MAC",
        "seleniumProtocol": "WebDriver",
        "server:CONFIG_UUID": "c4faf8a4-6ff6-4df2-966e-4cbab352a3b6",
        "technologyPreview": false
      }
    ],
    "custom": {
    },
    "debug": false,
    "downPollingLimit": 2,
    "enablePlatformVerification": true,
    "host": "10.51.126.109",
    "hub": "http:\u002f\u002flocalhost:9999\u002fgrid\u002fregister",
    "id": "http:\u002f\u002f<ip>:48957",
    "maxSession": 5,
    "nodePolling": 5000,
    "nodeStatusCheckTimeout": 5000,
    "port": 48957,
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "register": true,
    "registerCycle": 5000,
    "remoteHost": "http:\u002f\u002f<ip>:48957",
    "role": "node",
    "servlets": [
    ],
    "timeout": 1800,
    "unregisterIfStillDownAfter": 60000,
    "withoutServlets": [
    ]
  },
  "description": null,
  "name": null
}
12:41:25.545 DEBUG [BaseRemoteProxy.getNewInstance] - Using class org.openqa.grid.selenium.proxy.DefaultRemoteProxy
12:41:25.550 DEBUG [BaseRemoteProxy.setupTimeoutListener] - starting cleanup thread
12:41:25.551 DEBUG [BaseRemoteProxy$CleanUpThread.run] - cleanup thread starting...
12:41:25.552 INFO [DefaultGridRegistry.add] - Registered a node http://<ip>:48957
12:41:25.553 DEBUG [RegistrationServlet.lambda$process$0] - proxy added http://<ip>:48957
12:42:15.029 INFO [RequestHandler.process] - Got a request to create a new session: Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, takesScreenshot: true}
12:42:15.031 DEBUG [ProxySet.getNewSession] - Available nodes: [http://<ip>:48957]
12:42:15.032 DEBUG [BaseRemoteProxy.getNewSession] - Trying to create a new session on node http://<ip>:48957
12:42:15.032 INFO [TestSlot.getNewSession] - Trying to create a new session on test slot {server:CONFIG_UUID=724f2847-bd46-43cb-8952-7f3aa19a70e5, seleniumProtocol=WebDriver, browserName=chrome, maxInstances=5, platformName=MAC, platform=MAC}

节点控制台显示:

java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://localhost:9999/grid/register
12:41:24.746 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
12:41:24.848 INFO [GridLauncherV3.lambda$buildLaunchers$7] - Launching a Selenium Grid node on port 48957
2019-07-02 12:41:24.918:INFO::main: Logging initialized @379ms to org.seleniumhq.jetty9.util.log.StdErrLog
12:41:25.102 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
12:41:25.179 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 48957
12:41:25.179 INFO [GridLauncherV3.lambda$buildLaunchers$7] - Selenium Grid node is up and ready to register to the hub
12:41:25.210 INFO [SelfRegisteringRemote$1.run] - Starting auto registration thread. Will try to register every 5000 ms.
12:41:25.509 INFO [SelfRegisteringRemote.registerToHub] - Registering the node to the hub: http://localhost:9999/grid/register
12:41:25.552 INFO [SelfRegisteringRemote.registerToHub] - The node is registered to the hub and ready to use
12:42:15.100 INFO [ActiveSessionFactory.apply] - Capabilities are: {
  "browserName": "chrome",
  "goog:chromeOptions": {
    "args": [
    ],
    "extensions": [
    ]
  },
  "takesScreenshot": true
}
12:42:15.102 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)

共有1个答案

柳宏深
2023-03-14

更改node命令,使其与chromedriver的路径类似。exe和配置文件。配置节点上可用插槽的json文件:

 java -Dwebdriver.chrome.driver="C:\Users\xxxx\Documents\Browsers\ChromeDirectory\chromedriver.exe" -jar selenium-server-standalone-3.141.59.jar -role node -hub "http://XX.XXX.XX.XXX:4444/grid/register/" -nodeConfig config.json
 类似资料: