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

求助:如何将Flutter Web自动化测试关联到Chrome for Testing浏览器?

解决Flutter Web自动化测试关联Chrome for Testing的问题

1. 配置环境变量指定Chrome for Testing和ChromeDriver路径

Windows下先找到你的Chrome for Testing可执行文件路径(默认一般是C:\Program Files\Google\Chrome for Testing\Application\chrome.exe),以及ChromeDriver的路径(比如C:\tools\chromedriver.exe)。

在执行测试前,先在命令行里设置两个关键环境变量:

PowerShell命令:

$env:CHROME_EXECUTABLE = "C:\Program Files\Google\Chrome for Testing\Application\chrome.exe"
$env:WEBDRIVER_SERVER = "C:\tools\chromedriver.exe"

Cmd命令:

set CHROME_EXECUTABLE=C:\Program Files\Google\Chrome for Testing\Application\chrome.exe
set WEBDRIVER_SERVER=C:\tools\chromedriver.exe

2. 修改测试驱动文件禁用移动端模拟

默认Flutter Web会强制启用移动端视图,你需要在test_driver/app.dart里添加配置,强制使用桌面模式:

import 'package:flutter_driver/driver_extension.dart';
import 'package:你的应用包名/main.dart' as app;

void main() {
  enableFlutterDriverExtension();
  
  // 配置WebDriver参数,关闭移动端模拟
  final webConfig = {
    'browserName': 'chrome',
    'chromeOptions': {
      'args': [
        '--window-size=1920,1080', // 指定桌面分辨率
        '--disable-mobile-emulation', // 禁用移动端模拟
      ],
    },
  };
  
  app.main(webConfig);
}

3. 执行测试命令

完成上述配置后,直接执行测试命令即可:

flutter drive --target=test_driver/app.dart --browser-name=chrome

4. 验证关联结果

启动后检查浏览器右上角菜单→帮助→关于Google Chrome,确认标题是"Chrome for Testing",同时页面会以桌面端样式加载,而非移动端响应式视图。

注意:必须保证ChromeDriver和Chrome for Testing的版本严格匹配,版本不兼容会导致无法建立连接。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 10:42:38