com.version1.webdriver.configuration.driver.ConfiguredFirefoxDriver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of selenium-java-test-automation Show documentation
Show all versions of selenium-java-test-automation Show documentation
A simple Selenium framework offering externalised configuration, a good selection of libraries for supporting
test data, simple WebDriver browser binary resolution and an opinionated approach for WebDriver test design.
The newest version!
package com.version1.webdriver.configuration.driver;
import com.fasterxml.jackson.databind.JsonNode;
import com.version1.webdriver.configuration.BrowserType;
import com.version1.webdriver.configuration.TestConfigHelper;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
public class ConfiguredFirefoxDriver implements ConfiguredDriver {
/**
* @return WebDriver representing RemoteWebDriver grid
*/
public WebDriver getRemoteDriver() throws IOException {
return new RemoteWebDriver(
TestConfigHelper.get().getGridConfig().getGridUrl(), this.getOptions());
}
/**
*
* @return WebDriver representing RemoteWebDriver grid
* @throws IOException if log directory doesn't exist
*/
public WebDriver getLocalDriver() throws IOException {
createLogDirectory();
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"logs/firefox-driver.logs");
WebDriverManager.firefoxdriver().setup();
return new FirefoxDriver(this.getOptions());
}
/**
*
* @return configured options object for target browser driver
*/
public FirefoxOptions getOptions() throws IOException {
FirefoxOptions firefoxOptions = new FirefoxOptions();
Iterator> firefoxPreferences = TestConfigHelper.get()
.getBrowserPreferences(BrowserType.FIREFOX)
.fields();
while (firefoxPreferences.hasNext()) {
Map.Entry entry = firefoxPreferences.next();
JsonNode value = entry.getValue();
String key = entry.getKey();
switch (value.getNodeType()) {
case BOOLEAN:
firefoxOptions.addPreference(key, value.asBoolean());
break;
case NUMBER:
firefoxOptions.addPreference(key, value.asInt());
break;
default:
if (key.equals("browser.download.dir")) {
firefoxOptions.addPreference(key, createFileDownloadDirectory(value.asText()));
} else {
firefoxOptions.addPreference(key, value.asText());
}
break;
}
}
firefoxOptions.setHeadless(TestConfigHelper.get().isHeadless());
return firefoxOptions;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy