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(File profileDir) 

Source Link

Document

Constructs a firefox profile from an existing profile directory.

Usage

From source file:org.jboss.arquillian.drone.webdriver.factory.FirefoxDriverFactory.java

License:Apache License

@Override
public FirefoxDriver createInstance(TypedWebDriverConfiguration<FirefoxDriverConfiguration> configuration) {

    String binary = configuration.getFirefoxBinary();
    String profile = configuration.getFirefoxProfile();

    DesiredCapabilities capabilities = new DesiredCapabilities(configuration.getCapabilities());

    // set binary and profile values
    if (Validate.nonEmpty(binary)) {
        Validate.isExecutable(binary, "Firefox binary does not point to a valid executable,  " + binary);
        log.log(Level.FINE, "Setting firefox binary to {0}", binary);
        capabilities.setCapability(FirefoxDriver.BINARY, binary);
    }/* w  ww.jav  a 2  s  .c  o m*/
    if (Validate.nonEmpty(profile)) {
        Validate.isValidPath(profile, "Firefox profile does not point to a valid path " + profile);
        log.log(Level.FINE, "Setting firefox profile to path {0}", profile);
        capabilities.setCapability(FirefoxDriver.PROFILE, new FirefoxProfile(new File(profile)));
    }

    return SecurityActions.newInstance(configuration.getImplementationClass(),
            new Class<?>[] { Capabilities.class }, new Object[] { capabilities }, FirefoxDriver.class);

}

From source file:org.openqa.grid.selenium.SelfRegisteringSelenium.java

License:Apache License

@Override
public void addFirefoxSupport(File profileDir) {
    DesiredCapabilities ff = new DesiredCapabilities();
    ff.setBrowserName("*firefox");
    if (profileDir != null && profileDir.exists()) {
        firefoxProfileDir = profileDir;/*from w  w w.  j  av  a 2s.co m*/
        ff.setCapability(FirefoxDriver.PROFILE, new FirefoxProfile(profileDir));
        ff.setCapability("profilePath", profileDir.getPath());
    }
    getCaps().add(ff);
}

From source file:org.openqa.grid.selenium.SelfRegisteringWebDriver.java

License:Apache License

@Override
public void addFirefoxSupport(File profile) {
    DesiredCapabilities ff = DesiredCapabilities.firefox();
    if (profile != null) {
        ff.setCapability(FirefoxDriver.PROFILE, new FirefoxProfile(profile));
    }//from w ww. j  a v  a 2 s  . co  m
    getCaps().add(ff);
}

From source file:org.safs.selenium.webdriver.lib.SelectBrowser.java

License:Open Source License

/**
 * Create a FirefoxProfile according to a profile's name of profile's filename.
 * @param profileNameOrPath String, Can be profile's name or profile's file name (absolute)
 * @return FirefoxProfile, can be null/*from  w w  w  .  j  a va 2  s .c om*/
 */
public static FirefoxProfile getFirefoxProfile(String profileNameOrPath) {
    String debugmsg = StringUtils.debugmsg(false);
    FirefoxProfile profile = null;

    IndependantLog.debug(debugmsg + " Get firefox profile by '" + profileNameOrPath + "'.");
    try {
        File profileFile = new File(profileNameOrPath);
        if (profileFile.exists()) {
            profile = new FirefoxProfile(profileFile);
        }
    } catch (Exception ignore) {
    }

    if (profile == null) {
        ProfilesIni allProfiles = new ProfilesIni();
        profile = allProfiles.getProfile(profileNameOrPath);
    }

    if (profile == null)
        IndependantLog.error(debugmsg + " Fail to get firefox profile.");

    return profile;
}

From source file:org.securitytests.cisecurity.drivers.DriverFactory.java

License:Open Source License

