org.openqa.selenium.firefox.FirefoxProfile Java Examples

The following examples show how to use org.openqa.selenium.firefox.FirefoxProfile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FirefoxCustomProfile.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 7 votes vote down vote up
public static void main(String... args) throws IOException {

        System.setProperty("webdriver.gecko.driver",
                "./src/test/resources/drivers/geckodriver 2");

        FirefoxProfile profile = new FirefoxProfile();
        profile.addExtension(
                new File("./src/test/resources/extensions/xpath_finder.xpi"));

        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);

        FirefoxDriver driver = new FirefoxDriver(firefoxOptions);

        try {
            driver.get("http://www.google.com");
        } finally {
            driver.quit();
        }

    }
 
Example #2
Source File: ScenarioLoaderImpl.java    From Asqatasun with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
     * 
     * @param firefoxProfile
     * @return an initialised instance of TestRunFactory
     */
    private TestRunFactory initTestRunFactory (FirefoxProfile firefoxProfile){
        TgTestRunFactory testRunFactory = new TgTestRunFactory();
        testRunFactory.addNewPageListener(this);
        testRunFactory.setFirefoxProfile(firefoxProfile);
        testRunFactory.setJsScriptMap(jsScriptMap);
        if (implicitelyWaitDriverTimeout != -1) {
            testRunFactory.setImplicitlyWaitDriverTimeout(implicitelyWaitDriverTimeout);
        }
        testRunFactory.setPageLoadDriverTimeout(pageLoadDriverTimeout);
        
        testRunFactory.setScreenHeight(
                Integer.valueOf(
                        parameterDataService.getParameter(
                                webResource.getAudit(), ParameterElement.SCREEN_HEIGHT_KEY).getValue()));
        testRunFactory.setScreenWidth(
                Integer.valueOf(
                        parameterDataService.getParameter(
                                webResource.getAudit(), ParameterElement.SCREEN_WIDTH_KEY).getValue()));
//      ((TgTestRunFactory)testRunFactory).setFirefoxDriverObjectPool(firefoxDriverObjectPool);
        return testRunFactory;
    }
 
Example #3
Source File: LocalDriverFactory.java    From hsac-fitnesse-fixtures with Apache License 2.0 6 votes vote down vote up
/**
 * Set firefox profile. For example to make sure text/csv file is downloaded without asking (convenient if run on buildserver), do:
 * |script           |selenium driver setup                                                                                               |
 * |start driver for |firefox              |with profile|!{browser.download.folderList:2,browser.helperApps.neverAsk.saveToDisk:text/csv}||
 * @param profile setting from subtable
 * @return firefox profile with specified settings
 */
public static FirefoxProfile getFirefoxProfile(Map<String, Object> profile) {
    FirefoxProfile fxProfile = new FirefoxProfile();
    if (profile != null) {
        for (Map.Entry<String, Object> profileEntry : profile.entrySet()) {
            String key = profileEntry.getKey();
            Object value = profileEntry.getValue();
            if (value instanceof Boolean) {
                fxProfile.setPreference(key, (Boolean) value);
            } else if (value instanceof Integer) {
                fxProfile.setPreference(key, (Integer) value);
            } else if (value == null) {
                fxProfile.setPreference(key, null);
            } else {
                fxProfile.setPreference(key, value.toString());
            }
        }
    }
    return fxProfile;
}
 
Example #4
Source File: JiraIssueCreation.java    From rice with Educational Community License v2.0 6 votes vote down vote up
private void login() throws InterruptedException {DesiredCapabilities capabilities = new DesiredCapabilities();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(false);
    capabilities.setCapability(FirefoxDriver.PROFILE, profile);

    driver = new FirefoxDriver(capabilities);
    driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS);
    driver.get(jiraBase + "/secure/Dashboard.jspa");

    WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.className("login-link"),
            this.getClass().toString()).click();

    // CAS
    WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.id("username"),
            this.getClass().toString());
    driver.findElement(By.id("username")).sendKeys(System.getProperty("cas.username"));
    driver.findElement(By.id("password")).sendKeys(System.getProperty("cas.password"));
    driver.findElement(By.name("submit")).click();
}
 
