Example usage for org.openqa.selenium WebDriver getTitle

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

Introduction

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

Prototype

String getTitle();

Source Link

Document

Get the title of the current page.

Usage

From source file:org.mitre.mpf.wfm.ui.NodesAndProcessPage.java

License:Open Source License

public static boolean ValidNodeManagerPage(WebDriver driver) {
    log.info("Current Title:" + driver.getTitle());
    List<WebElement> h2s = driver.findElements(By.xpath("//h2"));
    boolean valid = false;
    for (WebElement ele : h2s) {
        log.info("h2:" + ele.getText());
        if (ele.getText().startsWith("Cluster participants as of")) {
            valid = true;/*from w  w  w .j av  a 2s  .c  om*/
            break;
        }
    }
    return valid;
}

From source file:org.mitre.mpf.wfm.ui.UploadMediaPage.java

License:Open Source License

public static boolean ValidPage(WebDriver driver) {
    log.debug("Current Title:" + driver.getTitle() + "  Desired:" + PAGE_TITLE);
    return driver.getTitle().startsWith(PAGE_TITLE) && driver.getCurrentUrl().contains(PAGE_URL)
            && Utils.checkIDExists(driver, "fileManager");
}

From source file:org.nsesa.editor.gwt.an.it.SeleniumIT.java

License:EUPL

public static void main(String[] args) {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://localhost:8080/editor/amendment.html?documentID=1");
    final String title = driver.getTitle();
    new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
        @Override/*from   ww  w  .  j av a  2  s.c o m*/
        public Boolean apply(WebDriver input) {
            return input.getTitle().toLowerCase().contains("document 1");
        }
    });
    Assert.assertEquals("Document 1 - Nsesa Editor", driver.getTitle());
    driver.quit();
}

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

License:Educational Community License

/**
 * Start playing a new episode. //from www.j  ava2s. c o m
 */
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.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  w  w .ja v  a  2s  . c  o 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.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);/* ww w  .java2s.  c o m*/
    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;
            }
        }
    }, 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 {// w ww  .j a va2s.  c  om
        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.api.common.WebDriverHelper.java

License:Open Source License

public String obtainAuthorizationCode(String scopes, String orcid, String userId, String password,
        boolean isLoggedIn) throws InterruptedException {
    String url = String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, orcid, scopes, redirectUri);
    webDriver.get(url);//  w w  w .j ava  2 s .  c  om

    if (!isLoggedIn) {
        // Switch to the login form
        try {
            By switchFromLinkLocator = By.id("in-register-switch-form");
            (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
                    .until(ExpectedConditions.presenceOfElementLocated(switchFromLinkLocator));
            WebElement switchFromLink = webDriver.findElement(switchFromLinkLocator);
            switchFromLink.click();
        } catch (Exception e) {
            System.out.println("Unable to load URL: " + url);
            e.printStackTrace();
            throw e;
        }

        // Fill the form
        By userIdElementLocator = By.id("userId");
        (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
                .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
        WebElement userIdElement = webDriver.findElement(userIdElementLocator);
        userIdElement.sendKeys(userId);
        WebElement passwordElement = webDriver.findElement(By.id("password"));
        passwordElement.sendKeys(password);
        WebElement submitButton = webDriver.findElement(By.id("authorize-button"));
        submitButton.click();
    } else {
        By authorizeBtn = By.id("authorize");
        (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
                .until(ExpectedConditions.presenceOfElementLocated(authorizeBtn));
        WebElement btn = webDriver.findElement(authorizeBtn);
        btn.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 = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String authorizationCode = matcher.group(1);
    assertNotNull(authorizationCode);
    return authorizationCode;
}

From source file:org.orcid.api.common.WebDriverHelper.java

License:Open Source License

public String obtainAuthorizationCodeWhenAlreadySignedIn(String scopes, String orcid)
        throws InterruptedException {
    webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, orcid, scopes, redirectUri));

    By authorizeButtonLocator = ByName.name("authorize");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(authorizeButtonLocator));
    WebElement submitButton = webDriver.findElement(authorizeButtonLocator);
    submitButton.click();/*  ww w .j  av a  2 s  . c  o  m*/

    (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 = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String authorizationCode = matcher.group(1);
    assertNotNull(authorizationCode);
    return authorizationCode;
}

From source file:org.orcid.api.common.WebDriverHelper.java

License:Open Source License

public String obtainAuthorizationCode(String scopes, String orcid, String userId, String password,
        List<String> inputIdsToCheck, boolean markAsSelected) throws InterruptedException {
    webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, orcid, scopes, redirectUri));

    // Switch to the login form
    By switchFromLinkLocator = By.id("in-register-switch-form");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(switchFromLinkLocator));
    WebElement switchFromLink = webDriver.findElement(switchFromLinkLocator);
    switchFromLink.click();//from ww w .j a  va  2 s  . com

    // Check the given inputs
    if (inputIdsToCheck != null && !inputIdsToCheck.isEmpty()) {
        for (String id : inputIdsToCheck) {
            By input = By.id(id);
            (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
                    .until(ExpectedConditions.presenceOfElementLocated(input));
            WebElement inputElement = webDriver.findElement(input);
            if (markAsSelected) {
                if (!inputElement.isSelected())
                    inputElement.click();
            } else {
                if (inputElement.isSelected())
                    inputElement.click();
            }
        }
    }

    // Fill the form
    By userIdElementLocator = By.id("userId");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
    WebElement userIdElement = webDriver.findElement(userIdElementLocator);
    userIdElement.sendKeys(userId);
    WebElement passwordElement = webDriver.findElement(By.id("password"));
    passwordElement.sendKeys(password);
    WebElement submitButton = webDriver.findElement(By.id("authorize-button"));
    submitButton.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 = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String authorizationCode = matcher.group(1);
    assertNotNull(authorizationCode);
    return authorizationCode;
}