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:com.qulix.ft.teachingSite.Conditions.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
 *//*from  w  w  w .  ja  va2s .co m*/
public static ExpectedCondition<Boolean> titleIs(final String title) {
    return new ExpectedCondition<Boolean>() {
        private String currentTitle = "";

        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.qulix.ft.teachingSite.Conditions.ExpectedConditions.java

License:Apache License

/**
 * An expectation for checking that the title contains a case-sensitive
 * substring//from   w ww.j ava2s  . c o  m
 *
 * @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 = "";

        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);
        }
    };
}

From source file:com.redhat.darcy.webdriver.internal.WindowTitleWebDriverTargetTest.java

License:Open Source License

@Test
public void shouldTargetAWindowWhichExactlyMatchesTitle() {
    WebDriverTarget target = WebDriverTargets.windowByTitle("foo");
    WebDriver found = target.switchTo(locator);

    assertThat(found.getTitle(), is("foo"));
}

From source file:com.redhat.darcy.webdriver.internal.WindowTitleWebDriverTargetTest.java

License:Open Source License

@Test
public void shouldKeepFindingTheSameWindowEvenIfItsTitleLaterChanges() {
    WebDriverTarget target = WebDriverTargets.windowByTitle("foo");

    WebDriver found = target.switchTo(locator);
    assertThat(found.getTitle(), is("foo"));

    when(fooWindow.getTitle()).thenReturn("no longer foo");

    WebDriver foundAgain = target.switchTo(locator);
    assertThat(foundAgain.getTitle(), is("no longer foo"));
}

From source file:com.safeway.app.appcert.smoketester.SmokeTester.java

@Test
public void executeSmokeTest() throws Exception {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.

    System.setProperty("webdriver.chrome.driver", "C:\\Nino\\ChromeWebDriver\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    TestCaseReader tcreader = new TestCaseReader();
    List<TestScriptTemplate> tcl = tcreader.readExcel();

    List<TestScriptTemplate> validatedTestScript = new ArrayList();

    String log_execution = "";
    Iterator<TestScriptTemplate> i = tcl.iterator();
    while (i.hasNext()) {
        TestScriptTemplate testscript = i.next();
        //collect the results
        TestScriptTemplate testexecution = new TestScriptTemplate();

        testexecution.setAppCode(testscript.getAppCode());
        log_execution = log_execution + " Start smoke testing for application code: "
                + testexecution.getAppCode();

        //access the URL
        driver.get(testscript.getAppURL());

        //login if not yet
        if (driver.getCurrentUrl().contains("identity.safeway.com")) {
            //key in userid and password
            WebElement weusername = driver.findElement(By.id("username"));
            //System.out.println("tag:" + weusername.getTagName());
            weusername.sendKeys(testscript.getAppUserID());

            WebElement wepassword = driver.findElement(By.id("password"));
            //System.out.println("tag:" + wepassword.getTagName());
            wepassword.sendKeys(testscript.getAppPassword());

            WebElement weloginform = driver.findElement(By.name("loginData"));
            //System.out.println("tag:" + weloginform.getTagName());
            weloginform.submit();//from w ww.  j av a2 s .co m
        }

        //recoding URL; required so no need to check for nullity
        testexecution.setAppURL(driver.getCurrentUrl());
        log_execution = log_execution + " Current URL: " + driver.getCurrentUrl();

        //recoding title; required so no need to check for nullity
        testexecution.setHomePageTitle(driver.getTitle());
        log_execution = log_execution + " Login Successful";
        log_execution = log_execution + " Page Title: " + driver.getTitle();

        if (isElementExist(testscript.getHomePageElementType(), testscript.getHomePageElement(), driver)) {
            System.out.println("Element match!" + testscript.getHomePageElement());
            log_execution = log_execution + " Home Page Element validation...";
            testexecution.setHomePageElement(testscript.getHomePageElement());
        } else {
            testexecution.setHomePageElement("not found");
        }

        //next page validation
        if (!testscript.getLevel1URL().isEmpty() || !testscript.getLevel1URL().equals("")) {
            //go to next level page
            driver.get(testscript.getLevel1URL());
            log_execution = log_execution + " Next Page validation URL: " + testscript.getLevel1URL();

            testexecution.setLevel1URL(driver.getCurrentUrl());
            System.out.println("execution log: current level 1 URL on set" + testexecution.getLevel1URL());

            if (!testscript.getLevel1PageTitle().isEmpty() || !testscript.getLevel1PageTitle().equals("")) {
                testexecution.setLevel1PageTitle(driver.getTitle());
                log_execution = log_execution + " Next Page title validation: " + driver.getTitle();
            }

            if (isElementExist(testscript.getLevel1ElementType(), testscript.getLevel1Element(), driver)) {
                testexecution.setLevel1Element(testscript.getLevel1Element());
                log_execution = log_execution + " Next Page element validation: "
                        + testscript.getLevel1Element();
            } else {
                testexecution.setLevel1Element("not found");
            }

        }
        testexecution.setLogs(log_execution);
        System.out.println("Execution Log: " + log_execution);
        log_execution = "";
        SmokeTestValidator testvalidator = new SmokeTestValidator(testscript);
        TestScriptTemplate testingresult = testvalidator.getTestResult(testexecution);
        validatedTestScript.add(testingresult);

    }

    tcreader.writetoExcel(validatedTestScript);
    //Close the browser
    driver.quit();
    //return log_execution;
}

From source file:com.saucelabs.sauce_ondemand.driver.SauceOnDemandTest.java

License:Open Source License

public void testWebDriver() throws IOException, InterruptedException {
    WebDriver s = SeleniumFactory.createWebDriver(
            "sauce-ondemand:?max-duration=30&os=Linux&browser=firefox&browser-version=3.",
            "http://www.google.com/");
    assertEquals("Google", s.getTitle());

    SauceOnDemandSelenium ss = (SauceOnDemandSelenium) s;
    assertNotNull(ss.getSessionIdValue());
    WebDriver augmentedDriver = new Augmenter().augment(s);
    File screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
    ss.jobPassed();/*from w  ww .j a v a 2 s  .co m*/
    s.quit();

    Thread.sleep(15000);

    System.out.println(ss.getSeleniumServerLogFile());
    System.out.println(ss.getVideo());
    IOUtils.copy(ss.getSeleniumServerLogFileInputStream(), System.out);
}

From source file:com.saucelabs.selenium.client.embedded_rc.EmbeddedSeleniumRCTest.java

License:Open Source License

public void testWebDriver() {
    WebDriver s = SeleniumFactory.createWebDriver("embedded-rc:*firefox", "http://www.google.com/");
    assertEquals("Google", s.getTitle());
    s.quit();/*from  w w  w . j  a  v  a 2s. com*/
}

From source file:com.saucelabs.selenium.client.htmlunit.HtmlUnitTest.java

License:Open Source License

public void testWebDriver() {
    WebDriver s = SeleniumFactory.createWebDriver("htmlunit:", "http://www.google.com/");
    assertEquals("Google", s.getTitle());
    s.quit();/*from ww  w.  j  a  v a2  s . c om*/
}

From source file:com.saucelabs.selenium.client.logging.LoggingSeleniumTest.java

License:Open Source License

public void testWebDriver() {
    WebDriver s = SeleniumFactory.createWebDriver("log:embedded-rc:*firefox", "http://www.google.com/");

    LoggingSelenium ls = (LoggingSelenium) s;
    Logger l = Logger.getAnonymousLogger();
    ls.setLogger(l);//  w  ww .j  a va 2 s.com
    l.addHandler(new Handler() {
        @Override
        public void publish(LogRecord record) {
            logs.add(record);
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    });

    s.get("http://www.google.com/");
    assertEquals("Google", s.getTitle());
    s.quit();

    verifyLog();
}

From source file:com.sios.stc.coseng.test.Base.java

License:Open Source License

public void acceptSslCertificate(final WebDriver webDriver) throws InterruptedException {
    // For Internet Explorer
    if (!browser.equals(Browser.FIREFOX) || !browser.equals(Browser.CHROME)) {
        final Boolean title = webDriver.getTitle().equals("Certificate Error: Navigation Blocked");
        final int count = webDriver.findElements(By.id("overridelink")).size();
        if (title && (count == 1)) {
            final WebElement overrideLink = webDriver.findElement(By.id("overridelink"));
            if (overrideLink.isDisplayed()) {
                new Actions(driver).moveToElement(overrideLink).click().build().perform();
            }/* www  .  j  ava  2 s .com*/
        }
    }
}