Add more waits

This commit is contained in:
Marty30 2017-06-25 15:39:03 +02:00
parent b544ab80bd
commit c9d54ba6b8
4 changed files with 5 additions and 7 deletions

View file

@ -6,7 +6,6 @@ import org.junit.experimental.categories.Category;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.net.MalformedURLException;
@ -31,17 +30,17 @@ public class AddOwnerIT extends SeleniumBaseIT {
fillTextField(By.name("city"), "Enschede");
fillTextField(By.name("telephone"), "0534890000");
driver.findElement(By.name("telephone")).submit();
waitForPageToLoad();
Assert.assertTrue(pageContainsText("Sophie Lathouwers"));
//Add a pet
new WebDriverWait(driver, 3).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.linkText("Add New Pet")));
waitFor(ExpectedConditions.presenceOfAllElementsLocatedBy(By.linkText("Add New Pet")));
driver.findElement(By.linkText("Add New Pet")).click();
fillTextField(By.name("name"), "Thumper");
fillTextField(By.name("birthDate"), "1942/08/09");
new Select(driver.findElement(By.name("type"))).selectByValue("hamster");
driver.findElement(By.name("name")).submit();
waitFor(new FixedPeriod(1000));
waitForPageToLoad();
Assert.assertTrue("Could not locate \"Thumper\" on the page. This is the html of the current page: "+getHTML(),pageContainsText("Thumper"));
setTestFinished();

View file

@ -24,13 +24,13 @@ public class AddVisitIT extends SeleniumBaseIT {
driver.get(BASE_URL+"/owners/find");
driver.findElement(By.name("lastName")).submit();
waitFor(new FixedPeriod(1000));
waitForPageToLoad();
//Go to first owner
WebElement table = driver.findElement(By.tagName("table"));
List<WebElement> cells = table.findElements(By.xpath(".//tr/td"));
cells.get(0).findElement(By.xpath("a")).click();
waitForPageToLoad();
//Go to edit page of first pet
driver.findElement(By.xpath("//table//tr/td/table/tbody//a[contains(text(),'Edit')]")).click();
@ -39,7 +39,6 @@ public class AddVisitIT extends SeleniumBaseIT {
fillTextField(By.name("name"), "foobar");
driver.findElement(By.name("name")).submit();
waitFor(new FixedPeriod(1000));
waitForPageToLoad();
Assert.assertNotNull(driver.findElement(By.xpath("//table//tr/td/dl/dd[contains(text(), 'foobar')]")));

View file

@ -23,7 +23,6 @@ public class FindOwnerIT extends SeleniumBaseIT {
driver.get(BASE_URL+"/owners/find");
fillTextField(By.name("lastName"),"Coleman");
driver.findElement(By.name("lastName")).submit();
waitFor(new FixedPeriod(1000));
waitForPageToLoad();
Assert.assertTrue("Could not find \"Jean Coleman\" on the current page. This is the html of the current page: "+getHTML(),driver.findElements(By.xpath("//*[text()='Jean Coleman']")).size() == 1);
setTestFinished();

View file

@ -62,10 +62,11 @@ public class SeleniumBaseIT {
}
protected void waitForPageToLoad() {
waitFor(new FixedPeriod(333));
waitFor(new PageLoadedExpectedCondition());
}
protected void waitFor(ExpectedCondition<Boolean> condition) {
protected void waitFor(ExpectedCondition<?> condition) {
new WebDriverWait(driver, 3).until(condition);
}