From 35b80ea7c48e59fd8700608d63949253d90fc7d6 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 20 Sep 2022 08:30:54 +0300 Subject: [PATCH 1/2] test: Make test more stable --- .../ui/push/AbstractClientServerCounterIT.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/flow-tests/test-root-ui-context/src/test/java/com/vaadin/flow/uitest/ui/push/AbstractClientServerCounterIT.java b/flow-tests/test-root-ui-context/src/test/java/com/vaadin/flow/uitest/ui/push/AbstractClientServerCounterIT.java index 240a58179de..858a80e3f92 100644 --- a/flow-tests/test-root-ui-context/src/test/java/com/vaadin/flow/uitest/ui/push/AbstractClientServerCounterIT.java +++ b/flow-tests/test-root-ui-context/src/test/java/com/vaadin/flow/uitest/ui/push/AbstractClientServerCounterIT.java @@ -2,6 +2,8 @@ import org.junit.Test; import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedCondition; @@ -45,9 +47,13 @@ protected WebElement getServerCounterStartButton() { } public static int getServerCounter(TestBenchTestCase t) { - WebElement serverCounterElem = t - .findElement(By.id(ClientServerCounterUI.SERVER_COUNTER_ID)); - return Integer.parseInt(serverCounterElem.getText()); + try { + WebElement serverCounterElem = t.findElement( + By.id(ClientServerCounterUI.SERVER_COUNTER_ID)); + return Integer.parseInt(serverCounterElem.getText()); + } catch (StaleElementReferenceException | NoSuchElementException e) { + return getServerCounter(t); + } } public static WebElement getServerCounterStartButton(TestBenchTestCase t) { From 0026bb3f3c052b330a8929855b1308e2efa9a344 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 20 Sep 2022 09:03:27 +0300 Subject: [PATCH 2/2] Limit the number of attempts --- .../push/AbstractClientServerCounterIT.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/flow-tests/test-root-ui-context/src/test/java/com/vaadin/flow/uitest/ui/push/AbstractClientServerCounterIT.java b/flow-tests/test-root-ui-context/src/test/java/com/vaadin/flow/uitest/ui/push/AbstractClientServerCounterIT.java index 858a80e3f92..a25dd4892f1 100644 --- a/flow-tests/test-root-ui-context/src/test/java/com/vaadin/flow/uitest/ui/push/AbstractClientServerCounterIT.java +++ b/flow-tests/test-root-ui-context/src/test/java/com/vaadin/flow/uitest/ui/push/AbstractClientServerCounterIT.java @@ -2,9 +2,8 @@ import org.junit.Test; import org.openqa.selenium.By; -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedCondition; @@ -47,13 +46,18 @@ protected WebElement getServerCounterStartButton() { } public static int getServerCounter(TestBenchTestCase t) { - try { - WebElement serverCounterElem = t.findElement( - By.id(ClientServerCounterUI.SERVER_COUNTER_ID)); - return Integer.parseInt(serverCounterElem.getText()); - } catch (StaleElementReferenceException | NoSuchElementException e) { - return getServerCounter(t); + WebDriverException lastException = null; + for (int i = 0; i < 10; i++) { + try { + WebElement serverCounterElem = t.findElement( + By.id(ClientServerCounterUI.SERVER_COUNTER_ID)); + return Integer.parseInt(serverCounterElem.getText()); + } catch (WebDriverException e) { + lastException = e; + } } + + throw lastException; } public static WebElement getServerCounterStartButton(TestBenchTestCase t) {