Java Code Examples for org.openqa.selenium.chrome.ChromeOptions#addArguments()

The following examples show how to use org.openqa.selenium.chrome.ChromeOptions#addArguments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AaarghFirefoxWhyDostThouMockMe.java    From webDriverExperiments with MIT License 6 votes vote down vote up
@Test
public void simpleUserInteractionInGoogleChrome(){
    String currentDir = System.getProperty("user.dir");

    // amend this for your location of chromedriver
    String chromeDriverLocation = currentDir + "/../tools/chromedriver/chromedriver.exe";
    System.setProperty("webdriver.chrome.driver", chromeDriverLocation);

    ChromeOptions options = new ChromeOptions();
    options.addArguments("disable-plugins");
    options.addArguments("disable-extensions");

    driver = new ChromeDriver(options);

    checkSimpleCtrlBInteractionWorks();
}
 
Example 2
Source File: IndexStep.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Use Google Chrome headless to fetch the content.
 * @return WebDriver.
 */
protected WebDriver chromeDriver() {
    final ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setBinary("/usr/bin/google-chrome-stable");
    chromeOptions.addArguments("--headless");
    chromeOptions.addArguments("--no-sandbox");
    chromeOptions.addArguments("--ignore-certificate-errors");

    final DesiredCapabilities dc = new DesiredCapabilities();
    dc.setJavascriptEnabled(true);
    dc.setCapability(
        ChromeOptions.CAPABILITY, chromeOptions
    );
    WebDriver chrome = new ChromeDriver(dc);
    return chrome;
}
 
Example 3
Source File: WebDriverFactoryImpl.java    From IridiumApplicationTesting with MIT License 5 votes vote down vote up
private void buildSecureChromeOptions(final ChromeOptions options) {
	options.addArguments("disable-file-system");
	options.addArguments("use-file-for-fake-audio-capture");
	options.addArguments("use-file-for-fake-video-capture");
	options.addArguments("use-fake-device-for-media-stream");
	options.addArguments("use-fake-ui-for-media-stream");
	options.addArguments("disable-sync");
	options.addArguments("disable-tab-for-desktop-share");
	options.addArguments("disable-translate");
	options.addArguments("disable-voice-input");
	options.addArguments("disable-volume-adjust-sound");
	options.addArguments("disable-wake-on-wifi");
}
 
Example 4
Source File: BaseActions.java    From kspl-selenium-helper with GNU General Public License v3.0 5 votes vote down vote up
@BeforeMethod
@Parameters({ "remoteURL", "baseURL", "OS", "browser",
		"version", "internal" })
public void beforeTest(String remoteURL, String baseURL,
		String OS, String browser, String version, String internal)
		throws IOException {
	this.testCase = new TestCase();
	this.testCase.setExecutionEnvironment("{browser:"+browser+",browserVersion:"+version+",OperatingSystem:"+OS+"}");
	this.testCase.setParentURL(baseURL);
	this.testCase.setTestCaseId("KT"+testCaseCount++);
	this.testCase.setScreenshotDirectory(log.getReportDirectory()+ File.separator + "images");
	config = new WebDriverConfig();
	config.setRemoteURL(remoteURL);
	this.baseURL = baseURL;
	config.setOS(OS);
	config.setBrowserName(browser);
	config.setBrowserVersion(version);
	config.setIntenal(Boolean.parseBoolean(internal));
	ChromeOptions options = new ChromeOptions();
	options.addArguments("--start-maximized");
	options.addArguments("--enable-strict-powerful-feature-restrictions");
	JsonObject jsonObject = new JsonObject();
	jsonObject.addProperty("profile.default_content_settings.geolocation", 2);
	jsonObject.addProperty("profile.default_content_setting_values.notifications",2);
	options.setExperimentalOption("prefs", jsonObject);
	options.addArguments("--disable-notifications");
	config.setChromeOptions(options);
	driver = xRemoteWebDriver.getInstance(config, log);
	driver.manage().window().maximize();
	driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	driver.get(this.baseURL);
}
 
