Example usage for org.openqa.selenium.firefox FirefoxProfile setAcceptUntrustedCertificates

List of usage examples for org.openqa.selenium.firefox FirefoxProfile setAcceptUntrustedCertificates

Introduction

In this page you can find the example usage for org.openqa.selenium.firefox FirefoxProfile setAcceptUntrustedCertificates.

Prototype


public void setAcceptUntrustedCertificates(boolean acceptUntrustedSsl) 

Source Link

Document

Sets whether Firefox should accept SSL certificates which have expired, signed by an unknown authority or are generally untrusted.

Usage

From source file:com.seleniumtests.browserfactory.MarionetteCapabilitiesFactory.java

License:Apache License

protected void configProfile(final FirefoxProfile profile, final DriverConfig webDriverConfig) {
    profile.setAcceptUntrustedCertificates(webDriverConfig.isSetAcceptUntrustedCertificates());
    profile.setAssumeUntrustedCertificateIssuer(webDriverConfig.isSetAssumeUntrustedCertificateIssuer());

    if (webDriverConfig.getFirefoxBinPath() != null) {
        System.setProperty("webdriver.firefox.bin", webDriverConfig.getFirefoxBinPath());
    }/*from w  w  w .j  av a  2s .co  m*/

    if (webDriverConfig.getUserAgentOverride() != null) {
        profile.setPreference("general.useragent.override", webDriverConfig.getUserAgentOverride());
    }

    if (webDriverConfig.getNtlmAuthTrustedUris() != null) {
        profile.setPreference("network.automatic-ntlm-auth.trusted-uris",
                webDriverConfig.getNtlmAuthTrustedUris());
    }

    if (webDriverConfig.getBrowserDownloadDir() != null) {
        profile.setPreference("browser.download.dir", webDriverConfig.getBrowserDownloadDir());
        profile.setPreference("browser.download.folderList", 2);
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                "application/octet-stream,text/plain,application/pdf,application/zip,text/csv,text/html");
    }

    if (!webDriverConfig.isEnableJavascript()) {
        profile.setPreference("javascript.enabled", false);
    }

    // fix permission denied issues
    profile.setPreference("capability.policy.default.Window.QueryInterface", "allAccess");
    profile.setPreference("capability.policy.default.Window.frameElement.get", "allAccess");
    profile.setPreference("capability.policy.default.HTMLDocument.compatMode.get", "allAccess");
    profile.setPreference("capability.policy.default.Document.compatMode.get", "allAccess");
    profile.setEnableNativeEvents(false);
    profile.setPreference("dom.max_chrome_script_run_time", 0);
    profile.setPreference("dom.max_script_run_time", 0);
}

From source file:com.surevine.alfresco.space.webdriver.AlfrescoWebDriverTestCase.java

License:Open Source License

@Before
public void openBrowserAndLogin() {
    ProfilesIni allProfiles = new ProfilesIni();
    FirefoxProfile profile = allProfiles.getProfile("selenium");

    // This looks counter-intuitive, but it works there has been lots of talk on the google groups about
    // the trusting and otherwise of ssl certificates.
    profile.setAcceptUntrustedCertificates(false);
    FirefoxDriver ffd = new FirefoxDriver(profile);

    casLoginPage = PageFactory.initElements(ffd, CasLogin.class);
    casLoginPage.open("http://79.125.19.164/share");
    space = casLoginPage.login("admin", "password");
}

From source file:com.surevine.alfresco.space.webdriver.TestSpaceDashboard.java

License:Open Source License

@Before
public void openTheBrowser() {

    ProfilesIni allProfiles = new ProfilesIni();
    FirefoxProfile profile = allProfiles.getProfile("selenium");
    // This looks counter-intuitive, but it works there has been lots of talk on the google groups about
    // the trusting and otherwise of ssl certificates.
    profile.setAcceptUntrustedCertificates(false);
    FirefoxDriver ffd = new FirefoxDriver(profile);

    casLoginPage = PageFactory.initElements(ffd, CasLogin.class);
    casLoginPage.open("http://79.125.19.164/share");
    space = casLoginPage.login("admin", "password");
}

