General idea (as it was pointed by @AlexeyR. & @kirbycope) is to use Chrome Profile with already defined setting & plug-ins. Here I'm going to describe some underwater rocks of this solution.
So first of all, we create WebDriver with ChromeOptions:
String username = System.getProperty("user.name");
String chromeProfile = "C:\\Users\\" + username + "\\AppData\\Local\\Google\\Chrome\\AutomationProfile";
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=" + chromeProfile);
// 'disable-default-apps' is added by default and needs to be removed because it disables plugin I use
options.setExperimentalOption("excludeSwitches", Arrays.asList("disable-default-apps"));
options.addArguments("start-maximized");
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\resources\\chromedriver.exe");
webDriver = new ChromeDriver(options);
Rock #1: WebDriver failes on initialization if default chrome profile is used and chrome is already opened (are you going to close all your browser windows all the time when you run test? :) ). To avoid this you should set Chrome profile to e.g. ...Chrome\AutomationProfile
(all files from ...Chrome\User Data
(default profile) are copied to that folder with an exception of file ...Chrome\User Data\Default\Current Tabs
- you don't need to open last tabs from the user profile)
Rock #2: by default WebDriver adds Chrome Option --disable-default-apps
which disabled plug-in I need, so be prepared to remove/add options you need (check them with the link chrome://version/
- see Comand line
)
Rock #3: If you use selenide library you can not apply ChromeOptions to configuration (check issue 'Are not added capabilities from Configuration.browserCapabilities'). So there is a workaround for this issue to define WebDriver manually as described above and pass it to Selenide with method com.codeborne.selenide.WebDriverRunner.setWebDriver
:
setWebDriver(webDriver);