Example #5
Source File: SeleniumDriver.java    From jsflight with Apache License 2.0 6 votes vote down vote up
private FirefoxProfile createDefaultFirefoxProfile()
{
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.setPreference("nglayout.initialpaint.delay", "0");
    firefoxProfile.setPreference("network.http.pipelining", true);
    firefoxProfile.setPreference("image.animation_mode", "none");
    firefoxProfile.setPreference("layers.acceleration.force-enabled", true);
    firefoxProfile.setPreference("layers.offmainthreadcomposition.enabled", true);
    firefoxProfile.setPreference("browser.sessionstore.interval", 3600000);
    firefoxProfile.setPreference("privacy.trackingprotection.enabled", true);
    firefoxProfile.setPreference("content.notify.interval", 849999);
    firefoxProfile.setPreference("content.notify.backoffcount", 5);
    firefoxProfile.setPreference("network.http.max-connections", 50);
    firefoxProfile.setPreference("network.http.max-connections-per-server", 150);
    firefoxProfile.setPreference("network.http.pipelining.aggressive", false);
    firefoxProfile.setPreference("browser.tabs.animate", false);
    firefoxProfile.setPreference("browser.display.show_image_placeholders", false);
    firefoxProfile.setPreference("browser.cache.use_new_backend", 1);
    firefoxProfile.setPreference("ui.submenuDelay", 0);
    firefoxProfile.setPreference("browser.cache.disk.enable", false);
    firefoxProfile.setPreference("browser.cache.memory.enable", true);
    firefoxProfile.setPreference("browser.cache.memory.capacity", 128000);
    return firefoxProfile;
}
 
Example #6
Source File: XpiDriverService.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Override
protected XpiDriverService createDriverService(
    File exe,
    int port,
    Duration timeout,
    List<String> args,
    Map<String, String> environment) {
  try {
    return new XpiDriverService(
        exe,
        port,
        timeout,
        args,
        environment,
        binary == null ? new FirefoxBinary() : binary,
        profile == null ? new FirefoxProfile() : profile,
        getLogFile());
  } catch (IOException e) {
    throw new WebDriverException(e);
  }
}
 
Example #7
Source File: XpiDriverServiceTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void builderPassesTimeoutToDriverService() {
  File exe = new File("someFile");
  Duration defaultTimeout = Duration.ofSeconds(45);
  Duration customTimeout = Duration.ofSeconds(60);

  FirefoxProfile mockProfile = mock(FirefoxProfile.class);
  FirefoxBinary mockBinary = mock(FirefoxBinary.class);
  XpiDriverService.Builder builderMock = spy(XpiDriverService.Builder.class);
  builderMock.withProfile(mockProfile);
  builderMock.withBinary(mockBinary);
  doReturn(exe).when(builderMock).findDefaultExecutable();
  builderMock.build();

  verify(builderMock).createDriverService(any(), anyInt(), eq(defaultTimeout), any(), any());

  builderMock.withTimeout(customTimeout);
  builderMock.build();
  verify(builderMock).createDriverService(any(), anyInt(), eq(customTimeout), any(), any());
}
 
Example #8
Source File: FirefoxInterface.java    From candybean with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void start() throws CandybeanException {
	String profileName = candybean.config.getValue("browser.firefox.profile", "default");
	File ffBinaryPath = new File(candybean.config.getPathValue("browser.firefox.binary"));
	if(!ffBinaryPath.exists()){
		String error = "Unable to find firefox browser driver from the specified location in the configuration file! \n"
				+ "Please add a configuration to the candybean config file for key \"browser.firefox.binary\" that"
				+ "indicates the location of the binary.";
		logger.severe(error);
		throw new CandybeanException(error);
	} else {
		FirefoxProfile ffProfile = (new ProfilesIni()).getProfile(profileName);
		FirefoxBinary ffBinary = new FirefoxBinary(ffBinaryPath);
		logger.info("Instantiating Firefox with profile name: "
				+ profileName + " and binary path: " + ffBinaryPath);
		super.wd = new FirefoxDriver(ffBinary, ffProfile);
		super.start(); // requires wd to be instantiated first
	}
}
 
Example #9
Source File: FireFoxProxyViaProfile.java    From at.info-knowledge-base with MIT License 6 votes vote down vote up
@BeforeMethod
public void setUpProxy() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.http", proxyIp);
    profile.setPreference("network.proxy.http_port", port);

    capabilities.setCapability(FirefoxDriver.PROFILE, profile);

    driver = new FirefoxDriver(capabilities);
    //or
    //driver = new FirefoxDriver(profile);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
 
Example #10
Source File: RemoteDesiredCapabilitiesFactory.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
public static DesiredCapabilities build(RemoteCapability capability){
 DesiredCapabilities desiredCapabilities;
 if(RemoteCapability.CHROME.equals(capability)){
  ChromeOptions options = new ChromeOptions();
     desiredCapabilities = DesiredCapabilities.chrome();
     desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
  return desiredCapabilities;
 } else if (RemoteCapability.FIREFOX.equals(capability)){
  FirefoxProfile profile = new FirefoxProfile();
  desiredCapabilities = DesiredCapabilities.firefox();
  desiredCapabilities.setCapability(FirefoxDriver.PROFILE, profile);
  return desiredCapabilities;
 } else if (RemoteCapability.INTERNET_EXPLORER.equals(capability)){
  desiredCapabilities = DesiredCapabilities.internetExplorer();
  return desiredCapabilities;
 } else if (RemoteCapability.PHANTOMJS.equals(capability)){
  desiredCapabilities = DesiredCapabilities.phantomjs();
  return desiredCapabilities;
 }
 throw new IllegalArgumentException("No such capability");
}
 
Example #11
Source File: FirefoxDriverConfig.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
private void setPreferences(FirefoxProfile profile) {
    JMeterProperty property = getProperty(PREFERENCES);
    if (property instanceof NullProperty) {
        return;
    }
    CollectionProperty rows = (CollectionProperty) property;
    for (int i = 0; i < rows.size(); i++) {
        ArrayList row = (ArrayList) rows.get(i).getObjectValue();
        String name = ((JMeterProperty) row.get(0)).getStringValue();
        String value = ((JMeterProperty) row.get(1)).getStringValue();
        switch (value) {
            case "true":
                profile.setPreference(name, true);
                break;
            case "false":
                profile.setPreference(name, false);
                break;
            default:
                profile.setPreference(name, value);
                break;
        }
    }
}
 
Example #12
Source File: FirefoxDriverConfig.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
FirefoxProfile createProfile() {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("app.update.enabled", false);
    
    String userAgentOverride = getUserAgentOverride();
    if (StringUtils.isNotEmpty(userAgentOverride)) {
        profile.setPreference("general.useragent.override", userAgentOverride);
    }
    
    String ntlmOverride = getNtlmSetting();
    if (StringUtils.isNotEmpty(ntlmOverride)) {
        profile.setPreference("network.negotiate-auth.allow-insecure-ntlm-v1", true);
    }

    addExtensions(profile);
    setPreferences(profile);

    return profile;
}
 
Example #13
Source File: FirefoxFrozenPreferences.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 6 votes vote down vote up
public static void main(String... args) {

        System.setProperty("webdriver.gecko.driver",
                "./src/test/resources/drivers/geckodriver 2");

        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.shell.checkDefaultBrowser", true);
        profile.setAssumeUntrustedCertificateIssuer(false);
        profile.setAcceptUntrustedCertificates(false);

        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);

        FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
        driver.get("http://facebook.com");
    }
 
Example #14
Source File: ProfileFactory.java    From Asqatasun with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
     * 
     * @return 
     *      a set-up Firefox profile
     */
    private FirefoxProfile getProfile(boolean loadImage) {
        if (StringUtils.isNotBlank(pathToPreSetProfile)) {
            File presetProfileDir = new File(pathToPreSetProfile);
            if (presetProfileDir.exists() 
                  && presetProfileDir.canRead() 
                  && presetProfileDir.canExecute()
                  && presetProfileDir.canWrite()) {
                Logger.getLogger(this.getClass()).debug(
                        "Start firefox profile with path " 
                        + presetProfileDir.getAbsolutePath());
                return new FirefoxProfile(presetProfileDir);
            } else {
                Logger.getLogger(this.getClass()).debug(
                        "The profile with path " 
                        + presetProfileDir.getAbsolutePath()
                        + " doesn't exist or don't have permissions");
            }
        }
        Logger.getLogger(this.getClass()).debug("Start firefox with fresh new profile");
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        setUpPreferences(firefoxProfile, loadImage);
//        setUpExtensions(firefoxProfile);
        setUpProxy(firefoxProfile);
        return firefoxProfile;
    }
 