Example 5
Source File: ChromeUser.java    From openvidu with Apache License 2.0 5 votes vote down vote up
private static ChromeOptions generateCustomScreenChromeOptions(String screenToCapture, boolean runningAsRoot,
		Path audioFileLocation) {
	ChromeOptions options = new ChromeOptions();
	// This flag selects the entire screen as video source when screen sharing
	options.addArguments("--auto-select-desktop-capture-source=" + screenToCapture);
	options.addArguments("--use-fake-device-for-media-stream");
	options.addArguments("--use-file-for-fake-audio-capture=" + audioFileLocation.toString());

	if (runningAsRoot) {
		options.addArguments("--no-sandbox");
	}

	return options;
}
 
Example 6
Source File: ChromeProxyViaOptions.java    From at.info-knowledge-base with MIT License 5 votes vote down vote up
@BeforeMethod
public void setUpProxy() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    ChromeOptions options = new ChromeOptions();
    options.addArguments("test-type"); //hide --ignore-certifcate-errors https://code.google.com/p/chromedriver/issues/detail?id=799
    options.addArguments("--proxy-server=http://" + proxyIp + ":" + port);
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);

    driver = new ChromeDriver(capabilities);
    //or
    //driver = new ChromeDriver(options);
}
 
Example 7
Source File: WebRtcChromeTest.java    From webdrivermanager-examples with Apache License 2.0 5 votes vote down vote up
@Before
public void setupTest() {
    ChromeOptions options = new ChromeOptions();

    // This flag avoids to grant the user media
    options.addArguments("--use-fake-ui-for-media-stream");

    // This flag fakes user media with synthetic video (green with spinner
    // and timer)
    options.addArguments("--use-fake-device-for-media-stream");

    driver = new ChromeDriver(options);
}
 
Example 8
Source File: ChromeUser.java    From openvidu with Apache License 2.0 5 votes vote down vote up
private static ChromeOptions generateDefaultScreenChromeOptions(boolean runningAsRoot) {
	ChromeOptions options = new ChromeOptions();
	// This flag avoids to grant the user media
	options.addArguments("--use-fake-ui-for-media-stream");
	// This flag fakes user media with synthetic video
	options.addArguments("--use-fake-device-for-media-stream");
	// This flag selects the entire screen as video source when screen sharing
	options.addArguments("--auto-select-desktop-capture-source=Entire screen");

	if (runningAsRoot) {
		options.addArguments("--no-sandbox");
	}

	return options;
}
 
Example 9
Source File: WebDriverFactory.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private static ChromeOptions getChromeUAECaps(DesiredCapabilities caps, Emulator emulator) {
      ChromeOptions chromeOptions = new ChromeOptions();
      if (!emulator.getUserAgent().trim().isEmpty()) {
          chromeOptions.addArguments("--user-agent=" + emulator.getUserAgent());
      }
chromeOptions.merge(caps);
      //caps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
      return chromeOptions;
  }
 
Example 10
Source File: ChromeUser.java    From openvidu with Apache License 2.0 5 votes vote down vote up
private static ChromeOptions generateFakeVideoChromeOptions(Path videoFileLocation) {
	ChromeOptions options = new ChromeOptions();
	// This flag avoids to grant the user media
	options.addArguments("--use-fake-ui-for-media-stream");
	// This flag fakes user media with synthetic video
	options.addArguments("--use-fake-device-for-media-stream");
	// This flag sets the video input as
	options.addArguments("--use-file-for-fake-video-capture=" + videoFileLocation.toString());
	return options;
}
 
