com.sdl.selenium.utils.browsers.ChromeConfigReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Testy Show documentation
Show all versions of Testy Show documentation
Automated Acceptance Testing. Selenium and Selenium WebDriver test framework for web applications.
(optimized for dynamic html, ExtJS, Bootstrap, complex UI, simple web applications/sites)
package com.sdl.selenium.utils.browsers;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.LocalFileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class ChromeConfigReader extends AbstractBrowserConfigReader {
private static final Logger LOGGER = LoggerFactory.getLogger(ChromeConfigReader.class);
private static final String DEFAULT_CONFIG =
"\n browser=chrome" +
"\n browser.driver.path=src\\\\test\\\\resources\\\\drivers\\\\chromedriver.exe" +
"\n browser.download.dir=src\\\\test\\\\resources\\\\download\\\\" +
"\n options.arguments=--lang=en --allow-running-insecure-content --enable-logging --v=1 --test-type" +
"\n options.experimental.profile.default_content_setting_values.automatic_downloads=1" +
"\n options.experimental.profile.content_settings.pattern_pairs.*.multiple-automatic-downloads=1" +
"\n options.experimental.profile.default_content_settings.popups=0" +
"\n options.experimental.download.prompt_for_download=1" +
"\n options.experimental.safebrowsing.enabled=true";
public ChromeConfigReader() {
this(null);
}
public ChromeConfigReader(String resourcePath) {
super(DEFAULT_CONFIG, resourcePath);
}
/***
* If you're using Selenium Grid, make sure the selenium server is in the same folder with the ChromeDriver
* or include the path to the ChromeDriver in command line when registering the node:
* -Dwebdriver.chrome.driver=%{path to chrome driver}
* @return chrome capabilities
* @throws IOException
*/
private DesiredCapabilities getDesiredCapabilities() throws IOException {
String driverPath = getProperty("browser.driver.path");
if (!"".equals(driverPath)) {
System.setProperty("webdriver.chrome.driver", driverPath);
}
ChromeOptions options = new ChromeOptions();
setProfilePreferences(options);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return capabilities;
}
@Override
public WebDriver createDriver() throws IOException {
DesiredCapabilities capabilities = getDesiredCapabilities();
return new ChromeDriver(capabilities);
}
@Override
public WebDriver createDriver(URL remoteUrl) throws IOException {
DesiredCapabilities capabilities = getDesiredCapabilities();
if (isRemoteDriver()) {
RemoteWebDriver driver = new RemoteWebDriver(remoteUrl, capabilities);
driver.setFileDetector(new LocalFileDetector());
return driver;
} else {
return new ChromeDriver(capabilities);
}
}
@Override
public boolean isSilentDownload() {
return !"".equals(getProperty("browser.download.dir"));
}
private void setProfilePreferences(ChromeOptions options) throws IOException {
Map prefs = new HashMap<>();
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy