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

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

Introduction

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

Prototype

public FirefoxProfile() 

Source Link

Usage

From source file:io.wcm.qa.galenium.webdriver.WebDriverManager.java

License:Apache License

private DesiredCapabilities getDesiredCapabilities(TestDevice newTestDevice) {
    DesiredCapabilities capabilities;//  w w w .ja  va 2  s .co m

    GaleniumReportUtil.getLogger().info("Getting capabilities for " + newTestDevice.getBrowserType());
    switch (newTestDevice.getBrowserType()) {
    case CHROME:
        capabilities = DesiredCapabilities.chrome();
        String chromeEmulator = newTestDevice.getChromeEmulator();
        if (chromeEmulator != null) {
            Map<String, String> mobileEmulation = new HashMap<String, String>();
            mobileEmulation.put("deviceName", chromeEmulator);
            Map<String, Object> chromeOptions = new HashMap<String, Object>();
            chromeOptions.put("mobileEmulation", mobileEmulation);
            capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
        }

        break;

    case IE:
        capabilities = DesiredCapabilities.internetExplorer();
        break;

    case SAFARI:
        capabilities = DesiredCapabilities.safari();
        break;

    case PHANTOMJS:
        capabilities = DesiredCapabilities.phantomjs();
        capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
                new String[] { "--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--web-security=false",
                        "--webdriver-loglevel=OFF", "--webdriver-loglevel=NONE" });
        break;

    default:
    case FIREFOX:
        capabilities = DesiredCapabilities.firefox();
        if (firefoxProfile == null) {
            firefoxProfile = new FirefoxProfile();
            // Workaround for click events spuriously failing in Firefox (https://code.google.com/p/selenium/issues/detail?id=6112)
            firefoxProfile.setEnableNativeEvents(false);
            firefoxProfile.setAcceptUntrustedCertificates(true);
            firefoxProfile.setAssumeUntrustedCertificateIssuer(false);
        }
        capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        break;
    }

    // Request browser logging capabilities for capturing console.log output
    LoggingPreferences loggingPrefs = new LoggingPreferences();
    loggingPrefs.enable(LogType.BROWSER, Level.INFO);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPrefs);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    GaleniumReportUtil.getLogger().info("Done generating capabilities");
    return capabilities;
}

From source file:jhc.redsniff.webdriver.SeleniumTesterFactory.java

License:Apache License

private static FirefoxProfile getDefaultFirefoxProfile() {
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    return firefoxProfile;
}

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

License:Apache License

/**
 * FireFox????/*www. jav  a 2s .c  o 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:lenguajes.project.GUI.java

/**
 * Creates new form GUI//from   w w w. j av a2s . c o m
 */
public GUI() {
    initComponents();
    output.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
    output.setCodeFoldingEnabled(true);
    input.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
    input.setCodeFoldingEnabled(true);
    setKeyBindings();
    if (cond) {
        System.setProperty("webdriver.gecko.driver", Config.WEB_DRIVER_PATH);
        //Create object of FirefoxProfile in built class to access Its properties.
        FirefoxProfile fprofile = new FirefoxProfile();
        //Set Location to store files after downloading.
        fprofile.setPreference("browser.download.dir", property + Config.DOWNLOAD_DIR);
        fprofile.setPreference("browser.download.folderList", 2);
        //Set Preference to not show file download confirmation dialogue using MIME types Of different file extension types.
        fprofile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;"//MIME types Of MS Excel File.
                        + "application/pdf;" //MIME types Of PDF File.
                        + "application/vnd.openxmlformats-officedocument.wordprocessingml.document;" //MIME types Of MS doc File.
                        + "text/plain;" //MIME types Of text File.
                        + "image/png;" //MIME types Of png Files.
                        + "text/csv"); //MIME types Of CSV File.
        fprofile.setPreference("browser.download.manager.showWhenStarting", false);
        fprofile.setPreference("pdfjs.disabled", true);
        //Pass fprofile parameter In webdriver to use preferences to download file.
        driver = new FirefoxDriver(fprofile);

        driver = new FirefoxDriver(fprofile);
        baseUrl = "http://localhost:7474";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get(baseUrl + "/browser/");
        WebDriverWait wait = new WebDriverWait(driver, 10);
        WebElement element = wait
                .until(ExpectedConditions.visibilityOfElementLocated(By.id("connect_password")));
        element.clear();
        element.sendKeys(Config.NEO4J_PASSWORD);
        driver.findElement(By.id("connect_button")).click();
    }
    drawComponents();
}

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