Example 11
Source File: ChromeUser.java    From openvidu with Apache License 2.0 5 votes vote down vote up
private ChromeUser(String userName, int timeOfWaitInSeconds, ChromeOptions options) {
	super(userName, timeOfWaitInSeconds);
	options.setAcceptInsecureCerts(true);
	options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE);

	options.addArguments("--disable-infobars");
	options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"}); 

	Map<String, Object> prefs = new HashMap<String, Object>();
	prefs.put("profile.default_content_setting_values.media_stream_mic", 1);
	prefs.put("profile.default_content_setting_values.media_stream_camera", 1);
	options.setExperimentalOption("prefs", prefs);

	String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME");
	if (REMOTE_URL != null) {
		log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
		try {
			this.driver = new RemoteWebDriver(new URL(REMOTE_URL), options);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	} else {
		log.info("Using local web driver");
		this.driver = new ChromeDriver(options);
	}

	this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);
	this.configureDriver();
}
 
Example 12
Source File: WebDriverTypeTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
@PrepareForTest(fullyQualifiedNames = "org.vividus.selenium.WebDriverType$3")
public void testGetChromeWebDriverWithAdditionalOptions() throws Exception
{
    Map<String, String> experimentalOptionValue = singletonMap(OPTION_KEY, OPTION_VALUE);
    WebDriverConfiguration configuration = new WebDriverConfiguration();
    configuration.setBinaryPath(Optional.of(PATH));
    configuration.setCommandLineArguments(new String[] { ARGUMENT });
    configuration.setExperimentalOptions(singletonMap(MOBILE_EMULATION, experimentalOptionValue));
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setBinary(PATH);
    chromeOptions.addArguments(ARGUMENT);
    chromeOptions.setExperimentalOption(MOBILE_EMULATION, experimentalOptionValue);
    testGetChromeWebDriver(configuration, chromeOptions);
}
 
Example 13
Source File: WebDriverFactoryImpl.java    From IridiumApplicationTesting with MIT License 5 votes vote down vote up
private WebDriver buildChrome(
	final String browser,
	final Optional<ProxyDetails<?>> mainProxy,
	final DesiredCapabilities capabilities,
	final boolean secure,
	final boolean headless,
	final boolean fullscreen) {

	/*
		These options are documented at:
		https://developers.google.com/web/updates/2017/04/headless-chrome
	 */
	final ChromeOptions options = buildChromeOptions();
	if (secure) {
		buildSecureChromeOptions(options);
	}

	/*
		There are some issues using Chrome headless
		https://bugs.chromium.org/p/chromium/issues/detail?id=721739
	 */
	if (headless) {
		options.addArguments("headless");
		options.addArguments("disable-gpu");
		options.addArguments("no-sandbox");
		options.addArguments("allow-running-insecure-content");
		options.addArguments("ignore-certificate-errors");
		options.addArguments("window-size=1920,1080");
	}

	if (fullscreen) {
		options.addArguments("kiosk");
	}

	capabilities.setCapability(ChromeOptions.CAPABILITY, options);

	return Try.of(() -> new ChromeDriver(capabilities))
		.onFailure(ex -> exitWithError(browser, ex))
		.getOrElseThrow(ex -> new RuntimeException(ex));
}
 
Example 14
Source File: WebRtcRemoteChromeTest.java    From webdrivermanager-examples with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws MalformedURLException {
    DesiredCapabilities capabilities = chrome();
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--use-fake-ui-for-media-stream");
    options.addArguments("--use-fake-device-for-media-stream");
    capabilities.setCapability(CAPABILITY, options);

    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),
            capabilities);
}
 
Example 15
Source File: CreateDriver.java    From Selenium-Framework-Design-in-Data-Driven-Testing with MIT License 4 votes vote down vote up
/**
 * setDriver method to create driver instance
 *
 * @param browser
 * @param environment
 * @param platform
 * @param optPreferences
 * @throws Exception
 */
