Example usage for org.openqa.selenium.remote DesiredCapabilities setJavascriptEnabled

List of usage examples for org.openqa.selenium.remote DesiredCapabilities setJavascriptEnabled

Introduction

In this page you can find the example usage for org.openqa.selenium.remote DesiredCapabilities setJavascriptEnabled.

Prototype

public void setJavascriptEnabled(boolean javascriptEnabled) 

Source Link

Usage

From source file:bi.com.seleniumgrid.PhantomJsTest.java

License:Apache License

@Test
public void test() {
    final DesiredCapabilities capabilities = new DesiredCapabilities();
    // Configure our WebDriver to support JavaScript and be able to find the PhantomJS binary
    capabilities.setJavascriptEnabled(true);
    capabilities.setCapability("takesScreenshot", false);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, PHANTOMJS_BINARY);
    final WebDriver driver = new PhantomJSDriver(capabilities);
    // Your test code here. For example:
    WebDriverWait wait = new WebDriverWait(driver, 30); // 30 seconds of timeout
    driver.get("https://en.wikipedia.org/wiki/Main_Page"); // navigate to Wikipedia

    pageTitle = driver.getTitle().trim();
    Assert.assertEquals(pageTitle, "GoalQuest");

    System.out.println("Page title is: " + driver.getTitle());

    By searchInput = By.id("searchInput"); // search for "Software"
    wait.until(ExpectedConditions.presenceOfElementLocated(searchInput));
    driver.findElement(searchInput).sendKeys("Software");
    By searchButton = By.id("searchButton");
    wait.until(ExpectedConditions.elementToBeClickable(searchButton));
    driver.findElement(searchButton).click();

    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"), "Computer software")); // assert that the resulting page contains a text
}

From source file:browsermator.com.RunASingleTest.java

public void RunSingleTest(Procedure bugtorun, ProcedureView thisbugview, String TargetBrowser, String OSType) {

    SiteTest.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    switch (TargetBrowser) {
    // legacy file support
    case "Firefox-Marionette":
        // legacy file support
        if ("Windows".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe");
        }/*  w w w. ja v  a  2 s.c  o m*/
        if ("Windows32".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe");
        }
        if ("Windows64".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win64\\geckodriver.exe");
        }
        if ("Mac".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-osx\\geckodriver");
        }
        if ("Linux-32".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux32\\geckodriver");
        }
        if ("Linux-64".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux64\\geckodriver");
        }

        if (firefox_path != null) {
            System.setProperty("webdriver.firefox.bin", firefox_path);
        }

        try {
            DesiredCapabilities cap = DesiredCapabilities.firefox();
            cap.setJavascriptEnabled(true);
            cap.setCapability("marionette", true);
            driver = new FirefoxDriver(cap);

            //  driver =  new MarionetteDriver();
        } catch (Exception ex) {
            System.out.println("Exception launching Marionette driver... possibly XP or missing msvcr110.dll: "
                    + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Marionette driver, will fallback to HTMLUnitDriver", false);

            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }

        break;

    case "Firefox":
        //legacy support
        if ("Windows".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe");
        }
        if ("Windows32".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe");
        }
        if ("Windows64".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win64\\geckodriver.exe");
        }
        if ("Mac".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-osx\\geckodriver");
        }
        if ("Linux-32".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux32\\geckodriver");
        }
        if ("Linux-64".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux64\\geckodriver");
        }

        if (firefox_path != null) {
            System.setProperty("webdriver.firefox.bin", firefox_path);
        }

        try {
            DesiredCapabilities cap = DesiredCapabilities.firefox();
            cap.setJavascriptEnabled(true);
            cap.setCapability("marionette", true);
            driver = new FirefoxDriver(cap);

            //  driver =  new MarionetteDriver();
        } catch (Exception ex) {
            System.out.println("Exception launching Marionette driver... possibly XP or missing msvcr110.dll: "
                    + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Marionette driver, will fallback to HTMLUnitDriver", false);

            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }

        break;

    case "Silent Mode (HTMLUnit)":
        driver = new HtmlUnitDriver();
        break;

    case "Internet Explorer-32":
        System.setProperty("webdriver.ie.driver", "lib\\iedriverserver_win32\\IEDriverServer.exe");
        try {
            driver = new InternetExplorerDriver();
        } catch (Exception ex) {
            System.out.println("Exception launching Internet Explorer driver: " + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Internet Explorer driver, will fallback to HTMLUnitDriver", false);
            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }
        break;
    case "Internet Explorer-64":
        System.setProperty("webdriver.ie.driver", "lib\\iedriverserver_win64\\IEDriverServer.exe");
        try {
            driver = new InternetExplorerDriver();
        } catch (Exception ex) {
            System.out.println("Exception launching Internet Explorer-64 driver: " + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Internet Explorer 64 driver, will fallback to HTMLUnitDriver",
                    false);
            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }
        break;
    case "Chrome":
        if ("Windows32".equals(OSType)) {
            System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_win32\\chromedriver.exe");
        }
        if ("Windows64".equals(OSType)) {
            System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_win32\\chromedriver.exe");
        }
        if ("Mac".equals(OSType)) {
            System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_mac64\\chromedriver");
        }
        if ("Linux-32".equals(OSType)) {
            System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_linux32\\chromedriver-linux32");
        }
        if ("Linux-64".equals(OSType)) {
            System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_linux64\\chromedriver-linux64");
        }
        try {
            driver = new ChromeDriver();
        } catch (Exception ex) {
            System.out.println("Problem launching Chromedriver: " + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Chrome driver, will fallback to HTMLUnitDriver", false);
            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }
        break;
    case "Chrome (WinXP)":
        if (chrome_path != null) {
            System.setProperty("webdriver.chrome.bin", chrome_path);
        }
        System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_win32\\chromedriver-winxp.exe");

        try {
            driver = new ChromeDriver();
        } catch (Exception ex) {
            System.out.println("Problem launching Chromedriver for XP: " + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Chrome WinXP driver, will fallback to HTMLUnitDriver", false);
            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }
        break;

    default:
        driver = new ChromeDriver();
        break;
    }

    int WaitTime = SiteTest.GetWaitTime();
    // driver.manage().timeouts().implicitlyWait(WaitTime, TimeUnit.SECONDS);
    int totalpause = WaitTime * 1000;

    if (!"Dataloop".equals(thisbugview.Type)) {
        for (Action ThisAction : bugtorun.ActionsList) {

            if (!ThisAction.Locked) {
                try {
                    try {
                        Thread.sleep(totalpause);
                    } catch (Exception ex) {
                        System.out.println("Exception when sleeping: " + ex.toString());
                    }
                    String varfieldname = "";
                    if (ThisAction.Variable2.contains("[stored_varname-start]")) {
                        varfieldname = ThisAction.Variable2;
                        int indexof_end_tag = varfieldname.indexOf("[stored_varname-end]");
                        // assuming name of "[stored_varname-start]" and "[stored_varname-end]"
                        String fieldname = varfieldname.substring(22, indexof_end_tag);
                        ThisAction.Variable2 = SiteTest.GetStoredVariableValue(fieldname);
                        ThisAction.RunAction(driver);
                        ThisAction.Variable2 = "[stored_varname-start]" + fieldname + "[stored_varname-end]";
                    } else {
                        ThisAction.RunAction(driver);
                    }

                    if (!"".equals(ThisAction.tostore_varvalue)) {

                        SiteTest.VarHashMap.put(ThisAction.tostore_varname, ThisAction.tostore_varvalue);
                    }

                } catch (Exception ex) {
                    SiteTest.setCursor(Cursor.getDefaultCursor());
                    driver.close();
                    driver.quit();
                    break;

                }
            } else {
                ThisAction.Pass = true;
            }
        }

    } else {
        int number_of_rows = thisbugview.myTable.DataTable.getRowCount();

        for (int x = 0; x < number_of_rows; x++) {
            for (Action ThisAction : bugtorun.ActionsList) {
                String original_value1 = ThisAction.Variable1;
                String original_value2 = ThisAction.Variable2;
                if (!ThisAction.Locked) {

                    DataLoopVarParser var1Parser = new DataLoopVarParser(ThisAction.Variable1);
                    DataLoopVarParser var2Parser = new DataLoopVarParser(ThisAction.Variable2);
                    if (var1Parser.hasDataLoopVar == false && var2Parser.hasDataLoopVar == false) {
                        if ("Pause with Continue Button".equals(ThisAction.Type)) {
                            String pause_message = "Paused at record " + (x + 1) + " of " + number_of_rows;
                            ThisAction.RunAction(driver, pause_message, this.SiteTest);
                        }
                        try {
                            Thread.sleep(totalpause);
                        } catch (Exception ex) {
                            System.out.println("Exception when sleeping: " + ex.toString());
                        }
                        try {
                            String varfieldname = "";
                            if (ThisAction.Variable2.contains("[stored_varname-start]")) {
                                varfieldname = ThisAction.Variable2;
                                int indexof_end_tag = varfieldname.indexOf("[stored_varname-end]");
                                // assuming name of "[stored_varname-start]" and "[stored_varname-end]"
                                String fieldname = varfieldname.substring(22, indexof_end_tag);
                                ThisAction.Variable2 = SiteTest.GetStoredVariableValue(fieldname);
                                ThisAction.RunAction(driver);
                                ThisAction.Variable2 = "[stored_varname-start]" + fieldname
                                        + "[stored_varname-end]";
                            } else {
                                ThisAction.RunAction(driver);
                            }

                            if (!"".equals(ThisAction.tostore_varvalue)) {

                                SiteTest.VarHashMap.put(ThisAction.tostore_varname,
                                        ThisAction.tostore_varvalue);
                            }

                        } catch (Exception ex) {
                            driver.close();
                            driver.quit();
                            ThisAction.Variable1 = original_value1;
                            ThisAction.Variable2 = original_value2;
                            SiteTest.setCursor(Cursor.getDefaultCursor());
                            break;

                        }

                    } else {

                        String concat_variable;
                        String concat_variable2;
                        concat_variable = var1Parser.GetFullValue(x, thisbugview.myTable);
                        if (var1Parser.hasDataLoopVar) {
                            ThisAction.Variable1 = concat_variable;
                            if ("".equals(ThisAction.Variable1)) {
                                ThisAction.Variable1 = " ";
                            }
                        }

                        concat_variable2 = var2Parser.GetFullValue(x, thisbugview.myTable);
                        if (var2Parser.hasDataLoopVar) {
                            ThisAction.Variable2 = concat_variable2;
                            if ("".equals(ThisAction.Variable2)) {
                                ThisAction.Variable2 = " ";
                            }
                        }
                        try {
                            try {
                                Thread.sleep(totalpause);
                            } catch (Exception ex) {
                                System.out.println("Exception when sleeping: " + ex.toString());
                            }
                            ThisAction.RunAction(driver);
                            ThisAction.Variable1 = original_value1;
                            ThisAction.Variable2 = original_value2;

                        } catch (Exception ex) {

                            ThisAction.Variable1 = original_value1;
                            ThisAction.Variable2 = original_value2;
                            driver.close();
                            driver.quit();
                            SiteTest.setCursor(Cursor.getDefaultCursor());
                            break;

                        }

                    }

                } else {
                    ThisAction.Pass = true;
                }
            }
        }
    }
    driver.close();
    driver.quit();
    ArrayList<ActionView> ActionView = thisbugview.ActionsViewList;

    int ActionIndex = 0;

    for (ActionView TheseActionViews : ActionView) {

        LocalDateTime stringtime = bugtorun.ActionsList.get(ActionIndex).TimeOfTest;
        boolean TestState = bugtorun.ActionsList.get(ActionIndex).Pass;
        if (TestState == true) {
            thisbugview.ActionsViewList.get(ActionIndex).JLabelPassFail.setText("Passed at " + stringtime);

        } else {
            thisbugview.ActionsViewList.get(ActionIndex).JLabelPassFail.setText("Fail at " + stringtime);

        }

        ActionIndex++;

    }

}

From source file:com.btmatthews.selenium.junit4.runner.WrappedDriverFactory.java

License:Apache License

/**
 * Create a Selenium Server object that wraps the {@link WebDriver} that is
 * created using reflection. We are explicitly enabling JavaScript for the
 * {@link HtmlUnitDriver} case./*from www . j  av a 2s  .  c o  m*/
 *
 * @return The new {@link WebDriver} instance.
 */
public Selenium create() {
    return new WebDriverBackedSelenium(new Supplier<WebDriver>() {
        public WebDriver get() {
            if (HtmlUnitDriver.class.isAssignableFrom(webDriverClass)) {
                final DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
                capabilities.setJavascriptEnabled(true);
                return new HtmlUnitDriver(capabilities);
            } else {
                try {
                    return webDriverClass.newInstance();
                } catch (Exception e) {
                    return null;
                }
            }
        }
    }, configuration.browserURL());
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * This method build a webDriver based on the passed in browser request
 *
 * @param browser/*from w w  w  .j a  v  a2  s.  c om*/
 * @return WebDriver
 * @throws MalformedURLException
 */
private static WebDriver buildWebDriver(String browserName) {
    DesiredCapabilities capability = null;
    BrowserType browserType = BrowserType.getBrowserTypeFromString(browserName);
    switch (browserType) {
    case MARIONETTE:
        FirefoxProfile ffProfile = null;
        ffProfile = new FirefoxProfile();
        ffProfile.setAcceptUntrustedCertificates(true);
        ffProfile.setAssumeUntrustedCertificateIssuer(false);
        DesiredCapabilities cap = DesiredCapabilities.firefox();
        cap.setCapability("marionette", true);
        cap.setCapability("firefox_profile", ffProfile);
        cap.setCapability("handlesAlerts", true);
        sysEnv = System.getenv("webdriver.firefox.marionette");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "geckodriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.firefox.marionette in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.firefox.marionette", sysEnv);
            }
        }
        return new MarionetteDriver(capability);
    case FIREFOX_DRIVER:
        capability = DesiredCapabilities.firefox();
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        firefoxProfile.setAcceptUntrustedCertificates(true);
        firefoxProfile.setEnableNativeEvents(true);
        firefoxProfile.setAssumeUntrustedCertificateIssuer(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        return new FirefoxDriver(capability);
    case CHROME_DRIVER:
        sysEnv = System.getenv("webdriver.chrome.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "chromedriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.chrome.driver in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.chrome.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        options.addArguments(new String[] { "--allow-running-insecure-content" });
        options.addArguments(new String[] { "--ignore-certificate-errors" });
        options.addArguments(new String[] { "--enable-npapi" });
        options.addArguments(new String[] { "--disable-extensions" });
        options.addArguments(new String[] { "--start-maximized" });
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability(ChromeOptions.CAPABILITY, options);
        return new ChromeDriver(capability);
    case INTERNET_EXPLORER:
        sysEnv = System.getenv("webdriver.ie.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "IEDriverServer.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.ie.driver in system environment variables and restart the PC");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.ie.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.internetExplorer();
        capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        capability.setCapability("ignoreProtectedModeSettings", true);
        capability.setCapability("acceptSslCerts", true);
        capability.setCapability("ignoreZoomSetting", true);
        capability.setCapability("nativeEvents", true);
        capability.setCapability("ie.ensureCleanSession", true);
        return new InternetExplorerDriver(capability);
    case SAFARI:
        capability = DesiredCapabilities.safari();
        capability.setCapability("acceptSslCerts", true);
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability("ensureCleanSession", true);
        capability.setJavascriptEnabled(true);
        return new SafariDriver(capability);
    /*        case OPERA_DRIVER:
    capability = DesiredCapabilities.opera();
    capability.setCapability("opera.host", "127.0.0.1");
    return new OperaDriver();
     */
    case EDGE:
        capability = DesiredCapabilities.edge();
        EdgeOptions option = new EdgeOptions();
        capability.setCapability("edgeOptions", option);
        return new EdgeDriver(capability);
    default:
        log.info(
                "Currenty support is there for Chrome, Firefox, Firefox Marionette, Internet Explorer, Edge, Safari & Opera. Support is not there for "
                        + browserName);
        capability = DesiredCapabilities.firefox();
        FirefoxProfile firefoxProf = new FirefoxProfile();
        firefoxProf.setAcceptUntrustedCertificates(true);
        firefoxProf.setEnableNativeEvents(true);
        firefoxProf.setAssumeUntrustedCertificateIssuer(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProf);
        return new FirefoxDriver(capability);
    }
}

From source file:com.citrix.g2w.webdriver.tests.BaseWebDriverTest.java

License:Open Source License

/**
 * Method to create new WebDriver.//w  w  w.j  a  v  a2  s.  c  o  m
 * 
 * @return (driver object depends on input)
 */
protected WebDriver getWebDriver() {
    // Not handling any concurrency issues since expect single thread to run
    // TODO: Web driver creation for every page seems weird, should be a
    // webdriver per test. Move out web driver instantiation
    if (this.webDriver != null) {
        return this.webDriver;
    }
    String driver = this.propertyUtil.getProperty("driver");
    if ((driver != null) && (driver.equalsIgnoreCase("firefox"))) {
        this.webDriver = new FirefoxDriver();

    } else if (driver.equalsIgnoreCase("remotewebdriver")) {
        //Hardcoding to  firefox  
        DesiredCapabilities capability = DesiredCapabilities.firefox();
        try {
            this.webDriver = new RemoteWebDriver(
                    new URL("http://" + this.propertyUtil.getProperty("seleniumGridHost") + ":4444/wd/hub"),
                    capability);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    } else if (driver.equalsIgnoreCase("ghostdriver")) {
        // String path1 =
        // this.getClass().getResource("/test/phantomjs").getPath();
        String path = "D://Projects//WebinarProject//lib//phantomjs/ .exe";

        // Command line arguments to phantomjs
        ArrayList<String> cliArgsCap = new ArrayList<String>();
        cliArgsCap.add("--web-security=false");
        cliArgsCap.add("--ssl-protocol=any");
        cliArgsCap.add("--ignore-ssl-errors=true");

        DesiredCapabilities dCaps = new DesiredCapabilities();

        dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
        dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, path);
        dCaps.setJavascriptEnabled(true);

        this.webDriver = new PhantomJSDriver(dCaps);
        this.webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    } else {
        this.webDriver = new CustomHtmlUnitDriver(true, false);
        this.webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }

    return this.webDriver;
}

From source file:com.dhenton9000.embedded.jetty.PhantomJSTest.java

public final WebDriver configureDriver(PropertiesConfiguration sConfig) throws IOException {
    DesiredCapabilities sCaps = new DesiredCapabilities();
    sCaps.setJavascriptEnabled(true);
    sCaps.setCapability("takesScreenshot", false);
    if (sConfig.getProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY) != null) {
        sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                sConfig.getProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY));
    } else {//from   ww  w.j a v a  2 s .  c o m
        throw new IOException(String.format("Property '%s' not set!",
                PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY));
    }
    // "phantomjs_driver_path"
    if (sConfig.getProperty(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY) != null) {
        LOG.debug("Test will use an external GhostDriver");
        sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY,
                sConfig.getProperty(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY));
    } else {
        LOG.debug("Test will use PhantomJS internal GhostDriver");
    }

    WebDriver mDriver = new PhantomJSDriver(sCaps);

    return mDriver;

}

From source file:com.dhenton9000.phantom.js.PhantomJSBase.java

protected final WebDriver configureDriver(PropertiesConfiguration sConfig) throws IOException {
    DesiredCapabilities sCaps = new DesiredCapabilities();
    sCaps.setJavascriptEnabled(true);
    sCaps.setCapability("takesScreenshot", false);
    if (sConfig.getProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY) != null) {
        sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                sConfig.getProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY));
    } else {/*from  w w w. ja  v a2  s .com*/
        throw new IOException(String.format("Property '%s' not set!",
                PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY));
    }
    // "phantomjs_driver_path"
    if (sConfig.getProperty(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY) != null) {
        LOG.debug("Test will use an external GhostDriver");
        sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY,
                sConfig.getProperty(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY));
    } else {
        LOG.debug("Test will use PhantomJS internal GhostDriver");
    }

    WebDriver mDriver = new PhantomJSDriver(sCaps);

    return mDriver;

}

