Example usage for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver

List of usage examples for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver

Introduction

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

Prototype

public RemoteWebDriver(URL remoteAddress, Capabilities capabilities) 

Source Link

Usage

From source file:com.arcbees.test.CurrentScenarioAspect.java

License:Apache License

private WebDriver createGridWebDriver() throws MalformedURLException {
    URL hubUrl = new URL(TestParameters.SELENIUM_HUB_URL);
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setCapability(BROWSER_NAME, TestParameters.BROWSER);
    return new RemoteWebDriver(hubUrl, desiredCapabilities);
}

From source file:com.asiainfo.tfsPlatform.modules.test.selenium.WebDriverFactory.java

License:Apache License

/**
 * ?driverName??WebDriver./*  w  ww. jav  a  2 s. c om*/
 * 
 * ??firefox,ie,chrome??.
 * 
 * ????Windows, IE?XWindows, ???remote driverWindows.
 * drivernameremote:192.168.0.2:4444:firefox, ??http://192.168.0.2:4444/wd/hub?selenium remote?.
 */
public static WebDriver createDriver(String driverName) {
    WebDriver driver = null;

    if (BrowserType.firefox.name().equals(driverName)) {
        driver = new FirefoxDriver();
    } else if (BrowserType.ie.name().equals(driverName)) {
        driver = new InternetExplorerDriver();
    } else if (BrowserType.chrome.name().equals(driverName)) {
        driver = new ChromeDriver();
    } else if (driverName.startsWith(BrowserType.remote.name())) {
        String[] params = driverName.split(":");
        Validate.isTrue(params.length == 4,
                "Remote driver is not right, accept format is \"remote:localhost:4444:firefox\", but the input is\""
                        + driverName + "\"");

        String remoteHost = params[1];
        String remotePort = params[2];
        String driverType = params[3];

        String remoteUrl = "http://" + remoteHost + ":" + remotePort + "/wd/hub";

        DesiredCapabilities cap = null;
        if (BrowserType.firefox.name().equals(driverType)) {
            cap = DesiredCapabilities.firefox();
        } else if (BrowserType.ie.name().equals(driverType)) {
            cap = DesiredCapabilities.internetExplorer();
        } else if (BrowserType.chrome.name().equals(driverType)) {
            cap = DesiredCapabilities.chrome();
        }

        try {
            driver = new RemoteWebDriver(new URL(remoteUrl), cap);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }

    Validate.notNull(driver, "Driver could be found by name:" + driverName);

    return driver;
}

From source file:com.atanas.kanchev.testframework.selenium.driverfactory.RemoteWebDriverFactory.java

License:Apache License

/**
 * <p>getRemoteWebDriver.</p>
 *
 * @param desiredCapabilities a {@link org.openqa.selenium.remote.DesiredCapabilities} object.
 * @return a {@link org.openqa.selenium.remote.RemoteWebDriver} object.
 *//*from  w  ww.  jav  a  2  s  .  c  o m*/
public RemoteWebDriver getRemoteWebDriver(DesiredCapabilities desiredCapabilities) {

    URL url = null;
    try {
        url = new URL(getHubURL());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    String desiredBrowserVersion = getBrowserVersion();
    String desiredPlatform = getPlatform();

    if (null != desiredPlatform && !desiredPlatform.isEmpty()) {
        desiredCapabilities.setPlatform(Platform.valueOf(desiredPlatform.toUpperCase()));
    }

    if (null != desiredBrowserVersion && !desiredBrowserVersion.isEmpty()) {
        desiredCapabilities.setVersion(desiredBrowserVersion);
    }

    return new RemoteWebDriver(url, desiredCapabilities);
}

From source file:com.ceiwc.compugain.setup.TestBase.java

public WebDriver initializeDriver(String sbrowser, String sgrid) {
    WebDriver driver = null;/*from  w w  w  . jav a  2  s . c  o  m*/
    logger.info("Test Base Version is" + Configuration.getGrid());
    logger.info("Test Base Browser is" + sbrowser);
    sgrid = Configuration.getGrid();
    if (sgrid.equalsIgnoreCase("")) {
        sbrowser = Configuration.getAutomationBrowser();
        return driver = initializeDriver(sbrowser);
    } else if (!sgrid.equalsIgnoreCase("") && !sbrowser.equalsIgnoreCase("")) {
        logger.info("I am in Grid Intialization");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        URL hubUrl = null;
        try {
            hubUrl = new URL("http://localhost:4444/wb/hub");
            if (sbrowser.equalsIgnoreCase("firefox")) {
                FirefoxProfile profile = new FirefoxProfile();
                profile.setPreference("browser.download.folderList", 2);
                capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
                capabilities.setPlatform(Platform.WINDOWS);
                driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
                //remoteWebDriver.setFileDetector(new LocalFileDetector());
            }
            if (sbrowser.equalsIgnoreCase("chrome")) {
                System.setProperty("webdriver.chrome.driver", getFilePath(CHROMEPATH));
                capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
                //capabilities.setVersion(sversion1);
                capabilities.setPlatform(Platform.WINDOWS);
                driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    return driver;

}

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

License:Open Source License

/**
 * Method to create new WebDriver.//from w ww . j  a va  2  s .co  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.comcast.dawg.selenium.BrowserServiceManager.java

License:Apache License

/**
 * Gets a web driver for a given browser
 * @param browser The browser to get a driver for
 * @return// w  ww .  j a v a  2  s . co  m
 * @throws IOException
 */
public static synchronized RemoteWebDriver getDriver(Browser browser) throws IOException {
    if (global == null) {
        DriverService service = start(browser);
        global = new RemoteWebDriver(service.getUrl(), getDesiredBrowserCapabilities(browser));
        drivers.put(global, service);
    }
    return global;
}

From source file:com.comcast.magicwand.spells.saucelabs.SauceProvider.java

License:Apache License

/**
 * Creates one of:/*from w ww . j  ava2 s .c o  m*/
 * <ul>
 * <li>{@link RemoteWebDriver}</li>
 * <li>{@link AndroidDriver}</li>
 * <li>{@link IOSDriver}</li>
 * </ul>
 * driver that will be communicating with SauceLabs
 * @param remoteAddress URL of the location to connect to
 * @return Instance of a driver
 * @throws FlyingPhoenixException
 */
protected WebDriver createWebDriver(URL remoteAddress) throws FlyingPhoenixException {
    WebDriver retVal = null;

    boolean isAppium = (null != this.customCapabilities.getCapability("appiumVersion"));
    String platform = (String) this.customCapabilities.getCapability("platformName");
    boolean isAndroid = ("android".equalsIgnoreCase(platform));

    // upload files
    if (!filesToUpload.isEmpty()) {
        SauceResponse sauceResponse = uploadFilesToSauceStorage();
        LOG.info("FileName:UploadSuccess {}", sauceResponse.getResponseObject());
        if (!sauceResponse.isSuccess()) {
            LOG.error(sauceResponse.getFailureReason());
            throw new FlyingPhoenixException("Uploading file/s to sauce storage failed");
        }
    }

    if (isAppium && isAndroid) {
        retVal = new AndroidDriver(remoteAddress, this.customCapabilities);
    } else if (isAppium && (null != platform)) {
        retVal = new IOSDriver(remoteAddress, this.customCapabilities);
    } else {
        retVal = new RemoteWebDriver(remoteAddress, this.customCapabilities);
    }

    return retVal;
}

From source file:com.consol.citrus.selenium.client.WebClient.java

License:Apache License

private RemoteWebDriver createRemoteWebDriver(BrowserTypeEnum browserType, String serverAddress)
        throws MalformedURLException {
    switch (browserType) {
    case FIREFOX:
        DesiredCapabilities defaultsFF = DesiredCapabilities.firefox();
        defaultsFF.setCapability(FirefoxDriver.PROFILE, createFireFoxProfile());
        return new RemoteWebDriver(new URL(serverAddress), defaultsFF);
    case INTERNET_EXPLORER:
        DesiredCapabilities defaultsIE = DesiredCapabilities.internetExplorer();
        defaultsIE.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        return new RemoteWebDriver(new URL(serverAddress), defaultsIE);
    default://from   w  w w.j  av a  2  s .com
        DesiredCapabilities defaults = DesiredCapabilities.chrome();
        defaults.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        return new RemoteWebDriver(new URL(serverAddress), defaults);
    }
}

From source file:com.consol.citrus.selenium.endpoint.SeleniumBrowser.java

License:Apache License

/**
 * Creates remote web driver.//from  www  .  j a v  a 2  s .com
 * @param browserType
 * @param serverAddress
 * @return
 * @throws MalformedURLException
 */
private RemoteWebDriver createRemoteWebDriver(String browserType, String serverAddress) {
    try {
        switch (browserType) {
        case BrowserType.FIREFOX:
            DesiredCapabilities defaultsFF = DesiredCapabilities.firefox();
            defaultsFF.setCapability(FirefoxDriver.PROFILE, getEndpointConfiguration().getFirefoxProfile());
            return new RemoteWebDriver(new URL(serverAddress), defaultsFF);
        case BrowserType.IE:
            DesiredCapabilities defaultsIE = DesiredCapabilities.internetExplorer();
            defaultsIE.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            return new RemoteWebDriver(new URL(serverAddress), defaultsIE);
        case BrowserType.CHROME:
            DesiredCapabilities defaultsChrome = DesiredCapabilities.chrome();
            defaultsChrome.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            return new RemoteWebDriver(new URL(serverAddress), defaultsChrome);
        case BrowserType.GOOGLECHROME:
            DesiredCapabilities defaultsGoogleChrome = DesiredCapabilities.chrome();
            defaultsGoogleChrome.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            return new RemoteWebDriver(new URL(serverAddress), defaultsGoogleChrome);
        default:
            throw new CitrusRuntimeException("Unsupported remote browser type: " + browserType);
        }
    } catch (MalformedURLException e) {
        throw new CitrusRuntimeException("Failed to access remote server", e);
    }
}

From source file:com.demo.selenium.example.GridExampleTest.java

License:Apache License

@Test
public void GridTwoNodeTest() throws MalformedURLException, InterruptedException {

    DesiredCapabilities aDesiredcap = DesiredCapabilities.chrome();
    WebDriver dr = new RemoteWebDriver(new URL("http://172.19.6.46:5555/wd/hub"), aDesiredcap);
    dr.get("http://www.baidu.com");
    dr.manage().window().maximize();//from   w  ww.j av a  2  s.  c  o  m

    String str[] = new String[] { "java", "selenium", "spring", "mybatis", "jps", "grid", "mysql", "iphone" };
    for (String string : str) {
        WebElement element = dr.findElement(By.xpath(".//*[@id='kw']"));
        element.clear();
        element.sendKeys(string);

        Thread.sleep(1000);

        WebElement buttons = dr.findElement(By.xpath(".//*[@id='su']"));

        System.out.println(buttons.getTagName());

        buttons.click();
    }

    Thread.sleep(2000);

    dr.close();

}