From 0e0875a7ddb9a6f0b76094a33ce3f8348a7b977b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sauli=20T=C3=A4hk=C3=A4p=C3=A4=C3=A4?= Date: Mon, 2 Feb 2015 11:17:50 +0200 Subject: [PATCH] Reduce stability issues with LoadingIndicatorTest. Change-Id: Ia8a9c7cef41a1f7bbd4468d6a2c1cb8eb973ee7a --- .../server/LoadingIndicatorTest.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/LoadingIndicatorTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/LoadingIndicatorTest.java index b122eb02e9..f251313100 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/LoadingIndicatorTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/LoadingIndicatorTest.java @@ -18,7 +18,9 @@ package com.vaadin.tests.components.grid.basicfeatures.server; import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import com.vaadin.testbench.elements.GridElement; @@ -44,11 +46,8 @@ public class LoadingIndicatorTest extends GridBasicFeaturesTest { gridElement.getCell(200, 1); // Wait for loading indicator delay - Thread.sleep(500); - - Assert.assertTrue( - "Loading indicator should be visible when fetching rows that are visible", - isLoadingIndicatorVisible()); + waitUntil(ExpectedConditions.visibilityOfElementLocated(By + .className("v-loading-indicator"))); waitUntilNot(ExpectedConditions.visibilityOfElementLocated(By .className("v-loading-indicator"))); @@ -65,22 +64,29 @@ public class LoadingIndicatorTest extends GridBasicFeaturesTest { isLoadingIndicatorVisible()); // Finally verify that there was actually a request going on - Thread.sleep(2000); + waitUntilLogContains("Requested items"); + } - String firstLogRow = getLogRow(0); - Assert.assertTrue( - "Last log message should be number 6: " + firstLogRow, - firstLogRow.startsWith("6. Requested items")); + private void waitUntilLogContains(final String value) { + waitUntil(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver input) { + return getLogRow(0).contains(value); + } + + @Override + public String toString() { + // Timed out after 10 seconds waiting for ... + return "first log row to contain '" + value + "' (was: '" + + getLogRow(0) + "')"; + } + }); } private boolean isLoadingIndicatorVisible() { WebElement loadingIndicator = findElement(By .className("v-loading-indicator")); - if (loadingIndicator == null) { - return false; - } else { - return loadingIndicator.isDisplayed(); - } + return loadingIndicator.isDisplayed(); } } -- 2.39.5