From source file:com.digitalpebble.stormcrawler.protocol.selenium.RemoteDriverProtocol.java

License:Apache License

@Override
public void configure(Config conf) {
    super.configure(conf);

    // see https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setJavascriptEnabled(true);

    String userAgentString = getAgentString(conf);

    // custom capabilities
    Map<String, Object> confCapabilities = (Map<String, Object>) conf.get("selenium.capabilities");
    if (confCapabilities != null) {
        Iterator<Entry<String, Object>> iter = confCapabilities.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            Object val = entry.getValue();
            // substitute variable $useragent for the real value
            if (val instanceof String && "$useragent".equalsIgnoreCase(val.toString())) {
                val = userAgentString;
            }/*from  w  ww . j  ava 2  s.c o m*/
            capabilities.setCapability(entry.getKey(), entry.getValue());
        }
    }

    // load adresses from config
    List<String> addresses = ConfUtils.loadListFromConf("selenium.addresses", conf);
    if (addresses.size() == 0) {
        throw new RuntimeException("No value found for selenium.addresses");
    }
    try {
        for (String cdaddress : addresses) {
            RemoteWebDriver driver = new RemoteWebDriver(new URL(cdaddress), capabilities);
            Timeouts touts = driver.manage().timeouts();
            int implicitWait = ConfUtils.getInt(conf, "selenium.implicitlyWait", 0);
            int pageLoadTimeout = ConfUtils.getInt(conf, "selenium.pageLoadTimeout", -1);
            int setScriptTimeout = ConfUtils.getInt(conf, "selenium.setScriptTimeout", 0);
            touts.implicitlyWait(implicitWait, TimeUnit.MILLISECONDS);
            touts.pageLoadTimeout(pageLoadTimeout, TimeUnit.MILLISECONDS);
            touts.setScriptTimeout(setScriptTimeout, TimeUnit.MILLISECONDS);
            drivers.add(driver);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.ecofactor.qa.automation.platform.ops.impl.AndroidOperations.java

License:Open Source License

/**
 * Sets the driver capabilities.//from   w  ww .j av  a2 s  .c  om
 * @param deviceType the device type
 * @param app the app
 * @return the desired capabilities
 */
private DesiredCapabilities setDriverCapabilities(final boolean deviceType, final File app) {

    final DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("device", deviceType ? "Android" : "Selendroid");
    capabilities.setCapability("launch", deviceType ? "false" : "true");
    setHubCapabilities(capabilities);
    capabilities.setCapability("app", app.getAbsolutePath());
    capabilities.setCapability("app-package", "com.ecofactor.mobileapp.qa");
    capabilities.setCapability("app-activity", "com.ecofactor.mobileapp.qa.QA_Ecofactor");
    capabilities.setJavascriptEnabled(true);
    return capabilities;
}

From source file:com.ecofactor.qa.automation.platform.util.SeleniumDriverUtil.java

License:Open Source License

/**
 * Sets the driver capabilities./*from  ww  w. j a v  a  2 s. c o m*/
 * @param deviceType the device type
 * @param app the app
 * @return the desired capabilities
 */
private static DesiredCapabilities setDriverCapabilities(final boolean deviceType, final File app) {

    final DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("device", deviceType ? "Android" : "Selendroid");
    capabilities.setCapability("launch", deviceType ? "false" : "true");
    setHubCapabilities(capabilities);
    capabilities.setCapability("app", app.getAbsolutePath());
    capabilities.setCapability("app-package", "com.ecofactor.mobileapp.qa");
    capabilities.setCapability("app-activity", "com.ecofactor.mobileapp.qa.QA_Ecofactor");
    capabilities.setJavascriptEnabled(true);
    return capabilities;
}