Example #15
Source File: WebDriverUtils.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * <p>
 * remote.public.driver set to chrome or firefox (null assumes firefox).
 * </p><p>
 * if remote.public.hub is set a RemoteWebDriver is created (Selenium Grid)
 * if proxy.host is set, the web driver is setup to use a proxy
 * </p>
 *
 * @return WebDriver or null if unable to create
 */
public static WebDriver getWebDriver() {
    String driverParam = System.getProperty(HUB_DRIVER_PROPERTY);
    String hubParam = System.getProperty(HUB_PROPERTY);
    String proxyParam = System.getProperty(PROXY_HOST_PROPERTY);

    // setup proxy if specified as VM Arg
    DesiredCapabilities capabilities = new DesiredCapabilities();
    WebDriver webDriver = null;
    if (StringUtils.isNotEmpty(proxyParam)) {
        capabilities.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(proxyParam));
    }

    if (hubParam == null) {
        if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
            FirefoxProfile profile = new FirefoxProfile();
            profile.setEnableNativeEvents(false);
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            return new FirefoxDriver(capabilities);
        } else if ("chrome".equalsIgnoreCase(driverParam)) {
            return new ChromeDriver(capabilities);
        } else if ("safari".equals(driverParam)) {
            System.out.println("SafariDriver probably won't work, if it does please contact Erik M.");
            return new SafariDriver(capabilities);
        }
    } else {
        try {
            if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.firefox());
            } else if ("chrome".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.chrome());
            }
        } catch (MalformedURLException mue) {
            System.out.println(getHubUrlString() + " " + mue.getMessage());
            mue.printStackTrace();
        }
    }
    return null;
}
 
Example #16
Source File: HttpWebClient.java    From nutch-selenium with Apache License 2.0 5 votes vote down vote up
@Override
protected WebDriver initialValue()
{
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("permissions.default.stylesheet", 2);
    profile.setPreference("permissions.default.image", 2);
    profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false");
    WebDriver driver = new FirefoxDriver(profile);
    return driver;
}
 
Example #17
Source File: SeleniumDriverSetup.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
public boolean connectToFirefoxDriverAtWithProfile(String url, Map<String, Object> profile)
        throws MalformedURLException {
    FirefoxProfile fxProfile = getFirefoxProfile(profile);
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setCapability("browserName", "firefox");
    desiredCapabilities.setCapability(FirefoxDriver.PROFILE, fxProfile);
    return createAndSetRemoteDriver(url, desiredCapabilities);
}
 
Example #18
Source File: SeleniumWrapper.java    From SeleniumBestPracticesBook with Apache License 2.0 5 votes vote down vote up
public SeleniumWrapper(String browser) {
  if (browser.equals("firefox")) {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.http", "127.0.0.1");
    profile.setPreference("network.proxy.http_port", 9999);
    profile
        .setPreference("network.proxy.no_proxies_on",
                       "localhost, 127.0.0.1, *awful-valentine.com");

    selenium = new FirefoxDriver(profile);
  }
}
 
Example #19
Source File: DefaultSessionFactory.java    From JTAF-ExtWebDriver with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param ffp
 *            for use in setting the firefox profile for the tests to use
 *            when running firefox
 */
private static void addPreferences(FirefoxProfile ffp) {
    ffp.setPreference("capability.policy.default.HTMLDocument.readyState", "allAccess");
    ffp.setPreference("capability.policy.default.HTMLDocument.compatMode", "allAccess");
    ffp.setPreference("capability.policy.default.Document.compatMode", "allAccess");
    ffp.setPreference("capability.policy.default.Location.href", "allAccess");
    ffp.setPreference("capability.policy.default.Window.pageXOffset", "allAccess");
    ffp.setPreference("capability.policy.default.Window.pageYOffset", "allAccess");
    ffp.setPreference("capability.policy.default.Window.frameElement", "allAccess");
    ffp.setPreference("capability.policy.default.Window.frameElement.get", "allAccess");
    ffp.setPreference("capability.policy.default.Window.QueryInterface", "allAccess");
    ffp.setPreference("capability.policy.default.Window.mozInnerScreenY", "allAccess");
    ffp.setPreference("capability.policy.default.Window.mozInnerScreenX", "allAccess");
}
 
