[Selenium] 如何使用Chrome Options 定制测试Chrome 浏览器的特定属性 (类似FirefoxProfiles)

Chrome Options 类似于FirefoxProfiles,用于定制待测试的Chrome 浏览器的特定属性

1)如果希望测试某个浏览器插件,可通过addExtensions方式提前加载以.crx 为扩展名的插件

2)如果希望Chrome 浏览器启动时附带启动参数,可通过addArguments 方式加载

3)如果希望指定机器上特定的某个Chrome 版本运行测试,尤其是同一个台机器上安装了多个不同版本的Chrome 时,可通过setBinary 指定待测试Chrome

示例代码

ChromeOptions options = new ChromeOptions();

options.addExtensions(new File("/path/to/extension.crx"));

options.addArguments("arguments list");

options.setBinary("/path/to/chrome");

WebDriver driver = new ChromeDriver(options);

原文地址:https://www.cnblogs.com/feifeidxl/p/4538671.html