You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps中C# Selenium测试遇‘Unable to receive message from renderer’问题

解决Azure DevOps中Selenium测试“Unable to receive message from renderer”问题

环境信息

  • Chrome版本:133.0.6943.127
  • ChromeDriver版本:133.0.6943.126

问题描述

本地运行Selenium测试无异常,但在Azure DevOps代理执行时出现Unable to receive message from renderer严重警告。已尝试更新Chrome和ChromeDriver版本,添加部分Chrome Options并延长页面加载超时,目前警告仅出现在日志中但问题未彻底解决。

Azure DevOps日志片段

Starting ChromeDriver 133.0.6943.126 (cffa127ce7b6be72885391527c15b452056a2e81-refs/branch-heads/6943@{#1570}) on port 49360
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully on port 49360.
##[debug]Agent environment resources - Disk: D:\ Available 11931.57 MB out of 14334.00 MB, Memory: Used 1956.00 MB out of 7167.00 MB, CPU: Usage 2.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.57 MB out of 14334.00 MB, Memory: Used 1953.00 MB out of 7167.00 MB, CPU: Usage 74.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.57 MB out of 14334.00 MB, Memory: Used 2174.00 MB out of 7167.00 MB, CPU: Usage 98.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.57 MB out of 14334.00 MB, Memory: Used 2278.00 MB out of 7167.00 MB, CPU: Usage 31.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.57 MB out of 14334.00 MB, Memory: Used 2231.00 MB out of 7167.00 MB, CPU: Usage 86.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.57 MB out of 14334.00 MB, Memory: Used 2302.00 MB out of 7167.00 MB, CPU: Usage 97.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2452.00 MB out of 7167.00 MB, CPU: Usage 18.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2495.00 MB out of 7167.00 MB, CPU: Usage 6.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2440.00 MB out of 7167.00 MB, CPU: Usage 68.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2457.00 MB out of 7167.00 MB, CPU: Usage 27.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2470.00 MB out of 7167.00 MB, CPU: Usage 27.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2498.00 MB out of 7167.00 MB, CPU: Usage 59.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2525.00 MB out of 7167.00 MB, CPU: Usage 15.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2463.00 MB out of 7167.00 MB, CPU: Usage 11.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2490.00 MB out of 7167.00 MB, CPU: Usage 81.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2419.00 MB out of 7167.00 MB, CPU: Usage 7.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2452.00 MB out of 7167.00 MB, CPU: Usage 8.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2459.00 MB out of 7167.00 MB, CPU: Usage 19.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2496.00 MB out of 7167.00 MB, CPU: Usage 43.00%
##[debug]Agent environment resources - Disk: D:\ Available 11931.51 MB out of 14334.00 MB, Memory: Used 2552.00 MB out of 7167.00 MB, CPU: Usage 91.00%
**[1740500492.633][SEVERE]: Unable to receive message from renderer**

已尝试的操作

  1. 添加Chrome Options:
"--disable-gpu",
 "--no-sandbox",
 "--user-data-dir=C:\\temp\\SeleniumProfile",
 "--disable-extensions",
 "--disable-software-rasterizer",
 "--disable-renderer-accessibility",
 "--disable-dev-shm-usage",
 "--disable-features=NetworkService"
  1. 设置页面加载超时:
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(120);

可行解决方案

1. 调整Chrome启动参数

在现有Options基础上添加或修改以下参数:

  • --headless=new:使用新版无头模式,更贴近正常浏览器环境,降低渲染层通信故障概率
  • --window-size=1920,1080:指定固定窗口尺寸,避免代理环境中窗口大小异常引发渲染问题
  • --disable-background-timer-throttling:禁用后台定时器节流,防止页面脚本延迟导致通信中断
  • --disable-backgrounding-occluded-windows:禁止将遮挡窗口转入后台,维持渲染进程活跃状态

修改后的Options示例:

"--disable-gpu",
 "--no-sandbox",
 "--user-data-dir=C:\\temp\\SeleniumProfile",
 "--disable-extensions",
 "--disable-software-rasterizer",
 "--disable-renderer-accessibility",
 "--disable-dev-shm-usage",
 "--disable-features=NetworkService",
 "--headless=new",
 "--window-size=1920,1080",
 "--disable-background-timer-throttling",
 "--disable-backgrounding-occluded-windows"

2. 优化Azure代理资源配置

从日志可见代理CPU使用率多次接近100%,易导致渲染进程被抢占:

  • 切换至配置更高的Azure代理池(如2核4G及以上规格的机器)
  • 在VSTest任务中设置资源限制,避免测试进程持续占用过高CPU
  • 测试执行前清理代理机器临时文件与闲置进程,释放系统资源

3. 完善Selenium等待策略

除页面加载超时外,添加元素显式等待,避免因页面未完全渲染就执行操作引发通信问题:

// 设置隐式等待
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

// 使用显式等待等待目标元素加载完成
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.Until(d => d.FindElement(By.Id("target-element")).Displayed);

4. 消除Chrome与ChromeDriver版本微小差异

当前Chrome版本133.0.6943.127,ChromeDriver为133.0.6943.126,虽属同一大版本,但微小版本差可能引发兼容性问题,需确保两者版本完全一致。

5. 调整用户数据目录权限与清理

指定的--user-data-dir路径在Azure代理上可能存在权限问题或残留缓存,改为使用系统临时目录,并在测试结束后清理:

"--user-data-dir=" + Path.GetTempPath() + "SeleniumTempProfile"

测试完成后添加代码删除该临时目录,避免后续测试受残留文件影响。

内容的提问来源于stack exchange,提问作者Sanoop MV

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 03:45:55