From source file:com.tascape.qa.th.webui.comm.Firefox.java

License:Apache License

public Firefox(boolean enableFirebug) throws Exception {
    FirefoxProfile profile;

    ProfilesIni profileIni = new ProfilesIni();
    String profileName = sysConfig.getProperty(SYSPROP_FF_PROFILE_NAME);
    if (profileName != null) {
        LOG.debug("Load Firefox profile named as {}", profileName);
        profile = profileIni.getProfile(profileName);
    } else {/*from   ww w  .  ja va2  s .  c o m*/
        LOG.debug("Load Firefox profile named as {}", DEFAULT_FF_PROFILE_NAME);
        profile = profileIni.getProfile(DEFAULT_FF_PROFILE_NAME);
    }
    if (profile == null) {
        throw new Exception("Cannot find Firefox profile");
    }

    profile.setPreference("app.update.enabled", false);
    profile.setEnableNativeEvents(false);
    profile.setAcceptUntrustedCertificates(true);
    profile.setAssumeUntrustedCertificateIssuer(false);
    profile.setPreference("dom.max_chrome_script_run_time", 0);
    profile.setPreference("dom.max_script_run_time", 0);
    if (enableFirebug) {
        this.firebug = new Firebug();
        this.firebug.updateProfile(profile);
    }
    long end = System.currentTimeMillis() + 180000;
    while (System.currentTimeMillis() < end) {
        try {
            super.setWebDriver(new FirefoxDriver(profile));
            break;
        } catch (org.openqa.selenium.WebDriverException ex) {
            String msg = ex.getMessage();
            LOG.warn(msg);
            if (!msg.contains("Unable to bind to locking port 7054 within 45000 ms")) {
                throw ex;
            }
        }
    }
}

From source file:com.watchrabbit.crawler.driver.factory.FirefoxWebDriverFactory.java

License:Apache License

@Override
public synchronized RemoteWebDriver produceDriver() {
    LOGGER.debug("Returning new driver");
    if (drivers.isEmpty()) {
        LOGGER.debug("Creating new driver");
        FirefoxProfile profile = new FirefoxProfile();
        profile.setAcceptUntrustedCertificates(true);
        RemoteWebDriver ff = new FirefoxDriver(profile);
        return ff;
    } else {/*from  w  w w. j  a va 2  s .  co m*/
        LOGGER.debug("Returning {} driver from pool", drivers.peek().getWindowHandle());
        return drivers.poll();
    }
}

From source file:jp.co.nssol.h5.test.selenium.base.DriverFactory.java

License:Apache License

/**
 * FireFox????//  w ww .  j  a v a 2 s  .  co m
 *
 * @return
 */
private static WebDriver setupFireFoxDriver() {
    FirefoxProfile profile = null;

    try {
        File file = new File(SettingsReader.getProperty(PKEY_FIREBUG_PATH));
        profile = new FirefoxProfile();
        profile.addExtension(file);
        profile.setAcceptUntrustedCertificates(true);
        profile.setAssumeUntrustedCertificateIssuer(false);
        profile.setPreference("extensions.firebug.currentVersion", "1.9.1");
    } catch (IOException e) {
        e.printStackTrace();
    }

    return new FirefoxDriver(profile) {
        @Override
        public String toString() {
            return "FireFox";
        }
    };
}

From source file:net.continuumsecurity.web.drivers.DriverFactory.java

License:Open Source License

public WebDriver createFirefoxDriver(DesiredCapabilities capabilities) {

    if (capabilities != null) {
        return new FirefoxDriver(capabilities);
    }/*  ww  w. j  a  v a 2s .c  o m*/

    ProfilesIni allProfiles = new ProfilesIni();
    FirefoxProfile myProfile = allProfiles.getProfile("WebDriver");
    if (myProfile == null) {
        File ffDir = new File(System.getProperty("user.dir") + File.separator + "ffProfile");
        if (!ffDir.exists()) {
            ffDir.mkdir();
        }
        myProfile = new FirefoxProfile(ffDir);
    }
    myProfile.setAcceptUntrustedCertificates(true);
    myProfile.setAssumeUntrustedCertificateIssuer(true);
    myProfile.setPreference("webdriver.load.strategy", "unstable");
    if (capabilities == null) {
        capabilities = new DesiredCapabilities();
    }
    capabilities.setCapability(FirefoxDriver.PROFILE, myProfile);
    return new FirefoxDriver(capabilities);

}

From source file:org.cerberus.engine.execution.impl.SeleniumServerService.java

License:Open Source License

/**
 * Instanciate DesiredCapabilities regarding the browser
 * @param capabilities//from   w w w.j  a va 2 s . co m
 * @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.setAcceptUntrustedCertificates(true);
            profile.setAssumeUntrustedCertificateIssuer(true);
            profile.setPreference("app.update.enabled", false);
            profile.setEnableNativeEvents(true);
            try {
                Invariant invariant = this.invariantService.findInvariantByIdValue("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");
            }

            capabilities.setCapability("acceptInsecureCerts", true);
            capabilities.setCapability("acceptSslCerts", true);
            //capabilities.setCapability("marionette", true);
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
        } else if (browser.equalsIgnoreCase("IE")) {
            capabilities = DesiredCapabilities.internetExplorer();
        } else if (browser.equalsIgnoreCase("chrome")) {
            capabilities = DesiredCapabilities.chrome();
        } 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("opera")) {
            capabilities = DesiredCapabilities.opera();
        } 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;
}

From source file:org.cerberus.service.engine.impl.SeleniumServerService.java

License:Open Source License

private DesiredCapabilities setFirefoxProfile(TestCaseExecution tCExecution) throws CerberusException {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(true);
    profile.setAcceptUntrustedCertificates(true);
    profile.setPreference("network.http.connection-timeout", "300");

    try {/*from  w  w w.j a v  a  2  s.com*/
        Invariant invariant = this.invariantService.findInvariantByIdValue("COUNTRY", tCExecution.getCountry());
        if (invariant.getGp2() == null) {
            MyLogger.log(Selenium.class.getName(), Level.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) {
        MyLogger.log(Selenium.class.getName(), Level.WARN, "Country selected (" + tCExecution.getCountry()
                + ") not in Invariant table, default language set to English(en)");
        profile.setPreference("intl.accept_languages", "en");
    }

    if (tCExecution.getVerbose() > 0) {
        String firebugPath = parameterService
                .findParameterByKey("cerberus_selenium_firefoxextension_firebug", "").getValue();
        String netexportPath = parameterService
                .findParameterByKey("cerberus_selenium_firefoxextension_netexport", "").getValue();
        if (StringUtil.isNullOrEmpty(firebugPath)) {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%",
                    "Mandatory parameter for network traffic 'cerberus_selenium_firefoxextension_firebug' not defined."));
            throw new CerberusException(mes);
        }
        if (StringUtil.isNullOrEmpty(netexportPath)) {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%",
                    "Mandatory parameter for network traffic 'cerberus_selenium_firefoxextension_netexport' not defined."));
            throw new CerberusException(mes);
        }

        File firebug = new File(firebugPath);
        if (!firebug.canRead()) {
            MyLogger.log(Selenium.class.getName(), Level.WARN, "Can't read : " + firebugPath);
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : '" + firebugPath
                    + "' Change the Cerberus parameter : cerberus_selenium_firefoxextension_firebug"));
            throw new CerberusException(mes);

        }
        try {
            MyLogger.log(SeleniumServerService.class.getName(), Level.DEBUG,
                    "Adding firebug extension : " + firebugPath);
            profile.addExtension(firebug);
        } catch (IOException exception) {
            MyLogger.log(Selenium.class.getName(), Level.WARN, exception.toString());
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + firebugPath));
            throw new CerberusException(mes);
        }

        File netExport = new File(netexportPath);
        if (!netExport.canRead()) {
            MyLogger.log(Selenium.class.getName(), Level.WARN, "Can't read : " + netexportPath);
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + netexportPath
                    + "' Change the Cerberus parameter : cerberus_selenium_firefoxextension_netexport"));
            throw new CerberusException(mes);
        }
        try {
            MyLogger.log(SeleniumServerService.class.getName(), Level.DEBUG,
                    "Adding netexport extension : " + netexportPath);
            profile.addExtension(netExport);
        } catch (IOException exception) {
            MyLogger.log(Selenium.class.getName(), Level.WARN, exception.toString());
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + netexportPath));
            throw new CerberusException(mes);
        }

        String cerberusUrl = parameterService.findParameterByKey("cerberus_url", "").getValue();
        if (StringUtil.isNullOrEmpty(cerberusUrl)) {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%",
                    "Mandatory parameter for network traffic 'cerberus_url' not defined."));
            throw new CerberusException(mes);
        }

        // Set default Firefox preferences
        profile.setPreference("app.update.enabled", false);

        // Set default Firebug preferences
        profile.setPreference("extensions.firebug.currentVersion", "1.11.4");
        profile.setPreference("extensions.firebug.allPagesActivation", "on");
        profile.setPreference("extensions.firebug.defaultPanelName", "net");
        profile.setPreference("extensions.firebug.net.enableSites", true);

        // Set default NetExport preferences
        profile.setPreference("extensions.firebug.netexport.alwaysEnableAutoExport", true);
        // Export to Server.
        String url = cerberusUrl + "/SaveStatistic?logId=" + tCExecution.getExecutionUUID();
        profile.setPreference("extensions.firebug.netexport.autoExportToServer", true);
        profile.setPreference("extensions.firebug.netexport.beaconServerURL", url);
        MyLogger.log(SeleniumServerService.class.getName(), Level.DEBUG,
                "Selenium netexport.beaconServerURL : " + url);
        profile.setPreference("extensions.firebug.netexport.sendToConfirmation", false);
        profile.setPreference("extensions.firebug.netexport.showPreview", false);

    }

    //if userAgent
    if (!("").equals(tCExecution.getUserAgent())) {
        profile.setPreference("general.useragent.override", tCExecution.getUserAgent());
    }

    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability(FirefoxDriver.PROFILE, profile);

    return dc;
}

