Selenide ChromeOptions
2021-06-10 本文已影响0人
嗚嗚雲
Selenium 使用说明,增加 ChromeOptions
String CHROME_DRIVER_PATH = "/usr/bin/chromedriver";
System.setProperty("webdriver.chrome.driver", CHROME_DRIVER_PATH);
Configuration.reportsFolder = "test-result/reports";
Configuration.remote = "http://127.0.0.1:4444/wd/hub";
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments( //
"--verbose",
"--headless",// 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
"--disable-web-security",
"--ignore-certificate-errors",
"--allow-running-insecure-content",
"--allow-insecure-localhost",
"--hide-scrollbars",// 隐藏滚动条, 应对一些特殊页面
"--blink-settings=imagesEnabled=false",// 不加载图片, 提升速度
"--auto-open-devtools-for-tabs",
"--no-sandbox",// 解决DevToolsActivePort file doesn't exist 的错误
"--disable-gpu",// 谷歌文档提到需要加上这个属性来规避bug
"--start-fullscreen",// 全屏启动
"--no-startup-window",// 启动时,不激活(前置)窗口
"--window-size=3072x1920",// 设置分辨率
"--host-rules=MAP www.baidu.com 192.168.8.23" // 设置hosts
);
// selenide 6版本更新了chromeOptions的设置方式,避免丢失配置
// 详细:https://groups.google.com/g/selenide/c/o54TPyqpwhg
Configuration.browserCapabilities = chromeOptions;
WebDriverRunner.clearBrowserCache();