Azure DevOps发布流水线回归测试失败求助:ChromeDriver版本不兼容
解决Azure DevOps发布流水线中ChromeDriver与Chrome版本不匹配问题
问题核心
你的回归测试任务失败是因为ChromeDriver版本与代理服务器上的Chrome浏览器版本不兼容,错误提示明确指出当前ChromeDriver仅支持Chrome 86,但代理上的Chrome版本已偏离该版本(更高或更低)。
解决方案
1. 先确认代理上的Chrome版本
在Azure DevOps流水线中插入一个PowerShell任务,执行以下命令获取当前Chrome版本:
# Windows代理 chrome --version # Linux代理 google-chrome --version
2. 方案一:自动匹配ChromeDriver版本(推荐)
如果是Java/Maven项目,使用webdrivermanager工具自动管理ChromeDriver版本,彻底避免版本不匹配问题:
- 在
pom.xml中添加依赖:<dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>webdrivermanager</artifactId> <version>5.6.0</version> <scope>test</scope> </dependency> - 在测试代码中初始化ChromeDriver时调用工具:
WebDriverManager.chromedriver().setup(); WebDriver driver = new ChromeDriver();
该工具会自动检测代理上的Chrome版本,下载对应版本的ChromeDriver并配置到环境中。
3. 方案二:手动适配ChromeDriver版本
如果不想用自动管理工具,可在流水线中添加任务手动下载对应版本的ChromeDriver:
- 以Windows代理为例,添加PowerShell任务执行:
# 替换下方的[CHROME_VERSION]为查到的Chrome主版本(如86、118) $driverVersion = "[CHROME_VERSION]" # 需替换xxxx.xx为对应Chrome版本的具体Driver版本号 Invoke-WebRequest -Uri "https://chromedriver.storage.googleapis.com/$driverVersion.0.xxxx.xx/chromedriver_win32.zip" -OutFile "chromedriver.zip" Expand-Archive -Path "chromedriver.zip" -DestinationPath "$(Agent.ToolsDirectory)/chromedriver" # 将ChromeDriver路径加入环境变量 $env:PATH += ";$(Agent.ToolsDirectory)/chromedriver"
4. 长期维护建议
- 如果使用自托管代理,关闭Chrome的自动更新功能,避免版本突发变更;
- 定期检查Chrome和ChromeDriver版本,保持两者主版本号一致。
完整错误日志
2022-11-17T07:32:37.8052533Z Tests in error: 2022-11-17T07:32:37.8053113Z getData(Academy.BrowserTest): session not created: This version of ChromeDriver only supports Chrome version 86(..) 2022-11-17T07:32:37.8054011Z 2022-11-17T07:32:37.8054528Z Tests run: 2, Failures: 0, Errors: 1, Skipped: 0 2022-11-17T07:32:37.8054792Z 2022-11-17T07:32:37.8123963Z [INFO] ------------------------------------------------------------------------ 2022-11-17T07:32:37.8124674Z [INFO] BUILD FAILURE 2022-11-17T07:32:37.8125946Z [INFO] ------------------------------------------------------------------------ 2022-11-17T07:32:37.8148852Z [INFO] Total time: 01:11 min 2022-11-17T07:32:37.8150695Z [INFO] Finished at: 2022-11-17T07:32:37Z 2022-11-17T07:32:37.8151259Z [INFO] ------------------------------------------------------------------------ 2022-11-17T07:32:37.8166640Z [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project devops: There are test failures. 2022-11-17T07:32:37.8169627Z [ERROR] 2022-11-17T07:32:37.8170486Z [ERROR] Please refer to D:\a\r1\a\_GBSAutomationTestRepo.git\target\surefire-reports for the individual test results. 2022-11-17T07:32:37.8171162Z [ERROR] -> [Help 1] 2022-11-17T07:32:37.8171546Z [ERROR] 2022-11-17T07:32:37.8172050Z [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 2022-11-17T07:32:37.8172644Z [ERROR] Re-run Maven using the -X switch to enable full debug logging. 2022-11-17T07:32:37.8172947Z [ERROR] 2022-11-17T07:32:37.8173332Z [ERROR] For more information about the errors and possible solutions, please read the following articles: 2022-11-17T07:32:37.8174196Z [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 2022-11-17T07:32:37.8760477Z The process 'C:\ProgramData\chocolatey\lib\maven\apache-maven-3.8.6\bin\mvn.cmd' failed with exit code 1 2022-11-17T07:32:37.8761396Z Could not retrieve code analysis results - Maven run failed. 2022-11-17T07:32:39.7735190Z Result Attachments will be stored in LogStore 2022-11-17T07:32:39.8293757Z Run Attachments will be stored in LogStore 2022-11-17T07:32:39.9011567Z ##[error]Build failed. 2022-11-17T07:32:39.9091599Z ##[section]Async Command Start: Publish test results 2022-11-17T07:32:40.2939741Z Publishing test results to test run '18'. 2022-11-17T07:32:40.2969758Z TestResults To Publish 2, Test run id:18 2022-11-17T07:32:40.3013991Z Test results publishing 2, remaining: 0. Test run id: 18 2022-11-17T07:32:41.6218305Z Published Test Run : https://dev.azure.com/gbsr2rindiarepos/AZGBSDemoProject01/_TestManagement/Runs?runId=18&_a=runCharts 2022-11-17T07:32:42.0349797Z Flaky failed test results are opted out of pass percentage 2022-11-17T07:32:42.0701567Z ##[section]Async Command End: Publish test results 2022-11-17T07:32:42.0703521Z ##[section]Finishing: Maven D:\a\r1\a/_GBSAutomationTestRepo.git/pom.xml
内容的提问来源于stack exchange,提问作者budhaditya baneerjee
相关产品推荐
相关产品推荐

