Search in sources :

Example 26 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile in project cerberus-source by cerberustesting.

the class SeleniumServerService method setCapabilityBrowser.

/**
 * Instanciate DesiredCapabilities regarding the browser
 *
 * @param capabilities
 * @param browser
 * @param tCExecution
 * @return
 * @throws CerberusException
 */
private DesiredCapabilities setCapabilityBrowser(DesiredCapabilities capabilities, String browser, TestCaseExecution tCExecution) throws CerberusException {
    try {
        if (browser.equalsIgnoreCase("firefox")) {
            capabilities = DesiredCapabilities.firefox();
            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("app.update.enabled", false);
            try {
                Invariant invariant = invariantService.convert(invariantService.readByKey("COUNTRY", tCExecution.getCountry()));
                if (invariant.getGp2() == null) {
                    LOG.warn("Country selected (" + tCExecution.getCountry() + ") has no value of GP2 in Invariant table, default language set to English (en)");
                    profile.setPreference("intl.accept_languages", "en");
                } else {
                    profile.setPreference("intl.accept_languages", invariant.getGp2());
                }
            } catch (CerberusException ex) {
                LOG.warn("Country selected (" + tCExecution.getCountry() + ") not in Invariant table, default language set to English (en)");
                profile.setPreference("intl.accept_languages", "en");
            }
            // Set UserAgent if testCaseUserAgent or robotUserAgent is defined
            String usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());
            if (!StringUtil.isNullOrEmpty(usedUserAgent)) {
                profile.setPreference("general.useragent.override", usedUserAgent);
            }
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
        } else if (browser.equalsIgnoreCase("IE")) {
            capabilities = DesiredCapabilities.internetExplorer();
        } else if (browser.equalsIgnoreCase("chrome")) {
            capabilities = DesiredCapabilities.chrome();
            /**
             * Add custom capabilities
             */
            ChromeOptions options = new ChromeOptions();
            // Maximize windows for chrome browser
            options.addArguments("--start-fullscreen");
            // Set UserAgent if necessary
            String usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());
            if (!StringUtil.isNullOrEmpty(usedUserAgent)) {
                options.addArguments("--user-agent=" + usedUserAgent);
            }
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        } else if (browser.contains("android")) {
            capabilities = DesiredCapabilities.android();
        } else if (browser.contains("ipad")) {
            capabilities = DesiredCapabilities.ipad();
        } else if (browser.contains("iphone")) {
            capabilities = DesiredCapabilities.iphone();
        } else if (browser.contains("safari")) {
            capabilities = DesiredCapabilities.safari();
        } else {
            LOG.warn("Not supported Browser : " + browser);
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replace("%MES%", "Browser '" + browser + "' is not supported"));
            mes.setDescription("Not supported Browser : " + browser);
            throw new CerberusException(mes);
        }
    } catch (CerberusException ex) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
        mes.setDescription(mes.getDescription().replace("%MES%", "Failed to set capability on the browser '" + browser + "' due to " + ex.getMessageError().getDescription()));
        throw new CerberusException(mes);
    }
    return capabilities;
}
Also used : Invariant(org.cerberus.crud.entity.Invariant) CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 27 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile in project drools by kiegroup.

the class FEELShowcaseIT method getFirefoxProfile.

private FirefoxProfile getFirefoxProfile() {
    final FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("webdriver.log.init", true);
    profile.setPreference("webdriver.log.browser.ignore", true);
    profile.setPreference("webdriver.log.driver.ignore", true);
    profile.setPreference("webdriver.log.profiler.ignore", true);
    return profile;
}
Also used : FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 28 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile in project wcomponents by BorderTech.

the class FirefoxWebDriverType method getDriverImplementation.

/**
 * {@inheritDoc}.
 */
