Example usage for org.openqa.selenium WebDriver get

List of usage examples for org.openqa.selenium WebDriver get

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver get.

Prototype

void get(String url);

Source Link

Document

Load a new web page in the current browser window.

Usage

From source file:org.opencastproject.loadtest.engage.LoadTestEngage.java

License:Educational Community License

/**
 * Start playing a new episode. //from w  ww. j  a  va2  s .  com
 */
public void playNewStream() {
    if (episodeList == null || episodeList.size() <= 0) {
        return;
    }
    String episodeUrl = engageServerUrl + "/engage/ui/watch.html?id="
            + episodeList.get(generator.nextInt(episodeList.size()));
    driver.get(episodeUrl);
    if (!driver.getCurrentUrl().equalsIgnoreCase(episodeUrl)) {
        authenticate();
    }
    logger.info(name + " - Playing episode " + episodeUrl);
    logger.debug("Episode Page title is: " + driver.getTitle());

    // Play the episode. 
    WebElement play = (new WebDriverWait(driver, 60)).until(new ExpectedCondition<WebElement>() {
        @Override
        public WebElement apply(WebDriver driver) {
            WebElement webElement = driver.findElement(By.id("oc_btn-play-pause"));
            if (webElement != null && webElement.isDisplayed()) {
                return webElement;
            }
            return null;
        }
    });

    play.click();

    // Advance the play using fast forward. 
    WebElement fastForward = (new WebDriverWait(driver, 10000)).until(new ExpectedCondition<WebElement>() {
        @Override
        public WebElement apply(WebDriver driver) {
            WebElement webElement = driver.findElement(By.id("oc_btn-fast-forward"));
            if (webElement != null && webElement.isDisplayed()) {
                return webElement;
            }
            return null;
        }
    });

    for (int i = 0; i < 5; i++) {
        fastForward.click();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error("There was an exception while fastforwarding:", e);
        }
    }
}

From source file:org.openlmis.functional.ChromeTest.java

License:Open Source License

@Test
public void testGoogleSearch() {
    // Optional, if not specified, WebDriver will search your path for chromedriver.
    System.setProperty("webdriver.chrome.driver", "/home/mesh/Programs/chromedriver");

    WebDriver driver = new ChromeDriver();
    driver.get("http://www.google.com/xhtml");

    WebElement searchBox = driver.findElement(By.name("q"));
    searchBox.sendKeys("ChromeDriver");
    searchBox.submit();/*from w  ww  . j av a  2  s .  c  o  m*/
    driver.quit();
}

From source file:org.opennms.smoketest.IndexPageIT.java

License:Open Source License

@Test
public void verifyStatusMap() {
    // In order to have anything show up, we have to create a node with long/lat information first
    // A interface and service which does not exist is used, in order to provoke an alarm beeing sent by opennms
    // to have a status >= Warning
    // INITIALIZE
    LOG.info("Initializing foreign source with no detectors");
    String foreignSourceXML = "<foreign-source name=\"" + OpenNMSSeleniumTestCase.REQUISITION_NAME + "\">\n"
            + "<scan-interval>1d</scan-interval>\n" + "<detectors/>\n" + "<policies/>\n" + "</foreign-source>";
    createForeignSource(REQUISITION_NAME, foreignSourceXML);
    LOG.info("Initializing node with  source with no detectors");
    String requisitionXML = "<model-import foreign-source=\"" + OpenNMSSeleniumTestCase.REQUISITION_NAME + "\">"
            + "   <node foreign-id=\"tests\" node-label=\"192.0.2.1\">"
            + "       <interface ip-addr=\"192.0.2.1\" status=\"1\" snmp-primary=\"N\">"
            + "           <monitored-service service-name=\"ICMP\"/>" + "       </interface>"
            + "       <asset name=\"longitude\" value=\"-0.075949\"/>"
            + "       <asset name=\"latitude\" value=\"51.508112\"/>" + "   </node>" + "</model-import>";
    createRequisition(REQUISITION_NAME, requisitionXML, 1);

    // try every 5 seconds, for 120 seconds, until the service on 127.0.0.2 has been detected as "down", or fail afterwards
    try {/*from   w  w w .  j av  a 2s  .c  om*/
        setImplicitWait(5, TimeUnit.SECONDS);
        new WebDriverWait(m_driver, 120).until(new Predicate<WebDriver>() {
            @Override
            public boolean apply(@Nullable WebDriver input) {
                // refresh page
                input.get(getBaseUrl() + "opennms/index.jsp");

                // Wait until we have markers
                List<WebElement> markerElements = input
                        .findElements(By.xpath("//*[contains(@class, 'leaflet-marker-icon')]"));
                return !markerElements.isEmpty();
            }
        });
    } finally {
        setImplicitWait();
    }
}

From source file:org.openqa.grid.e2e.DemoTmp.java

License:Apache License

@Test(invocationCount = 3, threadPoolSize = 3)
public void test() throws MalformedURLException, InterruptedException {
    WebDriver driver = null;
    try {/*from   w  ww  .  j  a v a  2 s.co m*/
        DesiredCapabilities ff = DesiredCapabilities.firefox();
        driver = new RemoteWebDriver(new URL("http://" + hubIp + ":4444/grid/driver"), ff);
        driver.get("http://" + hubIp + ":4444/grid/console");
        Assert.assertEquals(driver.getTitle(), "Grid overview");
    } finally {
        driver.quit();
    }
}

From source file:org.openqa.grid.e2e.misc.GridViaCommandLineTest.java

License:Apache License