@SafeVarargs
public final void setDriver(String browser,
                            String platform,
                            String environment,
                            Map<String, Object>... optPreferences)
                            throws Exception {

    DesiredCapabilities caps = null;
    String getPlatform = null;
    props.load(new FileInputStream(Global_VARS.SE_PROPS));

    switch (browser) {
        case "firefox":
            caps = DesiredCapabilities.firefox();

            FirefoxOptions ffOpts = new FirefoxOptions();
            FirefoxProfile ffProfile = new FirefoxProfile();

            ffProfile.setPreference("browser.autofocus", true);
            ffProfile.setPreference("browser.tabs.remote.autostart.2", false);

            caps.setCapability(FirefoxDriver.PROFILE, ffProfile);
            caps.setCapability("marionette", true);

            // then pass them to the local WebDriver
            if ( environment.equalsIgnoreCase("local") ) {
                System.setProperty("webdriver.gecko.driver", props.getProperty("gecko.driver.windows.path"));
                webDriver.set(new FirefoxDriver(ffOpts.merge(caps)));
            }

            break;
        case "chrome":
            caps = DesiredCapabilities.chrome();

            ChromeOptions chOptions = new ChromeOptions();
            Map<String, Object> chromePrefs = new HashMap<String, Object>();

            chromePrefs.put("credentials_enable_service", false);

            chOptions.setExperimentalOption("prefs", chromePrefs);
            chOptions.addArguments("--disable-plugins", "--disable-extensions", "--disable-popup-blocking");

            caps.setCapability(ChromeOptions.CAPABILITY, chOptions);
            caps.setCapability("applicationCacheEnabled", false);

            if ( environment.equalsIgnoreCase("local") ) {
                System.setProperty("webdriver.chrome.driver", props.getProperty("chrome.driver.windows.path"));
                webDriver.set(new ChromeDriver(chOptions.merge(caps)));
            }

            break;
        case "internet explorer":
            caps = DesiredCapabilities.internetExplorer();

            InternetExplorerOptions ieOpts = new InternetExplorerOptions();

            ieOpts.requireWindowFocus();
            ieOpts.merge(caps);

            caps.setCapability("requireWindowFocus", true);

            if ( environment.equalsIgnoreCase("local") ) {
                System.setProperty("webdriver.ie.driver", props.getProperty("ie.driver.windows.path"));
                webDriver.set(new InternetExplorerDriver(ieOpts.merge(caps)));
            }

            break;
    }

    getEnv = environment;
    getPlatform = platform;
    sessionId.set(((RemoteWebDriver) webDriver.get()).getSessionId().toString());
    sessionBrowser.set(caps.getBrowserName());
    sessionVersion.set(caps.getVersion());
    sessionPlatform.set(getPlatform);

    System.out.println("\n*** TEST ENVIRONMENT = "
            + getSessionBrowser().toUpperCase()
            + "/" + getSessionPlatform().toUpperCase()
            + "/" + getEnv.toUpperCase()
            + "/Selenium Version=" + props.getProperty("selenium.revision")
            + "/Session ID=" + getSessionId() + "\n");

    getDriver().manage().timeouts().implicitlyWait(IMPLICIT_TIMEOUT, TimeUnit.SECONDS);
    getDriver().manage().window().maximize();
}
 
Example 16
Source File: RemoteDriverManager.java    From selenium-java-bootstrap with MIT License 4 votes vote down vote up
private static MutableCapabilities defaultChromeOptions() {
    ChromeOptions capabilities = new ChromeOptions();
    capabilities.addArguments("start-maximized");

    return capabilities;
}
 
Example 17
Source File: WebDriverFactory.java    From KITE with Apache License 2.0 4 votes vote down vote up
/**
 * Create common chrome option to create chrome web driver
 *
 * @param capability the Client capability
 * @param specs the Client browser specs
 * @return the chrome option
 */
