首页 > 解决方案 > Selenium Grid (Java) 无法与新的 Windows 终端一起正常工作

问题描述

我们在我们的项目中使用 Selenium (Java) 进行测试,并且我们成功运行了 Selenium Grid(基本上是一个带有各种浏览器的集线器)。

为 Windows CLI 运行 Selenium Grid 的脚本是这个,存储在 .bat 文件中:

start java -jar selenium-server-standalone-3.141.59.jar -role hub
start java -Dwebdriver.chrome.driver="D:\drivers\chromedriver.exe" -jar selenium-server-standalone-3.141.59.jar -role webdriver -hub http://localhost:4444/grid/register -port 4546
start java -Dwebdriver.ie.driver="D:\drivers\IEDriverServer.exe" -jar selenium-server-standalone-3.141.59.jar -role webdriver -hub http://localhost:4444/grid/register -port 4547

这个脚本一直在工作,但它在窗口中有 3 个单独的窗口,有点笨拙。

最近,Windows 发布了一个 Windows 终端 (WT),其中一项新功能是可以选择在一个窗口中运行多个选项卡。因此,我将之前的脚本改写为使用 Windows 终端的脚本,这样我的任务栏就不会杂乱无章了,它看起来像这样:

wt -d d:\Programs\SeleniumStandaloneServer\ java -jar selenium-server-standalone-3.141.59.jar -role hub; sp -d d:\Programs\SeleniumStandaloneServer\ java -Dwebdriver.chrome.driver='D:\drivers\chromedriver.exe' -jar selenium-server-standalone-3.141.59.jar -role webdriver -hub http://localhost:4444/grid/register -port 4546; sp -H -d d:\Programs\HIE\SeleniumStandaloneServer\ java -Dwebdriver.ie.driver='D:\drivers\IEDriverServer.exe' -jar selenium-server-standalone-3.141.59.jar -role webdriver -hub http://localhost:4444/grid/register -port 4547

问题是,每当我运行这个 WT 脚本而不是前一个脚本时,它只运行一次。在你问之前,是的,我用记事本++检查了转录后字母或可能不需要的空格的差异,人为错误 - 脚本本身很好。

前一个脚本每次都有效(每次启动浏览器并且我们的测试正确完成时),这个脚本每秒(偶数)次有效,每第一个(奇数)它都会在我们的 IntelliJ 控制台中留下一条错误消息:

有人可以帮我解决这个问题吗?我不知道可能出了什么问题。

INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
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: 'DESKTOP-B4ED459', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.8'
Driver info: driver.version: unknown
Command duration or timeout: 185 milliseconds
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    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.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
    at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
    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.browsersoft.selenium.core.SeleniumRunner.run(SeleniumRunner.java:44)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1260)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1027)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:814)
    at groovy.lang.GroovyObject.invokeMethod(GroovyObject.java:39)
    at com.browsersoft.selenium.SeleniumManager.executeTest(SeleniumManager.java:42)
    at com.browsersoft.config.core.scenario.Scenario.executeSeleniumStep(Scenario.java:223)
    at com.browsersoft.config.core.scenario.Scenario.executeStep(Scenario.java:189)
    at com.browsersoft.config.gui.document.scenario.ScenarioStepPanel$4.run(ScenarioStepPanel.java:224)
    at java.base/java.lang.Thread.run(Thread.java:834)
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: 'DESKTOP-B4ED459', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.8'
Driver info: driver.version: unknown
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'DESKTOP-B4ED459', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.8'
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:195)
    at java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:442)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
    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:195)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
    at java.util.Collections$2.tryAdvance(Collections.java:4747)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$3(NewSessionPipeline.java:69)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.util.stream.DistinctOps$1$2.accept(DistinctOps.java:175)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
    at java.util.stream.Streams$StreamBuilderImpl.tryAdvance(Streams.java:397)
    at java.util.stream.Streams$ConcatSpliterator.tryAdvance(Streams.java:720)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
    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:515)
    at java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.lang.Thread.run(Thread.java:834) 

这是运行失败后 WT 控制台窗口的内容:

16:09:30.589 INFO [GridLauncherV3.lambda$buildLaunchers$5] - Launching Selenium Grid hub on port 4444
2021-10-21 16:09:30.985:INFO::main: Logging initialized @744ms to org.seleniumhq.jetty9.util.log.StdErrLog
16:09:31.670 INFO [Hub.start] - Selenium Grid hub is up and running
16:09:31.672 INFO [Hub.start] - Nodes should register to http://172.30.1.4:4444/grid/register/
16:09:31.673 INFO [Hub.start] - Clients should connect to http://172.30.1.4:4444/wd/hub
16:09:32.615 INFO [DefaultGridRegistry.add] - Registered a node http://172.30.1.4:4546
16:09:32.616 INFO [DefaultGridRegistry.add] - Registered a node http://172.30.1.4:4547
16:10:32.120 INFO [RequestHandler.process] - Got a request to create a new session: Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, version: }
16:10:32.124 INFO [TestSlot.getNewSession] - Trying to create a new session on test slot {server:CONFIG_UUID=63e678db-5111-42b8-ba59-bb9780f21e47, seleniumProtocol=WebDriver, browserName=chrome, maxInstances=5, platformName=WIN10, platform=WIN10} 
16:09:30.653 INFO [GridLauncherV3.lambda$buildLaunchers$7] - Launching a Selenium Grid node on port 4546
2021-10-21 16:09:31.510:INFO::main: Logging initialized @1210ms to org.seleniumhq.jetty9.util.log.StdErrLog
16:09:31.721 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
16:09:31.800 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4546
16:09:31.801 INFO [GridLauncherV3.lambda$buildLaunchers$7] - Selenium Grid node is up and ready to register to the hub
16:09:32.082 INFO [SelfRegisteringRemote$1.run] - Starting auto registration thread. Will try to register every 5000 ms.
16:09:32.341 INFO [SelfRegisteringRemote.registerToHub] - Registering the node to the hub: http://localhost:4444/grid/register
16:09:32.616 INFO [SelfRegisteringRemote.registerToHub] - The node is registered to the hub and ready to use
16:10:32.191 INFO [ActiveSessionFactory.apply] - Capabilities are: {
  "browserName": "chrome",
  "goog:chromeOptions": {
    "args": [
    ],
    "extensions": [
    ]
  },
  "version": ""
}
16:10:32.193 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
16:09:30.704 INFO [GridLauncherV3.lambda$buildLaunchers$7] - Launching a Selenium Grid node on port 4547
2021-10-21 16:09:31.577:INFO::main: Logging initialized @1216ms to org.seleniumhq.jetty9.util.log.StdErrLog
16:09:31.780 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
16:09:31.862 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4547
16:09:31.862 INFO [GridLauncherV3.lambda$buildLaunchers$7] - Selenium Grid node is up and ready to register to the hub
16:09:32.135 INFO [SelfRegisteringRemote$1.run] - Starting auto registration thread. Will try to register every 5000 ms.
16:09:32.340 INFO [SelfRegisteringRemote.registerToHub] - Registering the node to the hub: http://localhost:4444/grid/register
16:09:32.616 INFO [SelfRegisteringRemote.registerToHub] - The node is registered to the hub and ready to use

标签: javaseleniumwindows-terminal

解决方案


因此,我发现了问题所在,并发布了答案,以防其他人遇到类似问题:

事实证明 Selenium 或 Windows Terminal 没有任何问题,我们不得不开始使用 Selenium Grid 的最新稳定版本(我们仍在使用 3.xx 版本,因为它是长期以来唯一支持的版本,并且最近才发布4.xx 版本)+ 更改脚本,因为 Selenium 开发人员决定更改版本之间的开关,所以旧脚本(发布在问题本身)将不起作用,必须像这样更新:

@echo off
start java -jar selenium-server-standalone-4.1.1.jar hub
start java -Dwebdriver.chrome.driver="D:\drivers\chromedriver.exe" -jar selenium-server-standalone-4.1.1.jar node --hub http://localhost:4444/grid/register --port 4546
start java -Dwebdriver.ie.driver="D:\drivers\IEDriverServer.exe" -jar selenium-server-standalone-4.1.1.jar node --hub http://localhost:4444/grid/register --port 4547

对于 Windows 终端,同样如此:

wt -d d:\Programs\SeleniumStandaloneServer\ java -jar selenium-server-standalone-4.1.1.jar hub; sp -d d:\Programs\SeleniumStandaloneServer\ java -Dwebdriver.chrome.driver="D:\drivers\chromedriver.exe" -jar selenium-server-standalone-4.1.1.jar node --hub http://localhost:4444/grid/register --port 4546; sp -H -d d:\Programs\SeleniumStandaloneServer\ java -Dwebdriver.ie.driver="D:\Praca\Automation\drivers\IEDriverServer.exe" -jar selenium-server-standalone-4.1.1.jar node --hub http://localhost:4444/grid/register --port 4547

现在 Grid 可以与这两个脚本一起正常工作。


推荐阅读