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:edu.samplu.common.WebDriverUtil.java

License:Educational Community License

/**
 * remote.public.driver set to chrome or firefox (null assumes firefox)
 * if remote.public.hub is set a RemoteWebDriver is created (Selenium Grid)
 * if proxy.host is set, the web driver is setup to use a proxy
 * @return WebDriver or null if unable to create
 *//*from  w  w w.j  a  v a  2  s . c om*/
public static WebDriver getWebDriver() {
    String driverParam = System.getProperty(ITUtil.HUB_DRIVER_PROPERTY);
    String hubParam = System.getProperty(ITUtil.HUB_PROPERTY);
    String proxyParam = System.getProperty(PROXY_HOST_PROPERTY);

    // setup proxy if specified as VM Arg
    DesiredCapabilities capabilities = new DesiredCapabilities();
    WebDriver webDriver = null;
    if (StringUtils.isNotEmpty(proxyParam)) {
        capabilities.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(proxyParam));
    }

    if (hubParam == null) {
        if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
            FirefoxProfile profile = new FirefoxProfile();
            profile.setEnableNativeEvents(false);
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            return new FirefoxDriver(capabilities);
        } else if ("chrome".equalsIgnoreCase(driverParam)) {
            return new ChromeDriver(capabilities);
        } else if ("safari".equals(driverParam)) {
            System.out.println("SafariDriver probably won't work, if it does please contact Erik M.");
            return new SafariDriver(capabilities);
        }
    } else {
        try {
            if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(ITUtil.getHubUrlString()), DesiredCapabilities.firefox());
            } else if ("chrome".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(ITUtil.getHubUrlString()), DesiredCapabilities.chrome());
            }
        } catch (MalformedURLException mue) {
            System.out.println(ITUtil.getHubUrlString() + " " + mue.getMessage());
            mue.printStackTrace();
        }
    }
    return null;
}

From source file:EndToEnd.BFUIJobsExcnVldtnTest.java

License:Apache License

/**
 * @throws java.lang.Exception//from  www. ja  va 2 s .c  om
 */
@Before
public void setUp(int address) throws Exception {

    baseUrl = "https://beachfront.stage.geointservices.io/";
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setBrowserName("chrome");
    capabilities.setPlatform(Platform.WINDOWS);
    driver = new RemoteWebDriver(new URL(urls[address]), capabilities);
    driver.manage().timeouts().implicitlyWait(90, TimeUnit.MINUTES);
}

From source file:example.ParameterizedExampleTest.java

License:Apache License

/**
 * Setup before test.//from  www. java2  s  . c o m
 *
 * @throws MalformedURLException
 *             If the hub URL is malformed.
 */
@Before
public void beforeTest() throws MalformedURLException {
    // Request WebDriver instance from TeCh Selenium to start the VM.
    final URL hub = new URL("http://localhost:4444/wd/hub");
    this.driver = new RemoteWebDriver(hub, capas);
}

From source file:example.SimpleExampleTest.java

License:Apache License

/**
 * Setup before test.//from  w  w  w.ja va  2s  .c o m
 *
 * @throws MalformedURLException
 *             If the hub URL is malformed.
 */
@Before
public void beforeTest() throws MalformedURLException {
    // Request WebDriver instance from TeCh Selenium to start the VM.
    final URL hub = new URL("http://localhost:4444/wd/hub");
    final DesiredCapabilities capas = DesiredCapabilities.chrome();
    this.driver = new RemoteWebDriver(hub, capas);
}

From source file:ExitOffers.MavenAutomation.QuotesGMI.java

