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.alfresco.po.share.FactorySharePage.java

License:Open Source License

/**
 * Creates the appropriate page object based on the current page the {@link WebDriver} is on.
 *
 * @param driver WebDriver Alfresco unmanned web browser client
 * @return SharePage the page object response
 * @throws PageException//  ww  w .j  a v a 2  s .co m
 */
public HtmlPage resolvePage(final WebDriver driver) throws PageException {
    // Determine if user is logged in if not return login page
    // if (driver.getTitle().toLowerCase().contains(driver.getLanguageValue("login.title")))
    if (driver.getTitle().toLowerCase().contains("login")) {
        return instantiatePage(driver, LoginPage.class);
    } else {
        // Share Error PopUp
        try {
            WebElement errorPrompt = driver.findElement(By.cssSelector(FAILURE_PROMPT));
            if (errorPrompt.isDisplayed()) {
                return instantiatePage(driver, SharePopup.class);
            }
        } catch (NoSuchElementException nse) {
        }

        // Check for Share Dialogue
        try {
            WebElement shareDialogue = driver.findElement(By.cssSelector(SHARE_DIALOGUE));
            if (shareDialogue.isDisplayed() || !driver.findElements(COPY_MOVE_DIALOGUE_SELECTOR).isEmpty()) {
                HtmlPage response = resolveShareDialoguePage(driver);
                if (response != null) {
                    return response;
                }
            }
        } catch (NoSuchElementException n) {
        }

        // Determine what page we're on based on url
        return getPage(driver.getCurrentUrl(), driver);
    }
}

From source file:org.arquillian.drone.browserstack.webdriver.BrowserStackMethodTest.java

License:Apache License

@Test
public void browserTest(@Drone final WebDriver driver) {

    driver.get("http://www.google.com/ncr");
    Graphene.waitGui().until().element(queryElement).is().visible();

    queryElement.sendKeys("BrowserStack");
    queryElement.submit();/*from   w  w  w  .  j  a  va2s  .co m*/

    Graphene.waitModel().withTimeout(5, TimeUnit.SECONDS).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver notUsed) {
            return "BrowserStack - Google Search".equals(driver.getTitle());
        }
    });
    System.out.println(driver.getTitle());

}

From source file:org.bigtester.ate.model.asserter.PagePropertyCorrectnessAsserter.java

License:Apache License

/**
 * {@inheritDoc}//from  ww  w.j a  va2s  .c  o  m
 */
@Override
public void assertER() {

    WebDriver webDriver = getResultPage().getMyWd().getWebDriver();// NOPMD
    if (null == webDriver) {
        throw new IllegalStateException("webDriver is not correctly populated.");
    }
    for (int i = 0; i < stepERValue.getValue().size(); i++) {
        StepErPageProperty sErPP = stepERValue.getValue().get(i);
        if (sErPP.getTestDataContext().getContextFieldValue()
                .equalsIgnoreCase(AssertType.PAGE_PROPERTY_CORRECTNESS)) {
            String assertProperty = sErPP.getAssertProperty();
            boolean correctFlag;
            if (PagePropertyType.COOKIE.equalsIgnoreCase(assertProperty)) {

                Cookie cki = new Cookie(sErPP.getAssertValue(), sErPP.getAssertValue());
                if (webDriver.manage().getCookies().contains(cki)) {
                    correctFlag = true;

                } else {
                    correctFlag = false;
                }
            } else if (PagePropertyType.PAGE_TITLE.equalsIgnoreCase(assertProperty)) {
                if (webDriver.getTitle().equals(sErPP.getAssertValue())) {
                    correctFlag = true;

                } else {
                    correctFlag = false;

                }
            } else {
                correctFlag = true;
            }
            if (correctFlag) {
                ItemCompareResult icr = new ItemCompareResult(sErPP.getAssertProperty(), sErPP.getAssertValue(),
                        EnumAssertResult.PAGEPROPERTYCORRECT.toString(), sErPP.getAssertPriority(),
                        EnumAssertResult.PAGEPROPERTYCORRECT);
                getExecResult().getComparedItemResults().put(sErPP.getIdColumn(), icr);
                super.appendAssertReportMSG(icr);
            } else {
                ItemCompareResult icr = new ItemCompareResult(sErPP.getAssertProperty(), sErPP.getAssertValue(),
                        EnumAssertResult.PAGEPROPERTYNOTCORRECT.toString(), sErPP.getAssertPriority(),
                        EnumAssertResult.PAGEPROPERTYNOTCORRECT);
                getExecResult().getComparedItemResults().put(sErPP.getIdColumn(), icr);
                getExecResult().getFailedItemResults().put(sErPP.getIdColumn(), icr);
                EnumAssertPriority failPriority = getStepERValue().getValue().get(i).getAssertPriority();
                if (failPriority.equals(EnumAssertPriority.HIGH)) {
                    setFlagFailCase(true);
                }
                super.appendAssertReportMSG(icr);
            }
        }
    }
}

From source file:org.craftercms.cstudio.share.selenium.basic.CStudioSeleniumUtil.java

License:Open Source License

public static boolean switch_to_window(WebDriver driver, String window) {
    Set<String> handles = driver.getWindowHandles();
    for (String h : handles) {
        driver.switchTo().window(h);/* ww w.j  av  a  2 s. c om*/
        if (driver.getTitle().equals(window))
            break;
    }
    return driver.getTitle().equals(window);
}

From source file:org.craftercms.cstudio.share.selenium.basic.SaveAndPreviewTest.java

License:Open Source License