private static ChromeOptions setCommonChromeOptions(Capability capability, BrowserSpecs specs) {
  ChromeOptions chromeOptions = new ChromeOptions();
  if (capability.useFakeMedia()) {
    // We use fake media or mediafile as webcam/microphone
    chromeOptions.addArguments("use-fake-ui-for-media-stream");
    chromeOptions.addArguments("use-fake-device-for-media-stream");
    chromeOptions.addArguments("enable-automation"); // https://stackoverflow.com/a/43840128/1689770
    chromeOptions.addArguments("no-sandbox"); //https://stackoverflow.com/a/50725918/1689770
    chromeOptions.addArguments("disable-infobars"); //https://stackoverflow.com/a/43840128/1689770
    chromeOptions.addArguments("disable-dev-shm-usage"); //https://stackoverflow.com/a/50725918/1689770
    chromeOptions.addArguments("disable-browser-side-navigation"); //https://stackoverflow.com/a/49123152/1689770
    chromeOptions.addArguments("disable-gpu"); //https://stackoverflow.com/questions/51959986/how-to-solve-selenium-chromedriver-timed-out-receiving-message-from-renderer-exc      // If we use mediafile (only if not on android)
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    if (!specs.getPlatform().equals(Platform.ANDROID)) {
      if (capability.getVideo() != null || capability.getAudio() != null) {
        chromeOptions.addArguments("allow-file-access-from-files");
        if (capability.getVideo() != null) {
          chromeOptions.addArguments("use-file-for-fake-video-capture="
              + fetchMediaPath(capability.getVideo(), specs.getBrowserName()));
        }
        if (capability.getAudio() != null) {
          chromeOptions.addArguments("use-file-for-fake-audio-capture="
              + fetchMediaPath(capability.getAudio(), specs.getBrowserName()));
        }
      }
    } else {
      chromeOptions.setExperimentalOption("w3c", false);
    }
  }

  // Create an Hashmap to edit user profile
  Map<String, Object> prefs = new HashMap<String, Object>();
  // Allow access to camera & micro
  // This does not affect fake media options above
  // but still logged the permission in profile, somes sfu require these
  prefs.put("profile.default_content_setting_values.media_stream_camera", 1);
  prefs.put("profile.default_content_setting_values.media_stream_mic", 1);
  chromeOptions.setExperimentalOption("prefs", prefs);


  if (specs.getPlatform().equals(Platform.ANDROID)) {
    return chromeOptions;
  }

  chromeOptions.addArguments("auto-select-desktop-capture-source=Entire screen");
  if (! "electron".equals(specs.getVersion())) {
    // CHROME ONLY
    String extension = System.getProperty("kite.chrome.extension");
    extension = extension == null ? specs.getExtension() : extension;
    if (extension != null && !extension.isEmpty()) {
      chromeOptions.addExtensions(new File(extension));
    }
  }
  /*
   * if (client.getVersion().toLowerCase().contains("electron")) {
   * chromeOptions.setBinary(client.getBrowserSpecs().getPathToBinary()); }
   */
  if (capability.isHeadless()) {
    chromeOptions.addArguments("headless");
  }
  if (capability.getWindowSize() != null && capability.getWindowSize().trim().length() > 0) {
    chromeOptions.addArguments("window-size=" + capability.getWindowSize());
  }
  for (String flag : capability.getFlags()) {
    chromeOptions.addArguments(flag);
    // Examples:
    /*
     * chromeOptions.addArguments("--disable-gpu");
     * chromeOptions.addArguments("no-sandbox");
     */
  }
  logger.debug("ChromeOptions: " + chromeOptions.toJson());
  return chromeOptions;
}
 
