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:ch.heigvd.amt.uat.selenium.pages.AccountRegistrationPage.java

public AccountRegistrationPage(WebDriver driver) {
    super(driver);
    if (!"Registration Page".equals(driver.getTitle())) {
        throw new IllegalStateException("This is not the correct page");
    }/*from w ww  .j  av  a2s.  c  o m*/

}

From source file:ch.heigvd.amt.uat.selenium.pages.YourAppPage.java

public YourAppPage(WebDriver driver) {
    super(driver);

    // Check that we're on the right page.
    if (!"Your apps".equals(driver.getTitle())) {
        throw new IllegalStateException("This is not the correct page");
    }/*from   ww w.  ja  v a 2s.c o m*/
}

From source file:com.actian.amc.pages.NewCloudDefinitionPage.java

public NewCloudDefinitionPage(WebDriver driver) {
    super(driver);
    // Check that we're on the right page.
    if (!"Actian Management Console".equals(driver.getTitle())) {
        throw new IllegalStateException("This is not the AMC login page.");
    }//from  w  w  w .j a  v a 2 s. c o  m
}

From source file:com.amazon.alexa.avs.AVSApp.java

License:Open Source License

/**
 * Performs amazon LWA login using the given <tt>driver</tt>.
 * /*  w  w  w  . j ava  2s.  c  o m*/
 * @param driver Driver which is already configured to LWA login page.
 */
private void authenticate(final WebDriver driver) {
    log.debug("Title : {}", driver.getTitle());
    new WebDriverWait(driver, 1000)
            .until(ExpectedConditions.and(ExpectedConditions.presenceOfElementLocated(By.id("ap_email")),
                    ExpectedConditions.presenceOfElementLocated(By.id("ap_password"))));
    log.info("Auto logging in to LWA");
    final WebElement username = driver.findElement(By.id("ap_email"));
    final WebElement password = driver.findElement(By.id("ap_password"));
    username.sendKeys(deviceConfig.getLWAUsername());
    password.sendKeys(deviceConfig.getLWAPassword());
    final WebElement button = driver.findElement(By.tagName("button"));
    button.click();
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.NavigateSelenium.java

License:Apache License

/**
 * {@inheritDoc}/*ww  w  .  ja va2  s .c om*/
 */
@Override
public INavigateSelenium navigateToWindowByPartialTitle(String title) {
    try {
        WebDriver popup;
        Iterator<String> windowIterator = driver.getWindowHandles().iterator();
        while (windowIterator.hasNext()) {
            String windowHandle = windowIterator.next();
            popup = driver.switchTo().window(windowHandle);
            if (popup.getTitle().contains(title)) {
                break;
            }
        }
        logger.debug("navigateToWindowByPartialTitle : Navigated to window by:" + title);

    } catch (NoSuchWindowException nswe) {
        logger.error("navigateToWindowByPartialTitle : No Window found");
        throw new NoSuchWindowException("navigateToWindowByPartialTitle : No Window found");

    }
    return this;
}

From source file:com.booleanworks.kryptopterus.selenium.testsuite001.BaseWelcomePageTest.java

@Test
@Ignore/*  ww  w .  ja  va  2 s  .c  om*/
public void testSimple() throws Exception {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("phantomjs.page.settings.userAgent",
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36");
    capabilities.setCapability("phantomjs.page.settings.localToRemoteUrlAccessEnabled", true);
    capabilities.setCapability("phantomjs.page.settings.browserConnectionEnabled", true);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
            "/usr/local/bin/phantomjs");
    capabilities.setCapability("takesScreenshot", true);

    WebDriver driver = new PhantomJSDriver((Capabilities) capabilities);
    driver.manage().window().setSize(new Dimension(1200, 800));
    driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);

    // And now use this to visit NetBeans
    driver.get("http://localhost:8084/kryptopterus/");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.netbeans.org");

    // Check the title of the page
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return d.getTitle().contains("NetBeans");
        }
    });

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

From source file:com.cloudbees.test.SeleniumTest.java

License:Apache License

private void testSeleniumDriver(WebDriver webDriver) {
    System.err.println("");
    System.err.println("#############################");
    System.err.println("# TEST WITH " + webDriver);
    System.err.println("#############################");
    try {//from  w w w . ja  va 2  s  .c  o  m
        String url = "https://google.com";
        webDriver.get(url);
        Assert.assertEquals("Unexpected page title requesting " + url + " with selenium driver "
                + webDriver.toString() + " displaying " + webDriver.getCurrentUrl(), "Google",
                webDriver.getTitle());
        System.err.println("SUCCESSFULLY invoked Selenium driver" + webDriver.toString() + " with URL "
                + webDriver.getCurrentUrl() + ", page.title='" + webDriver.getTitle() + "'");
    } finally {
        webDriver.close();
        webDriver.quit();
    }
}

From source file:com.comcast.magicwand.drivers.AbstractPhoenixDriver.java

License:Apache License

/**
 * {@inheritDoc}/* w  w  w .  j  a  v  a2s  .c  o m*/
 */
public String getTitle() {
    WebDriver driver = this.getDriver();
    String title = null;

    if (null != driver) {
        title = driver.getTitle();
    }

    return title;
}

From source file:com.common.ExpectedConditions.java

License:Apache License

/**
 * An expectation for checking the title of a page.
 *
 * @param title the expected title, which must be an exact match
 * @return true when the title matches, false otherwise
 *///  w w w .  ja  va  2  s  . c  o m
public static ExpectedCondition<Boolean> titleIs(final String title) {
    return new ExpectedCondition<Boolean>() {
        private String currentTitle = "";

        @Override
        public Boolean apply(WebDriver driver) {
            currentTitle = driver.getTitle();
            return title.equals(currentTitle);
        }

        @Override
        public String toString() {
            return String.format("title to be \"%s\". Current title: \"%s\"", title, currentTitle);
        }
    };
}

From source file:com.common.ExpectedConditions.java

License:Apache License

/**
 * An expectation for checking that the title contains a case-sensitive
 * substring/*from  www.j ava2 s  .  com*/
 *
 * @param title the fragment of title expected
 * @return true when the title matches, false otherwise
 */
public static ExpectedCondition<Boolean> titleContains(final String title) {
    return new ExpectedCondition<Boolean>() {
        private String currentTitle = "";

        @Override
        public Boolean apply(WebDriver driver) {
            currentTitle = driver.getTitle();
            return currentTitle != null && currentTitle.contains(title);
        }

        @Override
        public String toString() {
            return String.format("title to contain \"%s\". Current title: \"%s\"", title, currentTitle);
        }
    };
}