Example #20
Source File: MBeanFieldGroupRequiredErrorMessageTest.java    From viritin with Apache License 2.0 5 votes vote down vote up
public MBeanFieldGroupRequiredErrorMessageTest(String language, String expectedMessage) {
    this.expectedMessage = expectedMessage;
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("intl.accept_languages", language);
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setProfile(profile);
    WebDriver webDriver = new FirefoxDriver(firefoxOptions);
    startBrowser(webDriver);
}
 
Example #21
Source File: DefaultSessionFactory.java    From JTAF-ExtWebDriver with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param ffp
 *            the firefox profile you are using
 * @param propertiesFile
 *            the properties you want to add to the profile
 */
private static void addPreferences(FirefoxProfile ffp, String propertiesFile) {
    Properties firefoxProfile = new Properties();

    try(FileInputStream fis = new FileInputStream(propertiesFile)) {
        firefoxProfile.load(fis);
    } catch (Throwable th) {
        throw new RuntimeException("Could not load firefox profile", th);
    }

    for (Object o : firefoxProfile.keySet()) {
        String key = (String) o;
        String getVal = null;
        if (key.endsWith(".type")) {
            getVal = key.substring(0, key.lastIndexOf("."));
        }

        if (getVal != null) {
            String type = firefoxProfile.getProperty(key);
            String value = firefoxProfile.getProperty(getVal + ".value");

            if (value.contains("${PROJECT_PATH}")) {
                String projectPath = (new File("")).getAbsolutePath();
                value = projectPath + value.replaceAll("\\$\\{PROJECT_PATH\\}", "");
            }

            if (type.equalsIgnoreCase("BOOLEAN")) {
                ffp.setPreference(getVal, Boolean.parseBoolean(value));
            } else if (type.equalsIgnoreCase("STRING")) {
                ffp.setPreference(getVal, value);
            } else if (type.equalsIgnoreCase("INTEGER") || type.equalsIgnoreCase("INT")) {
                ffp.setPreference(getVal, Integer.parseInt(value));
            }
        }
    }
}
 
Example #22
Source File: AbstractCapabilities.java    From carina with Apache License 2.0 5 votes vote down vote up
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.CHROME_EXPERIMENTAL_OPTS).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);
        }
    }

    return caps;
}
 
Example #23
Source File: FirefoxCapabilities.java    From carina with Apache License 2.0 5 votes vote down vote up
/**
 * Generate DesiredCapabilities for Firefox with custom FirefoxProfile.
 *
 * @param testName
 *            - String.
 * @param profile
 *            - FirefoxProfile.
 * @return Firefox desired capabilities.
 */
public DesiredCapabilities getCapability(String testName, FirefoxProfile profile) {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities = initBaseCapabilities(capabilities, BrowserType.FIREFOX, testName);
    capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, false);
    
    FirefoxOptions options = new FirefoxOptions().setProfile(profile);
    capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
    
    LOGGER.debug("Firefox caps: " + capabilities);
    return capabilities;
}
 
Example #24
Source File: XpiDriverService.java    From selenium with Apache License 2.0 5 votes vote down vote up
private XpiDriverService(
    File executable,
    int port,
    Duration timeout,
    List<String> args,
    Map<String, String> environment,
    FirefoxBinary binary,
    FirefoxProfile profile,
    File logFile)
    throws IOException {
  super(executable, port, timeout, args, environment);

  this.port = Require.positive("Port", port);
  this.binary = binary;
  this.profile = profile;

  String firefoxLogFile = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE);
  if (firefoxLogFile != null) { // System property has higher precedence
    if ("/dev/stdout".equals(firefoxLogFile)) {
      sendOutputTo(System.out);
    } else if ("/dev/stderr".equals(firefoxLogFile)) {
      sendOutputTo(System.err);
    } else if ("/dev/null".equals(firefoxLogFile)) {
      sendOutputTo(ByteStreams.nullOutputStream());
    } else {
      sendOutputTo(new FileOutputStream(firefoxLogFile));
    }
  } else {
    if (logFile != null) {
      // TODO: This stream is leaked.
      sendOutputTo(new FileOutputStream(logFile));
    } else {
      sendOutputTo(ByteStreams.nullOutputStream());
    }
  }
}
 
