Контроль за ходом теста. Кастомные ожидания, попапы, алерты, Iframes.
Ожидания
@Test
public void testExplicitWait()
{
//Go to Sample Application
WebDriver driver = new FirefoxDriver();
driver.get("http://dl.dropbox.com/u/55228056/AjaxDemo.html");
try {
//Get the link for Page 4 and click on it, this will call AJAX code
//for loading the contents for Page 4
WebElement page4button = driver.findElement(By.linkText("Page4"));
page4button.click();
//Create Wait using WebDriverWait.
//This will wait for 5 seconds for timeout before page4 element is found
//Element is found in specified time limit test will move to the text step
//instead of waiting for 10 seconds
//Expected condition is expecting a WebElement to be returned
//after findElement finds the
//element with specified locator
WebElement message = (new WebDriverWait(driver, 5))
.until(new ExpectedCondition<WebElement>(){
@Override
public WebElement apply(WebDriver d) {
return d.findElement(By.id("page4"));
}});
assertTrue(message.getText().contains("Nunc nibh tortor"));
} catch (NoSuchElementException e) {
fail("Element not found!!");
e.printStackTrace();
} finally {
driver.close();
}
}Работа с alert окнами
Фреймы
Last updated