From 685e4487932f53890057d1e9a69f3d2e484eb0bd Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Fri, 20 Dec 2019 11:18:03 +0200 Subject: [PATCH] Test tweaks (#11851) * Test tweaks Less fixed waiting times when there are ways to check that the operation has been performed. This will hopefully improve the stability a bit. * Merge branch 'master' into updateTests20191218 --- .../grid/GridEditorFrozenColumnsUITest.java | 2 +- .../upload/InterruptUploadTest.java | 48 +++++++++++-------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUITest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUITest.java index 34ef8847c2..23a747c4ea 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUITest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUITest.java @@ -22,7 +22,7 @@ public class GridEditorFrozenColumnsUITest extends MultiBrowserTest { openTestURL(); openEditor(10); - sleep(500); + waitForElementPresent(By.className("v-grid-editor")); compareScreen("noscroll"); scrollGridHorizontallyTo(100); diff --git a/uitest/src/test/java/com/vaadin/tests/components/upload/InterruptUploadTest.java b/uitest/src/test/java/com/vaadin/tests/components/upload/InterruptUploadTest.java index 8e1d0ba7b3..3d791bd4b8 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/upload/InterruptUploadTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/upload/InterruptUploadTest.java @@ -7,19 +7,19 @@ import java.io.IOException; import org.junit.Test; import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.internal.WrapsElement; import org.openqa.selenium.remote.LocalFileDetector; import org.openqa.selenium.remote.RemoteWebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; +import com.vaadin.testbench.elements.ButtonElement; import com.vaadin.testbench.elements.LabelElement; import com.vaadin.testbench.elements.WindowElement; import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.tests.util.LoremIpsum; -import static org.junit.Assert.assertTrue; - public class InterruptUploadTest extends MultiBrowserTest { private static final String EXPECTED_COUNTER_TEXT = " (counting interrupted at "; @@ -29,36 +29,42 @@ public class InterruptUploadTest extends MultiBrowserTest { openTestURL(); File tempFile = createTempFile(); - scheduleUploadCancel(); - fillPathToUploadInput(tempFile.getPath()); - // Wait for 3 seconds until everything is done. - Thread.sleep(3000); - - String actual = $(LabelElement.class).caption("Line breaks counted") - .first().getText(); - assertTrue("Line break count note does not match expected (was: " - + actual + ")", actual.contains(EXPECTED_COUNTER_TEXT)); + waitForElementPresent(By.className("v-window")); + $(ButtonElement.class).caption("Cancel").first().click(); + waitUntilInterruptionRegistered(); $(WindowElement.class).first().close(); waitForElementNotPresent(By.className("v-window")); // Check if second upload happens tempFile = createTempFile(); - scheduleUploadCancel(); fillPathToUploadInput(tempFile.getPath()); - actual = $(LabelElement.class).caption("Line breaks counted").first() - .getText(); - assertTrue("Line break count note does not match expected (was: " - + actual + ")", actual.contains(EXPECTED_COUNTER_TEXT)); + waitForElementPresent(By.className("v-window")); + $(ButtonElement.class).caption("Cancel").first().click(); + waitUntilInterruptionRegistered(); } - private void scheduleUploadCancel() { - // Schedule upload cancel in 2 seconds - ((JavascriptExecutor) getDriver()).executeScript( - "setTimeout( function () {window.document.querySelector(\".v-window .v-button\").click()},2000)"); + private void waitUntilInterruptionRegistered() { + waitUntil(new ExpectedCondition() { + String actual; + + @Override + public Boolean apply(WebDriver arg0) { + actual = $(LabelElement.class).caption("Line breaks counted") + .first().getText(); + return actual.contains(EXPECTED_COUNTER_TEXT); + } + + @Override + public String toString() { + // Expected condition failed: waiting for ... + return "line break count note to mention interruption (was: " + + actual + ")"; + } + }); } /** -- 2.39.5