@Test
public void testRegisterNodeToHub() throws Exception {
    String[] hubArgs = { "-role", "hub" };
    GridLauncherV3.main(hubArgs);//from  w w  w .ja  va2  s  .c o  m
    UrlChecker urlChecker = new UrlChecker();
    urlChecker.waitUntilAvailable(10, TimeUnit.SECONDS, new URL("http://localhost:4444/grid/console"));

    String[] nodeArgs = { "-role", "node", "-hub", "http://localhost:4444", "-browser",
            "browserName=chrome,maxInstances=1" };
    GridLauncherV3.main(nodeArgs);
    urlChecker.waitUntilAvailable(100, TimeUnit.SECONDS, new URL("http://localhost:5555/wd/hub/status"));

    WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),
            DesiredCapabilities.chrome());

    try {
        driver.get("http://localhost:4444/grid/console");
        Assert.assertEquals("Should only have one chrome registered to the hub", 1,
                driver.findElements(By.cssSelector("img[src$='chrome.png']")).size());
    } finally {
        try {
            driver.quit();
        } catch (Exception e) {
        }
    }

}

From source file:org.openqa.grid.e2e.misc.Issue1586.java

License:Apache License

@Test(enabled = false)
public void test() throws MalformedURLException {
    DesiredCapabilities ff = DesiredCapabilities.firefox();
    WebDriver driver = null;
    try {/*from w w w.j av a  2s  .  c  om*/
        driver = new RemoteWebDriver(new URL(hub.getUrl() + "/grid/driver"), ff);
        for (int i = 0; i < 20; i++) {
            driver.get("http://code.google.com/p/selenium/");
            WebElement keywordInput = driver.findElement(By.name("q"));
            keywordInput.clear();
            keywordInput.sendKeys("test");
            WebElement submitButton = driver.findElement(By.name("projectsearch"));
            submitButton.click();
            driver.getCurrentUrl(); // fails here
        }
    } finally {
        if (driver != null) {
            driver.quit();
        }
    }
}

From source file:org.openqa.grid.e2e.node.BrowserTimeOutTest.java

License:Apache License

@Test
public void testWebDriverTimesOut() throws InterruptedException, MalformedURLException {
    String url = "http://" + hub.getHost() + ":" + hub.getPort() + "/grid/admin/SlowServlet";
    DesiredCapabilities ff = DesiredCapabilities.firefox();
    WebDriver driver = new RemoteWebDriver(new URL(hub.getUrl() + "/wd/hub"), ff);

    try {// w w w.  jav  a  2 s  . c o m
        driver.get(url);
    } catch (WebDriverException ignore) {
    } finally {
        RegistryTestHelper.waitForActiveTestSessionCount(hub.getRegistry(), 0);
    }
}

From source file:org.openqa.grid.e2e.node.NodeTimeOutTest.java

License:Apache License

@Test
public void webDriverTimesOut() throws InterruptedException, MalformedURLException {
    String url = "http://" + hub.getHost() + ":" + hub.getPort() + "/grid/console";
    DesiredCapabilities ff = DesiredCapabilities.firefox();
    WebDriver driver = new RemoteWebDriver(new URL(hub.getUrl() + "/wd/hub"), ff);
    driver.get(url);
    Assert.assertEquals(driver.getTitle(), "Grid overview");
    TestWaiter.waitFor(new Callable<Integer>() {
        public Integer call() throws Exception {
            Integer i = hub.getRegistry().getActiveSessions().size();
            if (i != 0) {
                return null;
            } else {
                return i;
            }/*w  w w  .java  2s  .  c o m*/
        }
    }, 8, TimeUnit.SECONDS);
    Assert.assertEquals(hub.getRegistry().getActiveSessions().size(), 0);

}

From source file:org.openqa.grid.e2e.node.SmokeTest.java

License:Apache License

@Test
public void firefoxOnWebDriver() throws MalformedURLException {
    WebDriver driver = null;
    try {//from  w ww.j av a  2  s  . com
        DesiredCapabilities ff = DesiredCapabilities.firefox();
        driver = new RemoteWebDriver(new URL(hub.getUrl() + "/wd/hub"), ff);
        driver.get(hub.getUrl() + "/grid/console");
        Assert.assertEquals(driver.getTitle(), "Grid overview");
    } finally {
        if (driver != null) {
            driver.quit();
        }
    }
}

From source file:org.orcid.integration.blackbox.api.OauthAuthorizationPageTest.java

License:Open Source License

@Test
public void stateParamIsPersistentAndReurnedWhenAlreadyLoggedInTest()
        throws JSONException, InterruptedException, URISyntaxException {
    WebDriver webDriver = new FirefoxDriver();
    webDriver.get(webBaseUrl + "/userStatus.json?logUserOut=true");
    webDriver.get(webBaseUrl + "/my-orcid");
    // Sign in//from   w  ww . ja  v  a2  s . c  om
    SigninTest.signIn(webDriver, user1UserName, user1Password);
    // Go to the authroization page
    webDriver.get(String.format(
            "%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s&state=%s", webBaseUrl,
            client1ClientId, SCOPES, client1RedirectUri, STATE_PARAM));
    By userIdElementLocator = By.id("authorize");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
    WebElement authorizeButton = webDriver.findElement(By.id("authorize"));
    authorizeButton.click();
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().equals("ORCID Playground");
        }
    });

    String currentUrl = webDriver.getCurrentUrl();
    Matcher matcher = STATE_PARAM_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String stateParam = matcher.group(1);
    assertFalse(PojoUtil.isEmpty(stateParam));
    assertEquals(STATE_PARAM, stateParam);
    webDriver.close();
}