@Test public void titleShouldReturnWindowTitle() { WebDriver d = getDriver(); d.get("http://docs.wpm.neustar.biz/testscript-api/index.html"); assertEquals("__MAIN_FRAME__", getCurrentFrameName(d)); String topLevelTitle = d.getTitle(); d.switchTo().frame("packageFrame"); assertEquals("packageFrame", getCurrentFrameName(d)); assertEquals(topLevelTitle, d.getTitle()); d.switchTo().defaultContent(); assertEquals(topLevelTitle, d.getTitle()); }
public static void main(String[] args) { String baseUrl = "http://newtours.demoaut.com/"; WebDriver driver = new FirefoxDriver(); String underConsTitle = "Under Construction: Mercury Tours"; // Creates result string driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get(baseUrl); List<WebElement> linkElements = driver.findElements(By.tagName("a")); // Creates lists from <a> tags String[] linkTexts = new String[linkElements.size()]; int i = 0; // extract the link texts of each link element for (WebElement e : linkElements) { linkTexts[i] = e.getText(); i++; } // test each link by looping over them for (String t : linkTexts) { driver.findElement(By.linkText(t)).click(); if (driver.getTitle().equals(underConsTitle)) { System.out.println("\"" + t + "\"" + " is under construction."); } else { System.out.println( "\"" + t + "\"" // print results to console + " is working."); } driver.navigate().back(); } driver.quit(); }
@Test public void shouldSwitchBackToMainFrameIfLinkInFrameCausesTopFrameReload() throws Exception { WebDriver d = getDriver(); String expectedTitle = "Unique title"; d.get("http://localhost:2310/common/frameset.html"); assertEquals(expectedTitle, d.getTitle()); d.switchTo().frame(0); d.findElement(By.linkText("top")).click(); // Wait for new content to load in the frame. expectedTitle = "XHTML Test Page"; WebDriverWait wait = new WebDriverWait(d, 10); wait.until(ExpectedConditions.titleIs(expectedTitle)); assertEquals(expectedTitle, d.getTitle()); WebElement element = d.findElement(By.id("amazing")); assertNotNull(element); }
protected boolean isBrowserStillOpen(WebDriver webDriver) { try { webDriver.getTitle(); return true; } catch (UnreachableBrowserException e) { log.log(FINE, "Browser is unreachable", e); return false; } catch (NoSuchWindowException e) { log.log(FINE, "Browser window is now found", e); return false; } catch (SessionNotFoundException e) { log.log(FINE, "Browser session is not found", e); return false; } }
public static void main(String[] args) throws Exception { DesiredCapabilities capabillities = DesiredCapabilities.firefox(); capabillities.setCapability("version", "8"); capabillities.setCapability("platform", Platform.WINDOWS); WebDriver driver = new RemoteWebDriver( new URL( "http://*****:*****@hub.testingbot.com:4444/wd/hub"), capabillities); driver.get("http://www.google.com"); WebElement search = driver.findElement(By.name("q")); search.sendKeys("Hello, WebDriver"); search.submit(); System.out.println(driver.getTitle()); driver.quit(); }
/** * Return the title of the page * * @return */ public String title() { return driver.getTitle(); }
@Test public void titleShouldBeHelloWorld() throws Exception { driver.get(baseUrl); assertEquals("Hello world", driver.getTitle()); }