License:Open Source License

public BurpFirefoxDriver() {
    log.debug("Constructing BurpFirefoxDriver");
    //DesiredCapabilities capabilities = new DesiredCapabilities();
    //capabilities.setCapability(CapabilityType.PROXY, getBurpProxy());
    FirefoxProfile ffProfile = new FirefoxProfile();
    ffProfile.setPreference("permissions.default.image", 2);
    ffProfile.setProxyPreferences(getBurpProxy());
    ffDriver = new FirefoxDriver(ffProfile);
}

From source file:nz.co.testamation.core.WebIntegrationTestAutoConfiguration.java

License:Apache License

@Bean
@Autowired/*  w ww  .  j  a  va  2 s.  co m*/
public WebDriver webDriver(@Value("${web.driver:firefox}") String webDriver,
        @Value("${web.driver.autoDownload.mimeTypes:application/pdf}") String autoDownloadMimeTypes,
        @Qualifier("webDriverDownloadDir") File downloadDir) {

    if ("htmlunit".equals(webDriver)) {
        return new HtmlUnitDriver();
    }

    if ("chrome".equals(webDriver)) {
        return new ChromeDriver();
    }

    if ("firefox".equals(webDriver)) {
        FirefoxBinary firefoxBinary = new FirefoxBinary();
        if (System.getenv("DISPLAY") == null) {
            firefoxBinary.setEnvironmentProperty("DISPLAY", ":99");
        }

        FirefoxProfile profile = new FirefoxProfile();

        profile.setPreference("browser.download.folderList", 2); // Download to: 0 desktop, 1 default download location, 2 custom folder
        profile.setPreference("browser.download.dir", downloadDir.getAbsolutePath());
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", autoDownloadMimeTypes);
        profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf");
        profile.setPreference("pdfjs.disabled", true);

        return new FirefoxDriver(firefoxBinary, profile);
    }

    if ("ie".equals(webDriver)) {
        return new InternetExplorerDriver();
    }

    if ("safari".equals(webDriver)) {
        return new SafariDriver();
    }

    if ("opera".equals(webDriver)) {
        return new OperaDriver();
    }

    throw new IllegalArgumentException(format("Web driver %s not supported.", webDriver));
}

From source file:org.ado.picasa.Main.java

License:Apache License