@Override
public FirefoxDriver getDriverImplementation() {
    WebDriverManager.getInstance(DriverManagerType.FIREFOX).setup();
    FirefoxOptions options = new FirefoxOptions(getCapabilities());
    FirefoxBinary binary = getFirefoxBinary();
    FirefoxProfile profile = getFirefoxProfile();
    if (profile != null) {
        // it gets angry if you give it a null profile
        options.setProfile(profile);
    }
    // options.setHeadless(true);
    options.setBinary(binary);
    return new FirefoxDriver(options);
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 29 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile in project acceptance-test-harness by jenkinsci.

the class KerberosSsoTest method getNegotiatingFirefox.

private FirefoxDriver getNegotiatingFirefox(KerberosContainer kdc, String tokenCache) {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setAlwaysLoadNoFocusLib(true);
    // Allow auth negotiation for jenkins under test
    String trustedUris = jenkins.url.toExternalForm();
    String jenkins_local_hostname = System.getenv("JENKINS_LOCAL_HOSTNAME");
    // if JENKINS_LOCAL_HOSTNAME is set, we add this to FF nego uris
    if (jenkins_local_hostname != null && !jenkins_local_hostname.isEmpty()) {
        try {
            // In the case where JENKINS_LOCAL_HOSTNAME is an IP,
            // we need to add its resolved hostname for auth negociation
            String hostName = InetAddress.getByName(jenkins_local_hostname).getCanonicalHostName();
            trustedUris = trustedUris + ", " + hostName;
        } catch (UnknownHostException e) {
            e.printStackTrace();
            throw new Error(e);
        }
    }
    profile.setPreference("network.negotiate-auth.trusted-uris", trustedUris);
    profile.setPreference("network.negotiate-auth.delegation-uris", trustedUris);
    FirefoxBinary binary = new FirefoxBinary();
    // Inject config and TGT
    binary.setEnvironmentProperty("KRB5CCNAME", tokenCache);
    binary.setEnvironmentProperty("KRB5_CONFIG", kdc.getKrb5ConfPath());
    // Turn debug on
    binary.setEnvironmentProperty("KRB5_TRACE", diag.touch("krb5_trace.log").getAbsolutePath());
    binary.setEnvironmentProperty("NSPR_LOG_MODULES", "negotiateauth:5");
    binary.setEnvironmentProperty("NSPR_LOG_FILE", diag.touch("firefox.nego.log").getAbsolutePath());
    String display = FallbackConfig.getBrowserDisplay();
    if (display != null) {
        binary.setEnvironmentProperty("DISPLAY", display);
    }
    final FirefoxDriver driver = new FirefoxDriver(binary, profile);
    cleaner.addTask(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            try {
                driver.quit();
            } catch (UnreachableBrowserException ex) {
                System.err.println("Browser died already");
                ex.printStackTrace();
            }
        }

        @Override
        public String toString() {
            return "Close Kerberos WebDriver after test";
        }
    });
    return driver;
}
Also used : UnknownHostException(java.net.UnknownHostException) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) Statement(org.junit.runners.model.Statement) Matchers.containsString(org.hamcrest.Matchers.containsString) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 30 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method createWebDriver.

private WebDriver createWebDriver(TestName testName) throws IOException {
    String browser = System.getenv("BROWSER");
    if (browser == null)
        browser = "firefox";
    browser = browser.toLowerCase(Locale.ENGLISH);
    String display = getBrowserDisplay();
    switch(browser) {
        case "firefox":
            FirefoxProfile profile = new FirefoxProfile();
            profile.setAlwaysLoadNoFocusLib(true);
            profile.setPreference(LANGUAGE_SELECTOR, "en");
            // Config screen with many plugins can cause FF to complain JS takes too long to complete - set longer timeout
            profile.setPreference(DOM_MAX_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            profile.setPreference(DOM_MAX_CHROME_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            FirefoxBinary binary = new FirefoxBinary();
            if (display != null) {
                binary.setEnvironmentProperty("DISPLAY", display);
            }
            return new FirefoxDriver(binary, profile);
        case "ie":
        case "iexplore":
        case "iexplorer":
            return new InternetExplorerDriver();
        case "chrome":
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", Collections.singletonMap(LANGUAGE_SELECTOR, "en"));
            ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
            if (display != null) {
                builder.withEnvironment(Collections.singletonMap("DISPLAY", display));
            }
            return new ChromeDriver(builder.build(), options);
        case "safari":
            return new SafariDriver();
        case "htmlunit":
            return new HtmlUnitDriver(true);
        case "saucelabs":
        case "saucelabs-firefox":
            DesiredCapabilities caps = DesiredCapabilities.firefox();
            caps.setCapability("version", "29");
            caps.setCapability("platform", "Windows 7");
            caps.setCapability("name", testName.get());
            // if running inside Jenkins, expose build ID
            String tag = System.getenv("BUILD_TAG");
            if (tag != null)
                caps.setCapability("build", tag);
            return new SauceLabsConnection().createWebDriver(caps);
        case "phantomjs":
            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
            capabilities.setCapability(LANGUAGE_SELECTOR, "en");
            capabilities.setCapability(LANGUAGE_SELECTOR_PHANTOMJS, "en");
            return new PhantomJSDriver(capabilities);
        case "remote-webdriver-firefox":
            String u = System.getenv("REMOTE_WEBDRIVER_URL");
            if (StringUtils.isBlank(u)) {
                throw new Error("remote-webdriver-firefox requires REMOTE_WEBDRIVER_URL to be set");
            }
            return new RemoteWebDriver(// http://192.168.99.100:4444/wd/hub
            new URL(u), DesiredCapabilities.firefox());
        default:
            throw new Error("Unrecognized browser type: " + browser);
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) URL(java.net.URL) SafariDriver(org.openqa.selenium.safari.SafariDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SauceLabsConnection(org.jenkinsci.test.acceptance.utils.SauceLabsConnection)

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