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

如何在Robot Framework中使用Chrome for Testing并解决浏览器自动关闭问题

在Robot Framework中使用Chrome for Testing及解决自动关闭问题

一、配置Robot Framework调用Chrome for Testing

从Chrome 114版本起,自动化测试必须使用Chrome for Testing,以下是两种可行的配置方式:

1. 直接指定Chrome for Testing二进制文件路径

确保你的SeleniumLibrary版本在6.0以上(对Chrome for Testing支持更完善)。使用Open Browser关键字时,通过chrome_options参数指定Chrome for Testing的可执行文件路径:

*** Test Cases ***
测试Chrome for Testing
    Open Browser    https://www.example.com    Chrome    chrome_options=--binary-path=/你的本地路径/chrome-for-testing/chrome.exe

注意替换路径为你本地Chrome for Testing的实际安装路径(Windows/macOS/Linux路径格式略有差异)。

2. 用WebDriverManager自动管理版本

如果不想手动维护Chrome for Testing和ChromeDriver的版本匹配,可以使用robotframework-webdrivermanager自动下载配置:
首先安装依赖:

pip install robotframework-webdrivermanager

然后在测试用例中调用:

*** Settings ***
Library    SeleniumLibrary
Library    WebDriverManager

*** Test Cases ***
自动配置Chrome for Testing
    Setup Chrome Driver    chrome
    Open Browser    https://www.example.com    Chrome

该库会自动下载对应版本的Chrome for Testing和ChromeDriver,无需手动指定路径。

二、解决测试结束后浏览器自动关闭的问题

Chrome for Testing默认设计为测试会话结束后自动关闭,即使未设置Teardown或Close Browser关键字。要阻止自动关闭,只需在启动浏览器时添加--no-exit参数:

方法1:配合指定二进制路径使用

Open Browser    https://www.example.com    Chrome    chrome_options=--binary-path=/你的本地路径/chrome-for-testing/chrome.exe --no-exit

方法2:配合WebDriverManager使用

自动配置Chrome for Testing
    Setup Chrome Driver    chrome    chrome_options=--no-exit
    Open Browser    https://www.example.com    Chrome

添加--no-exit后,测试结束后浏览器会保持打开状态,直到你手动关闭它。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 18:20:02