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

Chrome for Testing 115版本Windows自动化及C#项目适配咨询

Chrome 115+ 自动化测试(Windows环境)实操指南

一、Chrome for Testing 基础使用步骤

  • 下载对应架构(x64/arm64)的Chrome for Testing压缩包,版本需与WebDriver匹配
  • 解压到本地任意目录(如C:\Tools\ChromeForTesting),确保目录下存在chrome.exe可执行文件
  • 避免将解压目录放置到系统默认Chrome安装路径,防止版本冲突

二、既有C#项目配置更新

  • 将项目中的Selenium.WebDriver和Selenium.WebDriver.ChromeDriver NuGet包更新至4.10.0及以上版本,该版本原生支持Chrome for Testing
  • 在项目配置文件(如appsettings.json)中添加Chrome路径配置项:
    "TestSettings": {
      "ChromeBinaryPath": "C:\\Tools\\ChromeForTesting\\chrome.exe"
    }
    
  • 测试项目中可通过配置读取工具(如ConfigurationBuilder)获取该路径

三、WebDriver.cs 代码调整

  • 修改ChromeOptions初始化逻辑,指定Chrome二进制文件路径:
    var chromeOptions = new ChromeOptions();
    // 从配置文件读取Chrome路径
    chromeOptions.BinaryLocation = Configuration.GetValue<string>("TestSettings:ChromeBinaryPath");
    
    // 保留原有测试配置(如无头模式、窗口参数等)
    chromeOptions.AddArgument("--headless=new");
    chromeOptions.AddArgument("--start-maximized");
    
    // 初始化Driver,新版Selenium会自动匹配对应驱动,无需手动下载chromedriver.exe
    using var driver = new ChromeDriver(chromeOptions);
    
  • 若之前代码中手动指定了chromedriver.exe路径,可直接删除,新版Selenium会自动管理驱动版本匹配

四、参考资料

  • Selenium官方文档中关于Chrome for Testing的适配说明
  • Chrome官方发布的Chrome for Testing版本对照表,用于确认Chrome与驱动的对应版本

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 12:55:18