@Test
public void testUntitled() throws Exception {

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("name", "Run me on Chrome");
    caps.setCapability("build", "1.0");
    caps.setCapability("browser_api_name", "Chrome45");
    caps.setCapability("os_api_name", "Win10");
    caps.setCapability("screen_resolution", "1024x768");
    caps.setCapability("record_video", "true");
    caps.setCapability("record_network", "true");
    caps.setCapability("record_snapshot", "false");
    driver = new RemoteWebDriver(
            new URL("http://sstroman%40leadnomics.com:u2eecd8d888b0c95@hub.crossbrowsertesting.com:80/wd/hub"),
            caps);/* w w w  . j av a2 s  . com*/

    System.out.println("Navigating to Website");
    driver.navigate().to("http://staging.quotes.getmyinsurance.com/?_s=QAautoMultiPageA");
    //driver.navigate().to("https://quotes.getmyinsurance.com/?_s=QAautoMultiPageA");
    System.out.println("Navigated to Website");

    System.out.println("Enter Zip");
    driver.findElement(By.cssSelector("input[type=\"tel\"]")).sendKeys("19103");

    System.out.println("Submit Lander");
    driver.findElement(By.cssSelector("button.submit.callToAction")).click();

    System.out.println("Switch to form");
    for (String winHandle : driver.getWindowHandles()) {
        driver.switchTo().window(winHandle);
    }

    System.out.println("What type of vehicle do you drive?");
    WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("vehicle-year")));
    new Select(driver.findElement(By.id("vehicle-year"))).selectByVisibleText("2011");
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("vehicle-make")));
    new Select(driver.findElement(By.id("vehicle-make"))).selectByVisibleText("AUDI");
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("vehicle-model")));
    new Select(driver.findElement(By.id("vehicle-model"))).selectByVisibleText("A5 QUATTRO PREMIUM");
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("vehicle-style")));
    new Select(driver.findElement(By.id("vehicle-style"))).selectByVisibleText("Convertible");
    driver.findElement(By.cssSelector("button.btn.next")).click();

    System.out.println("Vehicle details - Part 2");
    new Select(driver.findElement(By.id("vehicle-own"))).selectByVisibleText("Leased");
    new Select(driver.findElement(By.id("vehicle-daily"))).selectByVisibleText("1-5 Miles");
    new Select(driver.findElement(By.id("annual-mileage"))).selectByVisibleText("5,000 - 7,500 miles");
    new Select(driver.findElement(By.id("collision-deductible"))).selectByVisibleText("$ 50");
    new Select(driver.findElement(By.id("comprehensive-deductible"))).selectByVisibleText("$ 100");

    System.out.println("Additional Vehicle");
    driver.findElement(By.cssSelector("fieldset.prehide > div.section > div.pagenav > button.btn.add")).click();
    new Select(driver.findElement(By.id("vehicle-year"))).selectByVisibleText("2014");
    new Select(driver.findElement(By.id("vehicle-make"))).selectByVisibleText("FORD");
    new Select(driver.findElement(By.id("vehicle-model"))).selectByVisibleText("F150");
    new Select(driver.findElement(By.id("vehicle-style"))).selectByVisibleText("Pickup");
    driver.findElement(By.cssSelector("button.btn.next")).click();
    new Select(driver.findElement(By.id("vehicle-own"))).selectByVisibleText("Owned");
    driver.findElement(By.cssSelector("fieldset.prehide > div.section > div.pagenav > button.btn.next"))
            .click();

    System.out.println("Coverage Options");
    new Select(driver.findElement(By.id("coverage-level"))).selectByVisibleText("Superior Coverage");
    new Select(driver.findElement(By.id("currently-insured"))).selectByVisibleText("No");
    new Select(driver.findElement(By.id("currently-insured"))).selectByVisibleText("Yes");
    new Select(driver.findElement(By.id("InsuranceCompany"))).selectByVisibleText("AAA Insurance Co.");
    new Select(driver.findElement(By.cssSelector("div.splitContainer > select")))
            .selectByVisibleText("February");
    new Select(driver.findElement(By.xpath(
            "//form[@id='the-form']/fieldset/fieldset/fieldset[2]/fieldset/div/fieldset/div/div[2]/div/select[2]")))
                    .selectByVisibleText("2021");
    new Select(driver.findElement(By.id("start-date"))).selectByVisibleText("3 years");
    driver.findElement(
            By.xpath("//form[@id='the-form']/fieldset/fieldset/fieldset[2]/fieldset/div/div[2]/button"))
            .click();

    System.out.println("Driver Details");
    driver.findElement(By.id("first-name")).sendKeys("TestA");
    driver.findElement(By.id("last-name")).sendKeys("LeadnomicsA");
    new Select(driver.findElement(
            By.cssSelector("div.section > div.row > div.field.control-group > div.splitContainer > select")))
                    .selectByVisibleText("Jan");
    new Select(driver.findElement(By
            .xpath("//form[@id='the-form']/fieldset[2]/fieldset/fieldset/div[2]/div[2]/div[2]/div/select[2]")))
                    .selectByVisibleText("1");
    new Select(driver.findElement(By
            .xpath("//form[@id='the-form']/fieldset[2]/fieldset/fieldset/div[2]/div[2]/div[2]/div/select[3]")))
                    .selectByVisibleText("1950");
    driver.findElement(By.name("Gender")).click();
    driver.findElement(By.name("MaritalStatus")).click();
    driver.findElement(By.name("MilitaryExperience")).click();
    new Select(driver.findElement(By.id("occupation-name"))).selectByVisibleText("Engineer");
    driver.findElement(
            By.cssSelector("fieldset.prehide > fieldset > div.section > div.pagenav > button.btn.next"))
            .click();

    System.out.println("Driver Details - Part 2");
    new Select(driver.findElement(By.id("vehicle-id"))).selectByVisibleText("2011 AUDI A5 QUATTRO PREMIUM");

    System.out.println("Additional Driver");
    driver.findElement(By.cssSelector(
            "fieldset.prehide > fieldset > fieldset > fieldset > div.section > div.pagenav > button.btn.add"))
            .click();
    driver.findElement(By.id("first-name")).sendKeys("TestB");
    driver.findElement(By.id("last-name")).sendKeys("LeadnomicsB");
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("relationship")));
    driver.findElement(By.id("relationship")).sendKeys("Child");
    new Select(driver.findElement(
            By.cssSelector("div.section > div.row > div.field.control-group > div.splitContainer > select")))
                    .selectByVisibleText("Feb");
    new Select(driver.findElement(By
            .xpath("//form[@id='the-form']/fieldset[2]/fieldset/fieldset/div[2]/div[2]/div[2]/div/select[2]")))
                    .selectByVisibleText("2");
    new Select(driver.findElement(By
            .xpath("//form[@id='the-form']/fieldset[2]/fieldset/fieldset/div[2]/div[2]/div[2]/div/select[3]")))
                    .selectByVisibleText("1970");
    driver.findElement(By.name("Gender")).click();
    driver.findElement(By.name("MaritalStatus")).click();
    driver.findElement(By.name("MilitaryExperience")).click();
    new Select(driver.findElement(By.id("occupation-name"))).selectByVisibleText("Clergy");
    driver.findElement(
            By.cssSelector("fieldset.prehide > fieldset > div.section > div.pagenav > button.btn.next"))
            .click();

    System.out.println("Additional Driver Details - Part 2");
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("license-state")));
    new Select(driver.findElement(By.id("license-state"))).selectByVisibleText("Pennsylvania");
    new Select(driver.findElement(By.id("vehicle-id"))).selectByVisibleText("2014 FORD F150");
    driver.findElement(By.cssSelector(
            "fieldset.prehide > fieldset > fieldset > fieldset > div.section > div.pagenav > button.btn.next"))
            .click();

    System.out.println("How Do We Reach You?");
    driver.findElement(By.cssSelector("input[type=\"tel\"]")).sendKeys("215");
    driver.findElement(By.cssSelector("span.phone1 > input[type=\"tel\"]")).sendKeys("847");
    driver.findElement(By.cssSelector("span.phone2 > input[type=\"tel\"]")).sendKeys("5555");
    driver.findElement(By.id("email")).sendKeys("test@leadnomics.com");
    driver.findElement(By.id("address")).sendKeys("1234 Main St");
    driver.findElement(By.id("residence-status")).click();
    new Select(driver.findElement(By.id("residence-status"))).selectByVisibleText("Rent");
    new Select(driver.findElement(By.id("credit-rating"))).selectByVisibleText("Excellent");
    driver.findElement(By.cssSelector("button.cta")).click();

    System.out.println("Offers Page");
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ckContainer")));
    driver.findElement(By.id("ckContainer"));

    System.out.println("Test Complete");
    driver.quit();
}

From source file:fr.jetoile.demo.breizhcamp.webapp.driver.WebDriverFactory.java

License:Apache License

private static WebDriver remoteDriver(DesiredCapabilities capabilities) throws UnsupportedDriverException {
    String osName = (String) capabilities.getCapability("os.name");

    capabilities.setPlatform(Platform.extractFromSysProperty(osName, ""));
    capabilities.setVersion((String) capabilities.getCapability("os.version"));

    String url = (String) capabilities.getCapability("webdriver.remote.url");
    try {//from   w ww .j a v  a2s. co  m
        return new RemoteWebDriver(new URL(url), capabilities);
    } catch (MalformedURLException e) {
        throw new UnsupportedDriverException("wrong parameters for remote webDriver: " + capabilities, e);
    }
}

From source file:fr.lip6.segmentations.BrowserRep.java

License:Open Source License

public void setRemoteDriver() throws MalformedURLException {
    this.driver = new RemoteWebDriver(new URL(SeleniumWrapper.seleniumUrl), capabilities);
    setJSDriver();//from ww w.j  a va2 s  .c  o  m
    this.driver = new Augmenter().augment(this.driver);
    this.driver.manage().timeouts().pageLoadTimeout(MAX_WAIT_S, TimeUnit.SECONDS);
    this.driver.manage().timeouts().implicitlyWait(MAX_WAIT_S, TimeUnit.SECONDS);
    this.driver.manage().window().setSize(new org.openqa.selenium.Dimension(1024, 768));
}

From source file:galen.api.server.GalenCommandExecutor.java

License:Apache License