Example 18
Source File: ChromeInterface.java    From candybean with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void start() throws CandybeanException {
	ChromeOptions chromeOptions = new ChromeOptions();
	String chromeDriverLogPath = candybean.config.getPathValue("browser.chrome.driver.log.path");
	logger.info("chromeDriverLogPath: " + chromeDriverLogPath);
	chromeOptions.addArguments("--log-path=" + chromeDriverLogPath);

	String chromeDriverPath = candybean.config.getPathValue("browser.chrome.driver.path");
	validateChromeDriverExist(chromeDriverPath);

	// If parallel is enabled and the chromedriver-<os>_<thread-name> doesn't exist, duplicate one
	// from chromedriver-<os> and give it executable permission.
	if("true".equals(candybean.config.getPathValue("parallel.enabled"))) {
		String originalChromePath = chromeDriverPath;
		// Cross platform support
		if(OSValidator.isWindows()) {
			chromeDriverPath = chromeDriverPath.replaceAll("(.*)(\\.exe)", "$1_" +
					Thread.currentThread().getName() + "$2");
		} else {
			chromeDriverPath = chromeDriverPath.replaceAll("$", "_" + Thread.currentThread().getName());
		}

		if(!new File(chromeDriverPath).exists()) {
			try {
				FileUtils.copyFile(new File(originalChromePath), new File(chromeDriverPath));
				if(!OSValidator.isWindows()) { //Not needed in Windows
					Runtime.getRuntime().exec("chmod u+x " + chromeDriverPath);
				}
			} catch(IOException e) {
				String error = "Cannot duplicate a new chromedriver for parallelization";
				logger.severe(error);
				throw new CandybeanException(error);
			}
		}
	}

	logger.info("chromeDriverPath: " + chromeDriverPath);
	System.setProperty("webdriver.chrome.driver", chromeDriverPath);
	logger.info("Instantiating Chrome with:\n    log path:"+ chromeDriverLogPath +
			"\n    driver path: " + chromeDriverPath);

	super.wd = ThreadGuard.protect(new ChromeDriver(chromeOptions));
	super.start(); // requires wd to be instantiated first
}
 