public static void main(String[] args) throws Exception {
    final Options options = new Options();
    options.addOption(new Option("a", "album", true, "Album name"));
    options.addOption("v", "verification-code", true, "Verification code");
    options.addOption("o", "output", true, "Albums output directory");
    options.addOption("h", "help", false, "Prints this help");
    final CommandLine cmd = new DefaultParser().parse(options, args);

    if (cmd.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("picasa-crawler", options);
        System.exit(0);/*from w  w  w. j  a v  a  2  s . c  o m*/
    }

    validateEnvironmentVariables();
    final File outputDirectory;
    if (cmd.hasOption("o")) {
        outputDirectory = new File(cmd.getOptionValue("o"));
    } else {
        outputDirectory = DEFAULT_OUTPUT_DIR;
    }
    FileUtils.forceMkdir(outputDirectory);
    long start = System.currentTimeMillis();

    final FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("browser.download.folderList", 2);
    profile.setPreference("browser.download.dir", outputDirectory.getAbsolutePath());
    profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "image/jpeg,image/png");
    final FirefoxDriver driver = new FirefoxDriver(profile);
    loginIntoPicasa(cmd.getOptionValue("v"), driver);

    driver.navigate().to("https://picasaweb.google.com/home?showall=true");
    TimeUnit.SECONDS.sleep(2);

    final List<WebElement> albumLinks = driver
            .findElements(By.xpath("//p[@class='gphoto-album-cover-title']/a"));

    if (cmd.hasOption("a")) {
        final String albumName = cmd.getOptionValue("a").trim();
        System.out.println(String.format("Album: %s", albumName));
        downloadAlbum(driver, albumLinks.stream().filter(al -> al.getText().equals(albumName)).findFirst().get()
                .getAttribute("href"), outputDirectory);

    } else {

        final Set<String> albumHrefs = albumLinks.stream().map(a -> a.getAttribute("href"))
                .collect(Collectors.toSet());

        albumHrefs.forEach(a -> downloadAlbum(driver, a, outputDirectory));

    }
    TimeUnit.SECONDS.sleep(10);
    System.out.println("done");
    long end = System.currentTimeMillis();
    System.out.println(String.format("execution took %d minutes.",
            Math.min(TimeUnit.MILLISECONDS.toMinutes(end - start), 1)));
    driver.close();
}

From source file:org.alfresco.grid.WebDriverFactory.java

License:Open Source License

/**
 * Create a basic fire fox profile./*from  w  ww  . j  a v a  2s .c o  m*/
 * @return {@link FirefoxProfile}
 */
private FirefoxProfile createProfile(String... profile) {
    FirefoxProfile firefoxProfile = null;
    if (profile.length > 0) {
        firefoxProfile = new ProfilesIni().getProfile(profile[0]);
        if (firefoxProfile == null) {
            throw new RuntimeException("The following profile: %s can not be found");
        }
    } else {
        firefoxProfile = new FirefoxProfile();
    }
    //Change default retry timeout of 30 minutes to 2 minutes
    firefoxProfile.setPreference("dom.mms.retrievalRetryIntervals;", "60000,120000");
    //Set it to not store session history, reduced memory foot print.
    firefoxProfile.setPreference("browser.sessionhistory.max_total_viewers;", "0");
    firefoxProfile.setPreference("intl.accept_languages", language);
    firefoxProfile.setPreference("general.useragent.locale", locale);
    return firefoxProfile;
}

From source file:org.apache.falcon.regression.testHelper.BaseUITestClass.java

License:Apache License

protected static void openBrowser() {

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.negotiate-auth.trusted-uris", MerlinConstants.PRISM_URL);

    driver = new FirefoxDriver(profile);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    int width = Config.getInt("browser.window.width", 0);
    int height = Config.getInt("browser.window.height", 0);

    if (width * height == 0) {
        driver.manage().window().maximize();
    } else {//from www  . ja  v  a  2  s . c  o  m
        driver.manage().window().setPosition(new Point(0, 0));
        driver.manage().window().setSize(new Dimension(width, height));
    }

}

From source file:org.apache.nutch.protocol.webdriver.driver.NutchFirefoxDriver.java

License:Apache License

private static FirefoxProfile getProfile(Capabilities cap) {
    FirefoxProfile profile = null;//from w ww  .j a  va2s .c o m
    Object raw = null;
    if (cap != null && cap.getCapability(PROFILE) != null) {
        raw = cap.getCapability(PROFILE);
    }
    if (raw != null) {
        if (raw instanceof FirefoxProfile) {
            profile = (FirefoxProfile) raw;
        } else if (raw instanceof String) {
            try {
                profile = FirefoxProfile.fromJson((String) raw);
            } catch (IOException e) {
                throw new WebDriverException(e);
            }
        }
    }
    if (profile == null) {
        profile = new FirefoxProfile();
    }
    return profile;
}