private void test_save_and_preview(WebDriver driver) {
    // Login//from w  w  w .j a  va2  s .c  o m
    CStudioSeleniumUtil.try_login(driver, CStudioSeleniumUtil.MANAGER_USER,
            CStudioSeleniumUtil.MANAGER_PASSWORD, true);

    // Navigate to Dashboard
    CStudioSeleniumUtil.navigate_to_dashboard(driver);

    // Edit 'index' page
    CStudioSeleniumUtil.edit_index_page(driver);

    // Switch to 'Entry' window
    CStudioSeleniumUtil.switch_to_window(driver, "Entry");

    // Open 'Sliders'
    WebElement element = driver.findElement(By.linkText("Sliders"));
    element.click();

    // Change slider caption
    CStudioSeleniumUtil.wait_until_displayed(driver, CStudioSeleniumUtil.SHORT_TIMEOUT,
            By.id("accordion$sliders$xf-567$caption$textarea-counted1"));
    element = driver.findElement(By.id("accordion$sliders$xf-567$caption$textarea-counted1"));
    element.clear();
    element.sendKeys("To remain competitive and functioning at peak efficiency, organizations like "
            + "yours can't afford to waste valuable resources on outdated, inefficient, or improperly<br/>"
            + "implemented communications equipment. - Updated");

    // Preview changes
    element = driver.findElement(By.id("formPreviewButton"));
    element.click();

    // Switch to 'Crafter Studio' window
    CStudioSeleniumUtil.switch_to_window(driver, "Crafter Studio");

    // Wait for the preview to load
    new WebDriverWait(driver, CStudioSeleniumUtil.LONG_TIMEOUT).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().startsWith("Acme Demo");
        }
    });

    // Verify changes
    assertTrue(driver.getTitle().startsWith("Acme Demo"));

    // Close driver
    CStudioSeleniumUtil.exit(driver);
}

From source file:org.jboss.arquillian.graphene.context.TestGrapheneProxyHandler.java

License:Open Source License

@Test
public void test_webDriver_methods_which_should_not_return_proxy() {
    IsNotProxyable isNotProxyable = new IsNotProxyable();

    // when/*  www .  j a va 2s .  c o m*/
    WebDriver driver = Mockito.mock(WebDriver.class, isNotProxyable);
    Options options = mock(Options.class, isNotProxyable);
    Navigation navigation = mock(Navigation.class, isNotProxyable);
    ImeHandler ime = mock(ImeHandler.class, isNotProxyable);
    Logs logs = mock(Logs.class, isNotProxyable);

    // then
    try {
        driver.toString();
        driver.close();
        driver.equals(new Object());
        driver.get("");
        driver.getClass();
        driver.getCurrentUrl();
        driver.getPageSource();
        driver.getTitle();
        driver.getWindowHandle();
        driver.hashCode();
        driver.quit();
        driver.toString();

        options.addCookie(mock(Cookie.class));
        options.deleteAllCookies();
        options.deleteCookie(mock(Cookie.class));
        options.deleteCookieNamed("");
        options.getCookieNamed("");

        navigation.back();
        navigation.forward();
        navigation.to("");
        navigation.to(new URL("http://localhost/"));

        ime.activateEngine("");
        ime.deactivate();
        ime.getActiveEngine();
        ime.isActivated();

        logs.get("");

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    assertEquals(Arrays.asList(), isNotProxyable.getViolations());
}

From source file:org.jboss.arquillian.graphene.ftest.enricher.selenium.TestSeleniumResourceProvider.java

License:Open Source License

@Test
public void testWebDriver(@ArquillianResource WebDriver driver) {
    assertEquals("Sample Page", driver.getTitle());
}

From source file:org.keycloak.testsuite.forms.SSOTest.java

License:Open Source License

@Test
public void multipleSessions() {
    loginPage.open();/*  ww  w . j  a va 2 s. com*/
    loginPage.login("test-user@localhost", "password");

    Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
    Assert.assertNotNull(oauth.getCurrentQuery().get(OAuth2Constants.CODE));

    Event login1 = events.expectLogin().assertEvent();

    WebDriver driver2 = WebRule.createWebDriver();
    try {
        OAuthClient oauth2 = new OAuthClient(driver2);
        oauth2.state("mystate");
        oauth2.doLogin("test-user@localhost", "password");

        Event login2 = events.expectLogin().assertEvent();

        Assert.assertEquals(RequestType.AUTH_RESPONSE, RequestType.valueOf(driver2.getTitle()));
        Assert.assertNotNull(oauth2.getCurrentQuery().get(OAuth2Constants.CODE));

        assertNotEquals(login1.getSessionId(), login2.getSessionId());

        oauth.openLogout();
        events.expectLogout(login1.getSessionId()).assertEvent();

        oauth.openLoginForm();

        assertTrue(loginPage.isCurrent());

        oauth2.openLoginForm();

        events.expectLogin().session(login2.getSessionId()).removeDetail(Details.USERNAME).assertEvent();
        Assert.assertEquals(RequestType.AUTH_RESPONSE, RequestType.valueOf(driver2.getTitle()));
        Assert.assertNotNull(oauth2.getCurrentQuery().get(OAuth2Constants.CODE));

        oauth2.openLogout();
        events.expectLogout(login2.getSessionId()).assertEvent();

        oauth2.openLoginForm();

        assertTrue(driver2.getTitle().equals("Log in to test"));
    } finally {
        driver2.close();
    }
}

From source file:org.lunifera.example.vaadin.osgi.testpart.TextFieldPartTest.java

License:Apache License

@Test
public void test() {
    WebDriver driver = new FirefoxDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.google.com");

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the
    // element/*from   w w w. j  ava 2 s.  c o m*/
    element.submit();

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    // Should see: "cheese! - Google Search"
    System.out.println("Page title is: " + driver.getTitle());

    // Close the browser
    driver.quit();
}

From source file:org.mitre.mpf.wfm.ui.CreateJobPage.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, "jobPipelineSelectServer");
}