Example 19
Source File: ChromeCapabilitiesFactory.java    From seleniumtestsframework with Apache License 2.0 4 votes vote down vote up
public DesiredCapabilities createCapabilities(final DriverConfig webDriverConfig) {

        DesiredCapabilities capability = null;
        capability = DesiredCapabilities.chrome();
        capability.setBrowserName(DesiredCapabilities.chrome().getBrowserName());

        ChromeOptions options = new ChromeOptions();
        if (webDriverConfig.getUserAgentOverride() != null) {
            options.addArguments("--user-agent=" + webDriverConfig.getUserAgentOverride());
        }

        capability.setCapability(ChromeOptions.CAPABILITY, options);

        if (webDriverConfig.isEnableJavascript()) {
            capability.setJavascriptEnabled(true);
        } else {
            capability.setJavascriptEnabled(false);
        }

        capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

        if (webDriverConfig.getBrowserVersion() != null) {
            capability.setVersion(webDriverConfig.getBrowserVersion());
        }

        if (webDriverConfig.getWebPlatform() != null) {
            capability.setPlatform(webDriverConfig.getWebPlatform());
        }

        if (webDriverConfig.getProxyHost() != null) {
            Proxy proxy = webDriverConfig.getProxy();
            capability.setCapability(CapabilityType.PROXY, proxy);
        }

        if (webDriverConfig.getChromeBinPath() != null) {
            capability.setCapability("chrome.binary", webDriverConfig.getChromeBinPath());
        }

        // Set ChromeDriver for local mode
        if (webDriverConfig.getMode() == DriverMode.LOCAL) {
            String chromeDriverPath = webDriverConfig.getChromeDriverPath();
            if (chromeDriverPath == null) {
                try {
                    if (System.getenv("webdriver.chrome.driver") != null) {
                        System.out.println("get Chrome driver from property:"
                                + System.getenv("webdriver.chrome.driver"));
                        System.setProperty("webdriver.chrome.driver", System.getenv("webdriver.chrome.driver"));
                    } else {
                        handleExtractResources();
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            } else {
                System.setProperty("webdriver.chrome.driver", chromeDriverPath);
            }
        }

        return capability;
    }
 
Example 20
Source File: WebDriverCapabilities.java    From QVisual with Apache License 2.0 4 votes vote down vote up
/**
 * List of Chromium Command Line Switches
 * http://peter.sh/experiments/chromium-command-line-switches/#disable-popup-blocking
 */
private void setupChrome() {
    HashMap<String, Object> prefs = new HashMap<>();
    prefs.put("profile.default_content_setting_values.notifications", 2);
    prefs.put("profile.default_content_settings.popups", 0);
    prefs.put("download.default_directory", DOWNLOAD_DIRECTORY);
    prefs.put("download.prompt_for_download", false);
    prefs.put("profile.content_settings.pattern_pairs.*.multiple-automatic-downloads", 1);
    prefs.put("safebrowsing.enabled", true);
    prefs.put("plugins.always_open_pdf_externally", true);

    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setExperimentalOption("useAutomationExtension", false);
    chromeOptions.setExperimentalOption("prefs", prefs);
    chromeOptions.addArguments("allow-file-access");
    chromeOptions.addArguments("allow-file-access-from-files");
    chromeOptions.addArguments("disable-background-networking");
    chromeOptions.addArguments("disable-background-timer-throttling");
    chromeOptions.addArguments("disable-breakpad");
    chromeOptions.addArguments("disable-child-account-detection");
    chromeOptions.addArguments("disable-clear-browsing-data-counters");
    chromeOptions.addArguments("disable-client-side-phishing-detection");
    chromeOptions.addArguments("disable-cloud-import");
    chromeOptions.addArguments("disable-component-cloud-policy");
    chromeOptions.addArguments("disable-component-update");
    chromeOptions.addArguments("disable-default-apps");
    chromeOptions.addArguments("disable-download-notification");
    chromeOptions.addArguments("disable-extensions");
    chromeOptions.addArguments("disable-extensions-file-access-check");
    chromeOptions.addArguments("disable-extensions-http-throttling");
    chromeOptions.addArguments("disable-hang-monitor");
    chromeOptions.addArguments("disable-infobars");
    chromeOptions.addArguments("disable-popup-blocking");
    chromeOptions.addArguments("disable-print-preview");
    chromeOptions.addArguments("disable-prompt-on-repost");
    chromeOptions.addArguments("disable-sync");
    chromeOptions.addArguments("disable-translate");
    chromeOptions.addArguments("disable-web-resources");
    chromeOptions.addArguments("disable-web-security");
    chromeOptions.addArguments("dns-prefetch-disable");
    chromeOptions.addArguments("download-whole-document");
    chromeOptions.addArguments("enable-logging");
    chromeOptions.addArguments("enable-screenshot-testing-with-mode");
    chromeOptions.addArguments("ignore-certificate-errors");
    chromeOptions.addArguments("log-level=0");
    chromeOptions.addArguments("metrics-recording-only");
    chromeOptions.addArguments("mute-audio");
    chromeOptions.addArguments("no-default-browser-check");
    chromeOptions.addArguments("no-displaying-insecure-content");
    chromeOptions.addArguments("no-experiments");
    chromeOptions.addArguments("no-first-run");
    chromeOptions.addArguments("no-sandbox");
    chromeOptions.addArguments("no-service-autorun");
    chromeOptions.addArguments("noerrdialogs");
    chromeOptions.addArguments("password-store=basic");
    chromeOptions.addArguments("reduce-security-for-testing");
    chromeOptions.addArguments("safebrowsing-disable-auto-update");
    chromeOptions.addArguments("safebrowsing-disable-download-protection");
    chromeOptions.addArguments("safebrowsing-disable-extension-blacklist");
    chromeOptions.addArguments("start-maximized");
    chromeOptions.addArguments("test-type=webdriver");
    chromeOptions.addArguments("use-mock-keychain");
    chromeOptions.setHeadless(BROWSER_HEADLESS);

    capabilities.merge(chromeOptions);
}