info.novatec.testit.webtester.browser.proxy.ChromeFactory Maven / Gradle / Ivy
The newest version!
package info.novatec.testit.webtester.browser.proxy;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import info.novatec.testit.webtester.browser.BrowserFactory;
import info.novatec.testit.webtester.browser.WebDriverBrowser;
import info.novatec.testit.webtester.browser.Browser;
/**
* Factory class for creating Chrome {@link Browser} objects. Needs the
* 'webdriver.chrome.driver' system property pointing to the driver server
* executable.
*
* Important information on using IE-Driver:
* https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver
*
*
* @see Browser
* @see ChromeDriver
* @since 2.0
*/
public class ChromeFactory implements BrowserFactory {
private ProxyConfiguration proxyConfiguration;
/**
* Creates a new {@link Browser} object for a Chrome web browser. Any
* desired capabilities will be initialized as well.
*
* Currently the following capabilities are configurable:
*
* - proxy setting using a {@link ProxyConfiguration}
*
*
* @return the created {@link Browser}.
* @see Browser
* @see BrowserFactory
* @since 2.0
*/
@Override
public Browser createBrowser() {
DesiredCapabilities capabilities = new DesiredCapabilities();
setOptionalProxyConfiguration(capabilities);
return createBrowser(capabilities);
}
@Override
public Browser createBrowser(DesiredCapabilities capabilities) {
return createBrowser(new ChromeDriver(capabilities));
}
@Override
public Browser createBrowser(WebDriver webDriver) {
if (!(webDriver instanceof ChromeDriver)) {
throw new IllegalArgumentException("Wrong WebDriver class: " + webDriver + " only ChromeDriver is allowed!");
}
return WebDriverBrowser.buildForWebDriver(webDriver);
}
private void setOptionalProxyConfiguration(DesiredCapabilities capabilities) {
if (proxyConfiguration != null) {
Proxy proxy = new Proxy();
proxyConfiguration.configureProxy(proxy);
capabilities.setCapability(CapabilityType.PROXY, proxy);
}
}
@Override
public ChromeFactory withProxyConfiguration(ProxyConfiguration configuration) {
proxyConfiguration = configuration;
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy