use of org.openqa.selenium.firefox.FirefoxProfile in project selenium-tests by Wikia.
the class FirefoxBrowser method setOptions.
@Override
public void setOptions() {
// to path where executive file of FF is placed
if ("WINDOWS 8".equalsIgnoreCase(System.getProperty("os.name"))) {
System.setProperty("webdriver.firefox.bin", "c:" + File.separator + "Program Files (x86)" + File.separator + "Mozilla Firefox" + File.separator + "Firefox.exe");
}
// Check if user who is running tests have write access in ~/.mozilla dir and home dir
if ("LINUX".equalsIgnoreCase(System.getProperty("os.name"))) {
File homePath = new File(System.getenv("HOME") + File.separator);
File mozillaPath = new File(homePath + File.separator + ".mozilla");
File tmpFile;
if (mozillaPath.exists()) {
try {
tmpFile = File.createTempFile("webdriver", null, mozillaPath);
} catch (IOException ex) {
Log.log("Can't create file", ex, false);
throw new WebDriverException("Can't create file in path: %s".replace("%s", mozillaPath.getAbsolutePath()));
}
} else {
try {
tmpFile = File.createTempFile("webdriver", null, homePath);
} catch (IOException ex) {
Log.log("Can't create file", ex, false);
throw new WebDriverException("Can't create file in path: %s".replace("%s", homePath.getAbsolutePath()));
}
}
tmpFile.delete();
}
firefoxProfile = new FirefoxProfile(new File(ClassLoader.getSystemResource("FirefoxProfiles/Default").getPath()));
if ("true".equals(Configuration.getPageLoadStrategy())) {
firefoxProfile.setPreference("webdriver.load.strategy", "unstable");
}
if ("true".equals(Configuration.getDisableFlash())) {
firefoxProfile.setPreference("plugin.state.flash", 0);
}
}
use of org.openqa.selenium.firefox.FirefoxProfile in project carina by qaprosoft.
the class DesktopCapabilitiesTest method getFirefoxCapabilityWithCustomFirefoxProfileTest.
@Test(groups = { "DesktopCapabilitiesTestClass" })
public static void getFirefoxCapabilityWithCustomFirefoxProfileTest() {
String testName = "firefox - getFirefoxCustomCapabilityTest";
FirefoxCapabilities firefoxCapabilities = new FirefoxCapabilities();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("media.eme.enabled", !MEDIA_EME_ENABLED);
profile.setPreference("media.gmp-manager.updateEnabled", !MEDIA_GMP_MANAGER_UPDATE_ENABLED);
DesiredCapabilities capabilities = firefoxCapabilities.getCapability(testName, profile);
Assert.assertEquals(capabilities.getBrowserName(), BrowserType.FIREFOX, "Returned browser name is not valid!");
Assert.assertEquals(capabilities.getCapability("name"), testName, "Returned test name is not valid!");
Assert.assertFalse((Boolean) capabilities.getCapability(CapabilityType.TAKES_SCREENSHOT), "Returned capability value is not valid!");
boolean actualMediaEmeEnabled = ((FirefoxProfile) capabilities.getCapability("firefox_profile")).getBooleanPreference("media.eme.enabled", true);
Assert.assertEquals(actualMediaEmeEnabled, !MEDIA_EME_ENABLED, "Returned firefox profile preference is not valid!");
boolean actualMediaGmpManagerUpdateEnabled = ((FirefoxProfile) capabilities.getCapability("firefox_profile")).getBooleanPreference("media.gmp-manager.updateEnabled", true);
Assert.assertEquals(actualMediaGmpManagerUpdateEnabled, !MEDIA_GMP_MANAGER_UPDATE_ENABLED, "Returned firefox profile preference is not valid!");
}
use of org.openqa.selenium.firefox.FirefoxProfile in project carina by qaprosoft.
the class AbstractCapabilities method getDefaultFirefoxProfile.
/**
* Generate default default Carina FirefoxProfile.
*
* @return Firefox profile.
*/
// keep it public to be bale to get default and override on client layerI
public FirefoxProfile getDefaultFirefoxProfile() {
FirefoxProfile profile = new FirefoxProfile();
// update browser language
String browserLang = Configuration.get(Parameter.BROWSER_LANGUAGE);
if (!browserLang.isEmpty()) {
LOGGER.info("Set Firefox lanaguage to: " + browserLang);
profile.setPreference("intl.accept_languages", browserLang);
}
boolean generated = false;
int newPort = 7055;
int i = 100;
while (!generated && (--i > 0)) {
newPort = PortProber.findFreePort();
generated = firefoxPorts.add(newPort);
}
if (!generated) {
newPort = 7055;
}
if (firefoxPorts.size() > 20) {
firefoxPorts.remove(0);
}
profile.setPreference(FirefoxProfile.PORT_PREFERENCE, newPort);
LOGGER.debug("FireFox profile will use '" + newPort + "' port number.");
profile.setPreference("dom.max_chrome_script_run_time", 0);
profile.setPreference("dom.max_script_run_time", 0);
if (Configuration.getBoolean(Configuration.Parameter.AUTO_DOWNLOAD) && !(Configuration.isNull(Configuration.Parameter.AUTO_DOWNLOAD_APPS) || "".equals(Configuration.get(Configuration.Parameter.AUTO_DOWNLOAD_APPS)))) {
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", getAutoDownloadFolderPath());
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", Configuration.get(Configuration.Parameter.AUTO_DOWNLOAD_APPS));
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.saveLinkAsFilenameTimeout", 1);
profile.setPreference("pdfjs.disabled", true);
profile.setPreference("plugin.scan.plid.all", false);
profile.setPreference("plugin.scan.Acrobat", "99.0");
} else if (Configuration.getBoolean(Configuration.Parameter.AUTO_DOWNLOAD) && Configuration.isNull(Configuration.Parameter.AUTO_DOWNLOAD_APPS) || "".equals(Configuration.get(Configuration.Parameter.AUTO_DOWNLOAD_APPS))) {
LOGGER.warn("If you want to enable auto-download for FF please specify '" + Configuration.Parameter.AUTO_DOWNLOAD_APPS.getKey() + "' param");
}
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);
// TODO: implement support of custom args if any
return profile;
}
use of org.openqa.selenium.firefox.FirefoxProfile in project carina by qaprosoft.
the class AbstractCapabilities method addFirefoxOptions.
private DesiredCapabilities addFirefoxOptions(DesiredCapabilities caps) {
FirefoxProfile profile = getDefaultFirefoxProfile();
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
caps.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
// add all custom firefox args
for (String arg : Configuration.get(Parameter.FIREFOX_ARGS).split(",")) {
if (arg.isEmpty()) {
continue;
}
options.addArguments(arg.trim());
}
// add all custom firefox preferences
for (String preference : Configuration.get(Parameter.FIREFOX_PREFERENCES).split(",")) {
if (preference.isEmpty()) {
continue;
}
// TODO: think about equal sign inside name or value later
preference = preference.trim();
String name = preference.split("=")[0].trim();
String value = preference.split("=")[1].trim();
// TODO: test approach with numbers
if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) {
options.addPreference(name, Boolean.valueOf(value));
} else {
options.addPreference(name, value);
}
}
String driverType = Configuration.getDriverType();
if (Configuration.getBoolean(Parameter.HEADLESS) && driverType.equals(SpecialKeywords.DESKTOP)) {
options.setHeadless(Configuration.getBoolean(Parameter.HEADLESS));
}
return caps;
}
use of org.openqa.selenium.firefox.FirefoxProfile in project carina by qaprosoft.
the class FirefoxCapabilities method getCapability.
/**
* Generate DesiredCapabilities for Firefox with default Carina FirefoxProfile.
*
* @param testName
* - String.
* @return Firefox desired capabilities.
*/
public DesiredCapabilities getCapability(String testName) {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = initBaseCapabilities(capabilities, BrowserType.FIREFOX, testName);
capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, false);
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("media.eme.enabled", true);
profile.setPreference("media.gmp-manager.updateEnabled", true);
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
return capabilities;
}
Aggregations