QAF 3.2.0与Selenium 4兼容异常:浏览器空白无法打开URL
环境信息
- 操作系统:Mac OSX
- Java版本:17
- 尝试过的Selenium版本:4.0.0、4.1.2、4.11.0
相关配置代码
<sourceVersion>1.8</sourceVersion> <targetVersion>1.8</targetVersion> <qaf.version>3.2.0</qaf.version> <selenium.version>3.141.59</selenium.version> <selenium.version>4.0.0</selenium.version>
错误日志
Aug 15, 2023 11:20:20 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Aug 15, 2023 11:20:20 PM org.openqa.selenium.remote.http.WebSocket$Listener onError
WARNING: Invalid Status code=403 text=Forbidden
java.io.IOException: Invalid Status code=403 text=Forbidden
at org.asynchttpclient.netty.handler.WebSocketHandler.abort(WebSocketHandler.java:92)
at org.asynchttpclient.netty.handler.WebSocketHandler.handleRead(WebSocketHandler.java:118)
at org.asynchttpclient.netty.handler.AsyncHttpClientHandler.channelRead(AsyncHttpClientHandler.java:78)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:311)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:432)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)
Unable to create driver instance in 1st attempt with retry timeout of 0 seconds. You can check/set value of 'driver.init.retry.timeout' appropriately to set retry timeout on driver initialization failure.Unable to Create Driver Instance for chrome: Unable to establish websocket connection to http://localhost:62671/devtools/browser/a7e95bd5-94a4-4089-9c14-aa0d6e9427c0 Build info: version: '4.0.0', revision: '3a21814679' System info: host: 'XXXXX-MacBook-Pro.local', ip: 'fe80:0:0:0:14e0:460c:5f80:9dbc%en0', os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '13.4', java.version: '17.0.8' Driver info: driver.version: ChromeDriver Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 8.84 sec <<< FAILURE! Preparing For Shut Down... Result updator: Completed 1 Remaining 0 result to be update. Results : Failed tests: Testing Google.com(com.qmetry.qaf.automation.step.client.Scenario): Timed out after 0 seconds: Unable to create driver instance in 1st attempt with retry timeout of 0 seconds. You can check/set value of 'driver.init.retry.timeout' appropriately to set retry timeout on driver initialization failure. Tests run: 1, Failures: 1, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11.398 s [INFO] Finished at: 2023-08-15T23:20:21+10:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.9:test (default-test) on project qaf-blank-project-maven: There are test failures. [ERROR] [ERROR] Please refer to /Users/Documents/Automation/qaf-blank-project-maven-master/test-results/15_Aug_2023_01_20_pm for the individual test results. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException XXXX@XXXXX-MacBook-Pro qaf-blank-project-maven-master %
解决建议
- 升级QAF版本:QAF 3.2.0对Selenium 4的兼容性支持不足,建议升级到QAF 3.3.0及以上版本,这类版本针对Selenium 4的WebSocket连接、W3C协议适配做了优化。
- 统一编译与Java版本:当前配置的
sourceVersion和targetVersion为1.8,但实际使用Java 17,版本不匹配可能引发兼容性问题,建议修改为:<sourceVersion>17</sourceVersion> <targetVersion>17</targetVersion> - 匹配ChromeDriver与浏览器版本:Selenium 4对浏览器和驱动的版本一致性要求更严格,确保ChromeDriver版本与本地Chrome浏览器完全对应。
- 调整驱动初始化参数:在QAF配置文件中添加以下参数,延长驱动初始化重试超时时间并启用W3C协议:
driver.init.retry.timeout=30000 selenium.grid.w3c=true
内容的提问来源于stack exchange,提问作者Renish K.R