/**
 * Executes the command received over the Thrift interface inside an instance of RemoteWebDriver.
 * @param sessionId WebDriver SessionId.
 * @param commandName Command name.//from   w  w  w. j a  va2 s  . c  o m
 * @param params Command params.
 * @return an instance of {@link org.openqa.selenium.remote.Response}
 * @throws TException
 */
@Override
public Response execute(String sessionId, String commandName, String params) throws TException {
    Map<String, Object> paramsAsMap = fromJsonToStringObjectMap(params);
    if (commandName.equals(DriverCommand.NEW_SESSION)) {
        try {
            log.info("Setting up new WebDriver session");
            HashMap<String, Object> hashMap = extractDesiredCapabilities(paramsAsMap);
            WebDriver driver = new RemoteWebDriver(new URL(remoteServerAddress),
                    new DesiredCapabilities(hashMap));
            DriversPool.get().set(driver);
            return createSessionInitSuccessResponse(driver);
        } catch (MalformedURLException e) {
            log.error("Provided URL is malformed " + remoteServerAddress);
            return createSessionInitFailureResponse("Provided URL is malformed " + remoteServerAddress);
        } catch (UnreachableBrowserException e) {
            log.error("Could not reach browser at URL " + remoteServerAddress
                    + " check remote server is running.");
            return createSessionInitFailureResponse("Could not reach browser at URL " + remoteServerAddress
                    + " check remote server is running.");
        } catch (WebDriverException e) {
            throw new RemoteWebDriverException(e.getMessage());
        }
    }
    Command driverCommand = new Command(new SessionId(sessionId), handleCommandNameExceptions(commandName),
            paramsAsMap);
    try {
        log.info(format("Executing command %s for sessionId %s", commandName, sessionId));
        WebDriver driver = DriversPool.get().getBySessionId(sessionId);
        org.openqa.selenium.remote.Response response = null;
        if (driver instanceof RemoteWebDriver) {
            response = ((RemoteWebDriver) driver).getCommandExecutor().execute(driverCommand);
        }
        if (response == null) {
            return null;
        } else {
            if (commandName.equals(DriverCommand.QUIT)) {
                DriversPool.get().removeDriverBySessionId(sessionId);
            }
            ThriftValueWrapper valueWrapper = new ThriftValueWrapper(response.getValue());
            return new Response(valueWrapper.getValue(), valueWrapper.getContainedValues(),
                    response.getSessionId(), response.getStatus(), response.getState());
        }
    } catch (IOException ioe) {
        log.error(format("IOException while executing command %s: %s", commandName, ioe.toString()));
    } catch (WebDriverException wex) {
        log.error(format("WebDriverException while executing command %s: + %s", commandName, wex.toString()));
        throw new RemoteWebDriverException(wex.getMessage());
    }
    return null;
}

From source file:grokpackage.GrokMobileAppTest.java

License:Open Source License

@BeforeClass
@Parameters({ "deviceName", "version", "sauceUserName", "sauceAccessKey" })
public void setUp(String deviceName, String platformVersion, String sauceUserName, String sauceAccessKey)
        throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("name", "Grok mobile Testing");
    capabilities.setCapability("app", "sauce-storage:grok-mobile-app-release.apk");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("device-orientation", "portrait");
    capabilities.setCapability("deviceName", deviceName);
    capabilities.setCapability("platformVersion", platformVersion);
    capabilities.setCapability("androidPackage", "com.groksolutions.grok.mobile");
    capabilities.setCapability("appActivity", "com.groksolutions.grok.mobile.SplashScreenActivity");
    driver = new RemoteWebDriver(
            new URL("http://" + sauceUserName + ":" + sauceAccessKey + "@ondemand.saucelabs.com:80/wd/hub"),
            capabilities);/*from ww  w  . j av  a  2  s  .  co m*/
    Thread.sleep(1000);
}

From source file:hu.traininfo.uitest.step.Steps.java

License:Open Source License

@BeforeStories
public void openBrowser() throws MalformedURLException {
    this.testEnv = System.getProperty("traininfo.test.env");
    if (this.testEnv == null || this.testEnv.trim().length() == 0 || this.testEnv.equalsIgnoreCase("prod")) {
        this.testEnv = "www";
    }//  w  w  w.  jav a  2 s  .c  o m

    this.browser = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), DesiredCapabilities.firefox());

    checkBrowser();

    this.browser.manage().timeouts().implicitlyWait(DEFAULT_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS);

    // FirefoxProfile profile = new FirefoxProfile();
    // profile.addAdditionalPreference("general.useragent.override",
    // KINDLE_HTTP_USER_AGENT);
    // WebDriver driver = new FirefoxDriver(profile);

    this.selenium = new WebDriverBackedSelenium(this.browser, getWebpageUrl());
}