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:com.raja.anucarita.SeWrapper.java

License:Open Source License

public static WebDriver getDriver() throws Exception {
    if (Browser.equals("Firefox")) {
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("capability.policy.default.Window.QueryInterface", "allAccess");
        profile.setPreference("capability.policy.default.Window.frameElement.get", "allAccess");
        driver = new FirefoxDriver(profile);
    } else if (Browser.equals("IE")) {
        driver = new InternetExplorerDriver();
    } else if (Browser.equals("GoogleChrome")) {
        System.setProperty("webdriver.chrome.driver", values.getProperty("GoogleChromeLocation"));
        driver = new ChromeDriver();
    } else {//from ww w. j av a 2 s. c o  m
        throw new Exception("Browser String is wrong");
    }
    return driver;
}

From source file:com.sat.dbds.utils.selenium.SeleniumUtilities.java

License:Open Source License

/**
 * Opens the Firefox instance for Selenium.
 *///from  w w  w.j av a 2s . co m
public static void openBrowser() {
    if (System.getProperty("run.type") == null || System.getProperty("run.type").equalsIgnoreCase("WUI")) {
        if (getDriver() != null)
            System.out.println(getDriver().toString() + "hi");
        if (getDriver() == null || (!getDriver().toString().contains("-"))) {
            try {

                String browser = Validate.readsystemvariable("browser");
                LogHandler.info("Browser:" + browser);

                String digest = Validate.readsystemvariable("browser.digest");
                LogHandler.info("Digest Auth:" + digest);

                if (browser.equals("firefox") && digest.toUpperCase().equals("YES")) {
                    LogHandler.info("Fire Fox Driver with addon configuration");
                    FirefoxProfile profile = new FirefoxProfile();
                    profile.setPreference("browser.link.open_newwindow", 2);
                    File extentions = new File(System.getProperty("user.dir")
                            + Validate.readsystemvariable("firefox.addons.path"));
                    if (extentions.exists()) {
                        for (File extention : extentions.listFiles()) {
                            if (extention.getName().endsWith(".xpi")) {
                                try {
                                    profile.addExtension(new File(extention.getAbsolutePath()));
                                } catch (IOException e) {
                                    Assert.assertTrue(
                                            "Exception occured while adding the extension to the profile..",
                                            false);
                                }
                                LogHandler.info("Added extention: " + extention.getName());
                            }
                        }
                    }
                    driver = new FirefoxDriver(profile);
                } else if (browser.equals("firefox") && digest.toUpperCase().equals("NO")) {
                    LogHandler.info("Fire Fox Driver without addon configuration");
                    driver = new FirefoxDriver();
                } else if (browser.equals("chrome"))

                {
                    LogHandler.info("Chrome Driver configuration");
                    JarFile jarFile = jarfilehandler.jarForClass(SeleniumUtilities.class);
                    jarfilehandler.copyResourcesToDirectory(jarFile, "chrome", "src/it/resources/chrome");
                    System.setProperty("webdriver.chrome.driver", "src/it/resources/chrome/chromedriver.exe");
                    driver = new ChromeDriver();

                } else if (browser.equals("IE")) {

                    LogHandler.info("IE Driver configuration");
                    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
                    String IEpath = (SeleniumUtilities.class).getResource("").getPath();
                    System.out.println(IEpath.substring(0, IEpath.length() - 31));

                    capabilities.setCapability(
                            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
                    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

                    JarFile jarFile = jarfilehandler.jarForClass(SeleniumUtilities.class);
                    // JarFile jarFile = new
                    // JarFile("C:\\Users\\amsathishkumar\\.m2\\repository\\com\\cisco\\dbds\\Utils\\0.0.1-Release\\Utils-0.0.1-Release.jar");
                    jarfilehandler.copyResourcesToDirectory(jarFile, "internetexplorer",
                            "src/it/resources/InternetExplorer");

                    System.setProperty("webdriver.ie.driver",
                            "src/it/resources/internetexplorer/IEDriverServer.exe");
                    driver = new InternetExplorerDriver(capabilities);

                    // driver = new InternetExplorerDriver();
                } else {
                    Assert.assertTrue("include the browswer variable...", false);
                }
            } catch (Exception e) {
                LogHandler.info("Check the varaiables: browser,firefox.addons.path,user.dir");

            }
            //   driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS);
            //   driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(Integer.parseInt(System.getProperty("implicit.wait")),
                    TimeUnit.SECONDS);
            driver.manage().timeouts().pageLoadTimeout(Integer.parseInt(System.getProperty("explicit.wait")),
                    TimeUnit.SECONDS);
            System.out.println(getDriver().toString() + "hi");
        }
    }
}

From source file:com.sat.spvgt.utils.selenium.SeleniumUtilities.java

License:Open Source License

/**
 * Opens the Firefox instance for Selenium.
 *//*ww  w.  j  a va2 s .c  o  m*/
public static void openBrowser() {
    if (System.getProperty("run.type") == null) {
        try {
            if (getDriver() == null || (!getDriver().toString().contains("-"))) {
                String browser = miscValidate.readsystemvariable("browser");
                LogHandler.info("Browser:" + browser);

                String digest = miscValidate.readsystemvariable("browser.digest");
                LogHandler.info("Digest Auth:" + digest);

                if (browser.equals("firefox") && digest.toUpperCase().equals("YES")) {
                    LogHandler.info("Fire Fox Driver with addon configuration");
                    FirefoxProfile profile = new FirefoxProfile();
                    profile.setPreference("browser.link.open_newwindow", 2);
                    File extentions = new File(System.getProperty("user.dir")
                            + miscValidate.readsystemvariable("firefox.addons.path"));
                    if (extentions.exists()) {
                        for (File extention : extentions.listFiles()) {
                            if (extention.getName().endsWith(".xpi")) {
                                try {
                                    profile.addExtension(new File(extention.getAbsolutePath()));
                                } catch (IOException e) {
                                    Assert.assertTrue(
                                            "Exception occured while adding the extension to the profile..",
                                            false);
                                }
                                LogHandler.info("Added extention: " + extention.getName());
                            }
                        }
                    }
                    driver = new FirefoxDriver(profile);
                } else if (browser.equals("firefox") && digest.toUpperCase().equals("NO")) {
                    LogHandler.info("Fire Fox Driver without addon configuration");
                    driver = new FirefoxDriver();
                } else if (browser.equals("chrome"))

                {
                    LogHandler.info("Chrome Driver configuration");
                    JarFile jarFile = miscJarfileHandler.jarForClass(SeleniumUtilities.class);
                    miscJarfileHandler.copyResourcesToDirectory(jarFile, "chrome", "src/it/resources/chrome");
                    System.setProperty("webdriver.chrome.driver", "src/it/resources/chrome/chromedriver.exe");
                    driver = new ChromeDriver();

                } else if (browser.equals("IE")) {

                    LogHandler.info("IE Driver configuration");
                    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
                    String IEpath = (SeleniumUtilities.class).getResource("").getPath();
                    System.out.println(IEpath.substring(0, IEpath.length() - 31));

                    capabilities.setCapability(
                            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
                    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

                    JarFile jarFile = miscJarfileHandler.jarForClass(SeleniumUtilities.class);
                    // JarFile jarFile = new
                    // JarFile("C:\\Users\\amsathishkumar\\.m2\\repository\\com\\cisco\\dbds\\Utils\\0.0.1-Release\\Utils-0.0.1-Release.jar");
                    miscJarfileHandler.copyResourcesToDirectory(jarFile, "internetexplorer",
                            "src/it/resources/InternetExplorer");

                    System.setProperty("webdriver.ie.driver",
                            "src/it/resources/internetexplorer/IEDriverServer.exe");
                    driver = new InternetExplorerDriver(capabilities);

                    // driver = new InternetExplorerDriver();
                } else {
                    Assert.assertTrue("include the browswer variable...", false);
                }
            }
        } catch (Exception e) {
            LogHandler.info("Check the varaiables: browser,firefox.addons.path,user.dir");

        }
        // driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS);
        // driver.manage().timeouts().setScriptTimeout(10,
        // TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(Integer.parseInt(System.getProperty("implicit.wait")),
                TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(Integer.parseInt(System.getProperty("explicit.wait")),
                TimeUnit.SECONDS);
    }
}

From source file:com.saucelabs.sauce_ondemand.driver.SauceOnDemandSPIImpl.java

License:Open Source License

private void setFirefoxProfile(Map<String, List<String>> paramMap, DesiredCapabilities desiredCapabilities) {
    FirefoxProfile profile = new FirefoxProfile();
    populateProfilePreferences(profile, paramMap);
    desiredCapabilities.setCapability("firefox_profile", profile);
}

From source file:com.sios.stc.coseng.util.Run.java

License:Open Source License

public synchronized WebDriver getWebDriver(final String testName) throws MalformedURLException {

    WebDriver driver = null;/*from w  ww.j a v  a 2s.c  o m*/

    if (testName != null) {

        for (final TestParam p : param.testParam) {
            if (p.getTestName().equals(testName)) {

                // DesiredCapabilities
                // https://code.google.com/p/selenium/wiki/DesiredCapabilities

                // !! It is *not* necessary to start *any* of the browser driver
                // profiles to start 'private/icognito' as each new driver
                // instance starts with a *fresh* profile that does not persist
                // after the driver is quit. !!

                if (p.getBrowser().equals(Browser.FIREFOX)) {
                    final FirefoxProfile profile = new FirefoxProfile();
                    final DesiredCapabilities dc = DesiredCapabilities.firefox();
                    if (p.getPlatform().equals(Platform.LINUX)) {
                        // Explicitly enable native events(this is mandatory on Linux system,
                        // since they are not enabled by default.
                        profile.setEnableNativeEvents(true);
                        dc.setPlatform(p.getPlatform());
                        dc.setCapability(Common.BROWSER_CAPABILITY_FIREFOX_PROFILE, profile);
                    }
                    if (p.getSpot().equals(Spot.LOCAL)) {
                        driver = new FirefoxDriver(profile);
                    } else {
                        driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc);
                    }
                } else if (p.getBrowser().equals(Browser.CHROME)) {
                    final DesiredCapabilities dc = DesiredCapabilities.chrome();
                    dc.setPlatform(p.getPlatform());
                    if (p.getSpot().equals(Spot.LOCAL)) {
                        driver = new ChromeDriver();
                    } else {
                        driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc);
                    }
                } else if (p.getBrowser().toString().toLowerCase().startsWith("ie")) {
                    final DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
                    dc.setBrowserName(Common.BROWSER_NAME_INTERNET_EXPLORER);
                    dc.setPlatform(p.getPlatform());
                    // IE8 and newer; Make sure
                    // HKEY_USERS\.Default\Software\Microsoft\Internet
                    // Explorer has DWORD TabProcGrowth set 0
                    // Launch separate process in 'private' mode.
                    dc.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
                    dc.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
                    //dc.setCapability(InternetExplorerDriver.LOG_FILE,
                    //        "C:/iedriver.log");
                    //dc.setCapability(InternetExplorerDriver.LOG_LEVEL,
                    //        "DEBUG");
                    dc.setCapability(InternetExplorerDriver.NATIVE_EVENTS, true);
                    // dc.setCapability(
                    // InternetExplorerDriver.REQUIRE_WINDOW_FOCUS,
                    // true);

                    // If *is* a specific IE9, IE10, IE11 (not IE) set the version
                    if (!p.getBrowser().equals(Browser.IE)) {
                        dc.setVersion(p.getBrowser().getVersion());
                    }

                    if (p.getSpot().equals(Spot.LOCAL)) {
                        driver = new InternetExplorerDriver();
                    } else {
                        driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc);
                    }
                }
            }
            // Collect the driver for quit after tests complete
            if (driver != null) {
                collectDriver(driver);
            }
        }
    }
    return driver;
}