public WebDriver createFirefoxDriver(DesiredCapabilities capabilities) {
    if (capabilities != null) {
        return new FirefoxDriver(capabilities);
    }//from  www . java  2 s  .  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.suren.autotest.web.framework.selenium.CapabilityConfig.java

License:Apache License

/**
 * ???/*from w w w.  j a  v a 2s .c om*/
 */
public void config() {
    firefox();

    chrome();

    ie();

    {
        String proFile = System.getProperty("firefox.profile", null);
        FirefoxProfile profile = new FirefoxProfile(proFile != null ? new File(proFile) : null);
        fireFoxPreSet(profile);
    }

    {
        DesiredCapabilities capability = DesiredCapabilities.safari();
        engineCapMap.put(DRIVER_SAFARI, capability);
    }

    {
        DesiredCapabilities capability = DesiredCapabilities.operaBlink();
        engineCapMap.put(DRIVER_OPERA, capability);
    }

    {
        DesiredCapabilities capability = DesiredCapabilities.phantomjs();
        engineCapMap.put(DRIVER_PHANTOM_JS, capability);
    }
}

From source file:org.testeditor.fixture.web.CapabilityIntegrationtest.java

License:Open Source License

private void readCapabilitiesFromProfile(WebDriverFixture fixture) {
    WebDriver driver = fixture.getDriver();
    Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
    String profilePath = (String) cap.getCapability("moz:profile");
    logger.debug("Firefox Preferences read successfully");
    FirefoxProfile profile = new FirefoxProfile(new File(profilePath));
    proxyHttp = profile.getStringPreference("network.proxy.http", "");
    logger.debug("Firefox Preference proxy HTTP = {} read successfully", proxyHttp);
    proxyHttpPort = profile.getIntegerPreference("network.proxy.http_port", 0);
    logger.debug("Firefox Preference proxy HTTP port = {} read successfully", proxyHttpPort);
    proxySsl = profile.getStringPreference("network.proxy.ssl", "");
    logger.debug("Firefox Preference proxy SSL = {}  read successfully", proxySsl);
    proxySslPort = profile.getIntegerPreference("network.proxy.ssl_port", 0);
    logger.debug("Firefox Preference proxy SSL port = {}  read successfully", proxySslPort);
    proxyType = profile.getIntegerPreference("network.proxy.type", 0);
    logger.debug("Firefox Preference proxy type = {}  read successfully", proxyType);
    logger.debug(" ######## End of Test readCapabilitiesFromProfile ########");
}

From source file:sf.wicklet.ext.test.arquillian.Test01.java

License:Apache License

@Test
public void test01(@ArquillianResource final URL httpContext) throws Exception {
    final StepWatch timer = new StepWatch(true);
    final FirefoxProfile profile = new FirefoxProfile(new File("../opt/firefox/7x16slsr.default"));
    profile.setPreference("network.dns.disableIPv6", true);
    final FirefoxDriver driver = new FirefoxDriver(profile);
    try {//  w w  w  .  java2s .  c o m
        if (Test01.DEBUG.isDebug()) {
            System.out.println(timer.toString("# Client start"));
        }
        driver.get(new URL(httpContext, TestAccordion01Page.MNT_PATH).toString());
        final String title = driver.getTitle();
        if (Test01.DEBUG.isDebug()) {
            System.out.println(timer.toString("Page title is: " + title));
            System.out.println(driver.getPageSource());
        }
        Assert.assertEquals("Test", driver.getTitle());
        final List<WebElement> p1 = driver.findElementsByLinkText("Panel1");
        final List<WebElement> p2 = driver.findElementsByLinkText("Panel2");
        final List<WebElement> p3 = driver.findElementsByLinkText("Panel3");
        final List<WebElement> c1 = driver.findElementsById("content1");
        final List<WebElement> c2 = driver.findElementsById("content2");
        final List<WebElement> c3 = driver.findElementsById("content3");
        Assert.assertEquals(1, p1.size());
        Assert.assertEquals(1, p2.size());
        Assert.assertEquals(1, p3.size());
        Assert.assertEquals(1, c1.size());
        Assert.assertEquals(1, c2.size());
        Assert.assertEquals(1, c3.size());
        Assert.assertEquals("", c2.get(0).getAttribute("style"));
        //
        p2.get(0).click();
        if (Test01.DEBUG.isDebug()) {
            System.out.println(driver.getPageSource());
        }
        final List<WebElement> cc1 = driver.findElementsById("content1");
        final List<WebElement> cc2 = driver.findElementsById("content2");
        final List<WebElement> cc3 = driver.findElementsById("content3");
        Assert.assertEquals(1, cc1.size());
        Assert.assertEquals(1, cc2.size());
        Assert.assertEquals(1, cc3.size());
        Assert.assertEquals("display: none;", cc2.get(0).getAttribute("style"));
        //
        p2.get(0).click();
        if (Test01.DEBUG.isDebug()) {
            System.out.println(driver.getPageSource());
        }
        final List<WebElement> ccc2 = driver.findElementsById("content2");
        Assert.assertEquals(1, ccc2.size());
        Assert.assertEquals("display: block;", ccc2.get(0).getAttribute("style"));
    } finally {
        if (Test01.DEBUG.isDebug()) {
            final String text = driver.getPageSource();
            FileUtil.writeFile(Test01.test01Html, false, text);
            SeleniumTestUtil.takeScreenshot(driver, Test01.test01Png);
            System.out.println(timer.toString("# Client done"));
        }
        if (Test01.DEBUG.isDebugServer()) {
            System.in.read();
        } else {
            driver.quit();
        }
    }
}

From source file:sf.wicklet.gwt.client.test.Test01.java

License:Apache License

@Test
public void testHome01() throws IOException {
    final StepWatch timer = new StepWatch(true);
    final FirefoxProfile profile = new FirefoxProfile(firefoxProfileDir);
    profile.setPreference("network.dns.disableIPv6", true);
    // final FirefoxDriver driver = new FirefoxDriver(new FirefoxBinary(firefoxBinary), profile);
    final FirefoxDriver driver = new FirefoxDriver(profile);
    try {//from w  w  w  . j ava 2  s.  com
        if (DEBUG.isDebug()) {
            System.out.println(timer.toString("# Client start"));
        }
        driver.get(BASEURL);
        final String title = driver.getTitle();
        if (DEBUG.isDebug()) {
            System.out.println(timer.toString("Page title is: " + title));
        }
        assertEquals("HomePage", title);
        if (DEBUG.isDebug()) {
            final String text = driver.getPageSource();
            System.out.println(text);
            FileUtil.writeFile(testHome01Html, false, text);
            takeScreenshot(driver, testHome01Png);
        }
        toppanel(driver);
        logindialog(driver);
        menubar(driver);
        stackpanel(driver);
        ajaxpanel(driver);
    } catch (final Throwable e) {
        e.printStackTrace();
        throw e;
    } finally {
        if (DEBUG.isDebug()) {
            System.out.println(timer.toString("# Client done"));
        }
        if (DEBUG.isDebugServer()) {
            System.in.read();
        } else {
            driver.quit();
        }
    }
}

From source file:sf.wicklet.gwt.site.test.firefox.TestEditUser01.java

License:Apache License

@Test
public void testEditUser01() throws LifecycleException, IOException {
    final StepWatch timer = new StepWatch(true);
    final FirefoxProfile profile = new FirefoxProfile(firefoxProfileDir);
    profile.setPreference("network.dns.disableIPv6", true);
    final FirefoxDriver driver = new FirefoxDriver(profile);
    // driver.manage().timeouts().implicitlyWait(1000, TimeUnit.MILLISECONDS);
    try {//from w  w w  . ja  v a2s .c  o  m
        // Check that acess to admin page redirect to https connection.
        debugprint(timer, "# Client start");
        driver.get(BASEURL + "p/admin");
        debugprint(timer.toString("# Client start"));
        assertEquals("Login", driver.getTitle());
        login(driver, USER_ADMIN, PASS_ADMIN);
        assertEquals("Admin", driver.getTitle());
        final String url = driver.getCurrentUrl();
        debugprint("# URL=" + url);
        assertTrue(url.startsWith("https"));
        // Test edit roles
        finder(driver).wait(By.cssSelector("table.zebraTable"), 1) //
                .finder(0).find(By.linkText("edit"), 4).click(0);
        final WebElement dialog = finder(driver).find(By.cssSelector(".gwt-DialogBox"), 1).get(0);
        finder(dialog).find(By.name("username"), 1);
        final WebElement roleselm = finder(dialog).find(By.name("roles"), 1).get(0);
        final String roles = roleselm.getAttribute("value");
        debugprint("# unedited roles=" + roles);
        assertFalse(roles, roles.indexOf("editor") >= 0);
        enterText(roleselm, roles + ",editor");
        finder(dialog).find(By.tagName("button"), 2).filterText("^OK$").click(0);
        TestUtil.assertWithinTimeout(new IPredicate() {
            @SuppressWarnings("synthetic-access")
            @Override
            public boolean ok() {
                final String editedroles = finder(driver)
                        .wait(By.cssSelector("table.zebraTable tr:first-child+tr td"), 3).get(1).getText();
                debugprint("# edited roles: " + editedroles);
                return editedroles.indexOf("editor") >= 0;
            }
        });
        // Test the delete link
        finder(driver).find(By.cssSelector("table.zebraTable tr")).count(5) //
                .find(By.cssSelector("table.zebraTable"), 1) //
                .finder(0).find(By.linkText("delete"), 4).click(3);
        finder(driver).wait(By.cssSelector(".gwt-DialogBox"), 1) //
                .finder(0).find(By.tagName("button"), 2).filterText("^OK$").click(0);
        finder(driver).wait(By.cssSelector("table.zebraTable tr"), 4);
    } finally {
        if (DEBUG.isDebug()) {
            final String text = driver.getPageSource();
            System.out.println(text);
            FileUtil.writeFile(htmlfile("TestEditUser01"), false, text);
            System.out.println(timer.toString("# Client done"));
        }
        if (DEBUG.isDebugServer()) {
            System.in.read();
        } else {
            driver.quit();
        }
    }
}