From source file:org.cerberus.serviceEngine.impl.SeleniumService.java

License:Open Source License

private DesiredCapabilities setFirefoxProfile(String executionUUID, boolean record, String country)
        throws CerberusException {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(true);
    profile.setAcceptUntrustedCertificates(true);
    profile.setPreference("network.http.connection-timeout", "300");

    try {// w  ww.j a  v a 2s . co m
        Invariant invariant = this.invariantService.findInvariantByIdValue("COUNTRY", country);
        if (invariant.getGp2() == null) {
            MyLogger.log(Selenium.class.getName(), Level.WARN, "Country selected (" + country
                    + ") 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) {
        MyLogger.log(Selenium.class.getName(), Level.WARN, "Country selected (" + country
                + ") not in Invariant table, default language set to English(en)");
        profile.setPreference("intl.accept_languages", "en");
    }

    if (record) {
        String firebugPath = parameterService
                .findParameterByKey("cerberus_selenium_firefoxextension_firebug", "").getValue();
        String netexportPath = parameterService
                .findParameterByKey("cerberus_selenium_firefoxextension_netexport", "").getValue();
        if (StringUtil.isNullOrEmpty(firebugPath)) {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%",
                    "Mandatory parameter for network traffic 'cerberus_selenium_firefoxextension_firebug' not defined."));
            throw new CerberusException(mes);
        }
        if (StringUtil.isNullOrEmpty(netexportPath)) {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%",
                    "Mandatory parameter for network traffic 'cerberus_selenium_firefoxextension_netexport' not defined."));
            throw new CerberusException(mes);
        }

        File firebug = new File(firebugPath);
        if (!firebug.canRead()) {
            MyLogger.log(Selenium.class.getName(), Level.WARN, "Can't read : " + firebugPath);
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : '" + firebugPath
                    + "' Change the Cerberus parameter : cerberus_selenium_firefoxextension_firebug"));
            throw new CerberusException(mes);

        }
        try {
            MyLogger.log(SeleniumService.class.getName(), Level.DEBUG,
                    "Adding firebug extension : " + firebugPath);
            profile.addExtension(firebug);
        } catch (IOException exception) {
            MyLogger.log(Selenium.class.getName(), Level.WARN, exception.toString());
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + firebugPath));
            throw new CerberusException(mes);
        }

        File netExport = new File(netexportPath);
        if (!netExport.canRead()) {
            MyLogger.log(Selenium.class.getName(), Level.WARN, "Can't read : " + netexportPath);
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + netexportPath
                    + "' Change the Cerberus parameter : cerberus_selenium_firefoxextension_netexport"));
            throw new CerberusException(mes);
        }
        try {
            MyLogger.log(SeleniumService.class.getName(), Level.DEBUG,
                    "Adding netexport extension : " + netexportPath);
            profile.addExtension(netExport);
        } catch (IOException exception) {
            MyLogger.log(Selenium.class.getName(), Level.WARN, exception.toString());
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%", "File not found : " + netexportPath));
            throw new CerberusException(mes);
        }

        String cerberusUrl = parameterService.findParameterByKey("cerberus_url", "").getValue();
        if (StringUtil.isNullOrEmpty(cerberusUrl)) {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replaceAll("%MES%",
                    "Mandatory parameter for network traffic 'cerberus_url' not defined."));
            throw new CerberusException(mes);
        }

        // Set default Firefox preferences
        profile.setPreference("app.update.enabled", false);

        // Set default Firebug preferences
        profile.setPreference("extensions.firebug.currentVersion", "1.11.4");
        profile.setPreference("extensions.firebug.allPagesActivation", "on");
        profile.setPreference("extensions.firebug.defaultPanelName", "net");
        profile.setPreference("extensions.firebug.net.enableSites", true);

        // Set default NetExport preferences
        profile.setPreference("extensions.firebug.netexport.alwaysEnableAutoExport", true);
        // Export to Server.
        String url = cerberusUrl + "/SaveStatistic?logId=" + executionUUID;
        profile.setPreference("extensions.firebug.netexport.autoExportToServer", true);
        profile.setPreference("extensions.firebug.netexport.beaconServerURL", url);
        MyLogger.log(SeleniumService.class.getName(), Level.DEBUG,
                "Selenium netexport.beaconServerURL : " + url);
        // Export to File. This only works on the selenium server side so should not be used as we don't know where to put the file and neither if Linux or Windows based.
        //            String cerberusHarPath = "logHar" + myFile.separator;
        //            String cerberusHarPath = "logHar" ;
        //            File dir = new File(cerberusHarPath + runId);
        //            dir.mkdirs();
        //            profile.setPreference("extensions.firebug.netexport.autoExportToFile", true);
        //            profile.setPreference("extensions.firebug.netexport.defaultLogDir", cerberusHarPath );
        //            MyLogger.log(SeleniumService.class.getName(), Level.DEBUG, "Selenium netexport.defaultLogDir : " + cerberusHarPath);
        profile.setPreference("extensions.firebug.netexport.sendToConfirmation", false);
        profile.setPreference("extensions.firebug.netexport.showPreview", false);

    }

    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability(FirefoxDriver.PROFILE, profile);

    return dc;
}