From source file:com.sonar.it.jenkins.orchestrator.JenkinsOrchestrator.java

License:Open Source License

public void start() {
    if (started.getAndSet(true)) {
        throw new IllegalStateException("Jenkins is already started");
    }//from  w w w.  j a v  a  2  s. c o m

    int port = config.getInt("jenkins.container.port", 0);
    if (port <= 0) {
        port = NetworkUtils.getNextAvailablePort();
    }
    distribution.setPort(port);
    FileSystem fileSystem = config.fileSystem();
    ServerInstaller serverInstaller = new ServerInstaller(fileSystem);
    server = serverInstaller.install(distribution);
    server.setUrl(String.format("http://localhost:%d", port));

    jenkinsWrapper = new JenkinsWrapper(server, config, fileSystem.javaHome(), port);
    jenkinsWrapper.start();

    FirefoxProfile profile = new FirefoxProfile();
    // Disable native events on all OS to avoid strange characters when using sendKeys
    profile.setEnableNativeEvents(false);
    driver = new FirefoxDriver(profile);

    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.get(server.getUrl());

    // Fix window size for having reproducible test behavior
    driver.manage().window().setPosition(new Point(20, 20));
    driver.manage().window().setSize(new Dimension(1024, 768));
    try {
        cli = new CLI(new URL(server.getUrl()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.thoughtworks.selenium.SeleneseTestBaseVir.java

License:Apache License

/**
 * Config web driver.//w w  w . j  ava 2 s .co  m
 * 
 * @param browserName
 *            the browser string
 */
public final void configWebDriver(final String browserName) {
    if (browserName.contains("chrome") || browserName.contains("Chrome")) {

        setBrowserString(browserString);
        File chromedriver = getChromeDriverServerExecutables();
        System.setProperty("webdriver.chrome.driver", chromedriver.getAbsolutePath());
        setWebDriverCapabilities(new DesiredCapabilities());
    } else if (browserName.contains("safari")) {

        setBrowserString(browserString);
        setWebDriverCapabilities(new DesiredCapabilities());
    } else if (browserName.contains("iexplore")) {

        setBrowserString(browserString);
        setWebDriverCapabilities(new DesiredCapabilities());
        File iedriver;
        if (isx64bit()) {
            iedriver = new File("src" + File.separator + "main" + File.separator + "resources" + File.separator
                    + "lib" + File.separator + "IEDriverServer(x64).exe");
        } else {
            iedriver = new File("src" + File.separator + "main" + File.separator + "resources" + File.separator
                    + "lib" + File.separator + "IEDriverServer(x86).exe");
        }
        System.setProperty("webdriver.ie.driver", iedriver.getAbsolutePath());

    } else if (browserName.contains("firefox")) {

        setBrowserString(browserString);
        setWebDriverCapabilities(new DesiredCapabilities());
        setDefaultProfile(new FirefoxProfile());
    } else if (browserName.contains("opera")) {

        setBrowserString(browserString);
        setWebDriverCapabilities(new DesiredCapabilities());
    } else {
        throw new AssertionError("Unsupported Browser");
    }
}

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 {//w w  w  . j  a  v a 2s.c  om
        LOGGER.debug("Returning {} driver from pool", drivers.peek().getWindowHandle());
        return drivers.poll();
    }
}

From source file:com.worldline.easycukes.selenium.WebDriverFactory.java

License:Open Source License

/**
 * Allows to customize and configure the options of a Firefox session
 *
 * @return DesiredCapabilities//from   w w w  . j  a  va 2s.c o  m
 */
private static DesiredCapabilities firefoxCapabilities() {
    final FirefoxProfile profile = new FirefoxProfile();
    // FirefoxProfile profile = new ProfilesIni().getProfile("default");
    final DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(FirefoxDriver.PROFILE, profile);
    return capabilities;
}

From source file:com.yufei.dataget.dataretriver.HttpDataRetriverUsingFirefoxDriver.java

@Override
public void connect() {
    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");
    //profile.setPreference("DISPLAY", ":10");
    FirefoxBinary fb = new FirefoxBinary();
    fb.setEnvironmentProperty("DISPLAY", ":10");
    // sudo Xvfb :10 -ac 
    driver = new FirefoxDriver(fb, profile);
    driver.get(this.url.toString());

}