Example #25
Source File: VaadinLocaleTest.java    From viritin with Apache License 2.0 5 votes vote down vote up
public VaadinLocaleTest(String language, String expectedLanuage) {
    this.expectedLanguage = expectedLanuage;
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("intl.accept_languages", language);
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setProfile(profile);
    WebDriver webDriver = new FirefoxDriver(firefoxOptions);
    startBrowser(webDriver);
}
 
Example #26
Source File: TestBrowserFactory.java    From webtester-core with Apache License 2.0 5 votes vote down vote up
@Override
public Browser createBrowser() {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setAcceptUntrustedCertificates(true);
    profile.setEnableNativeEvents(false);
    return createBrowser(new FirefoxDriver(profile));
}
 
Example #27
Source File: ProfileFactory.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @return 
 */
private String createRandomNetExportPath(FirefoxProfile firefoxProfile) {
    StringBuilder strb = new StringBuilder(netExportPath);
    strb.append(new Random().nextLong());
    netExportPathMap.put(firefoxProfile, strb.toString());
    return strb.toString();
}
 
Example #28
Source File: ProfileFactory.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setUpProxy(FirefoxProfile firefoxProfile) {
    if (!StringUtils.isEmpty(proxyPort) && !StringUtils.isEmpty(proxyHost)) {
        StringBuilder strb = new StringBuilder(proxyHost);
        strb.append(":");
        strb.append(proxyPort);
        Proxy proxy = new Proxy();
        proxy.setFtpProxy(strb.toString());
        proxy.setHttpProxy(strb.toString());
        proxy.setSslProxy(strb.toString());
        if (StringUtils.isNotEmpty(proxyExclusionUrl)) {
            proxy.setNoProxy(proxyExclusionUrl.replaceAll(";", ","));
        }
        firefoxProfile.setProxyPreferences(proxy);
    }
}
 
Example #29
Source File: ProfileFactory.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param firefoxProfile 
 */
private void setUpPreferences(FirefoxProfile firefoxProfile, boolean loadImage) {

    // to have a blank page on start-up
    firefoxProfile.setPreference("browser.startup.page", 0);
    firefoxProfile.setPreference("browser.cache.disk.capacity", 0);
    firefoxProfile.setPreference("browser.cache.disk.enable", false);
    firefoxProfile.setPreference("browser.cache.disk.smart_size.enabled", false);
    firefoxProfile.setPreference("browser.cache.disk.smart_size.first_run", false);
    firefoxProfile.setPreference("browser.cache.disk.smart_size_cached_value", 0);
    firefoxProfile.setPreference("browser.cache.memory.enable", false);
    firefoxProfile.setPreference("browser.shell.checkDefaultBrowser", false);
    firefoxProfile.setPreference("browser.startup.homepage_override.mstone", "ignore");
    firefoxProfile.setPreference("browser.preferences.advanced.selectedTabIndex", 0);
    firefoxProfile.setPreference("browser.privatebrowsing.autostart", false);
    firefoxProfile.setPreference("browser.link.open_newwindow", 2);
    firefoxProfile.setPreference("Network.cookie.cookieBehavior", 1);
    firefoxProfile.setPreference("signon.autologin.proxy", true);


    // to disable the update of search engines
    firefoxProfile.setPreference("browser.search.update", false);
    
    if (loadImage) {
        // To enable the load of images
        firefoxProfile.setPreference("permissions.default.image", 1);
    }else {
        // To disable the load of images
        firefoxProfile.setPreference("permissions.default.image", 2);
    }
}
 
Example #30
Source File: ProfileFactory.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param firefoxProfile 
 */
public void shutdownFirefoxProfile(FirefoxProfile firefoxProfile) {
    try {
        if (deleteProfileData) {
            FileDeleteStrategy.FORCE.delete(new File(netExportPathMap.get(firefoxProfile)));
        }
    } catch (IOException ex) {
        Logger.getLogger(this.getClass()).error(ex);
    }
    netExportPathMap.remove(firefoxProfile);
}