Search in sources :

Example 41 with FirefoxProfile

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);
    }
}
Also used : IOException(java.io.IOException) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException)

Example 42 with FirefoxProfile

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!");
}
Also used : DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) Test(org.testng.annotations.Test)

Example 43 with FirefoxProfile

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;
}
Also used : FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 44 with FirefoxProfile

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;
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 45 with FirefoxProfile

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;
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Aggregations

FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)46 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)25 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)20 File (java.io.File)16 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)10 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)10 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)9 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)9 IOException (java.io.IOException)7 WebDriverException (org.openqa.selenium.WebDriverException)7 Actions (org.openqa.selenium.interactions.Actions)7 HashMap (java.util.HashMap)6 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)6 URL (java.net.URL)5 Dimension (org.openqa.selenium.Dimension)5 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)5 WebDriver (org.openqa.selenium.WebDriver)5 TakesScreenshot (org.openqa.selenium.TakesScreenshot)3 FirefoxBinary (org.openqa.selenium.firefox.FirefoxBinary)3 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)3