From ea2af16765c74c525131e88b2a1511cf364b1193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Standa=20Luke=C5=A1?= Date: Wed, 2 Nov 2022 16:56:59 +0100 Subject: [PATCH] ui tests: avoid stale ements in ApiTests --- src/Samples/Tests/Tests/Feature/ApiTests.cs | 7 ++++--- src/Samples/Tests/Tests/UITestUtils.cs | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Samples/Tests/Tests/Feature/ApiTests.cs b/src/Samples/Tests/Tests/Feature/ApiTests.cs index 2be182d4ec..a28a467c38 100644 --- a/src/Samples/Tests/Tests/Feature/ApiTests.cs +++ b/src/Samples/Tests/Tests/Feature/ApiTests.cs @@ -9,6 +9,7 @@ using Riganti.Selenium.DotVVM; using Xunit; using Xunit.Abstractions; +using static DotVVM.Samples.Tests.UITestUtils; namespace DotVVM.Samples.Tests.Feature { @@ -28,7 +29,7 @@ public void Feature_Api_GetCollection() }, 30000, "Cannot find CompanyID = 11. Probably data are not loaded. (The page did not load in 5s.)"); // ensure that orders have been loaded - WaitForExecutor.WaitFor(() => { + WaitForIgnoringStaleElements(() => { AssertUI.Any(browser.FindElements(".id-order"), waitForOptions: WaitForOptions.Disabled).Attribute("data-order-id", "6"); }); @@ -36,7 +37,7 @@ public void Feature_Api_GetCollection() // delete order (ID = 7) browser.First($".id-order[data-order-id='{idToDelete}'] input[type=button][value=Delete]").Click(); - WaitForExecutor.WaitFor(() => { + WaitForIgnoringStaleElements(() => { AssertUI.Any(browser.FindElements(".id-order"), WaitForOptions.Disabled).Attribute("data-order-id", "6"); AssertUI.All(browser.FindElements(".id-order"), WaitForOptions.Disabled).Attribute("data-order-id", s => s != idToDelete); }); @@ -46,7 +47,7 @@ public void Feature_Api_GetCollection() // ensure that orders have been loaded - WaitForExecutor.WaitFor(() => { + WaitForIgnoringStaleElements(() => { AssertUI.Any(browser.FindElements(".id-order"), WaitForOptions.Disabled).Attribute("data-order-id", "2"); AssertUI.Any(browser.FindElements(".id-order"), WaitForOptions.Disabled).Attribute("data-order-id", "9"); }); diff --git a/src/Samples/Tests/Tests/UITestUtils.cs b/src/Samples/Tests/Tests/UITestUtils.cs index f2b9dcc2cf..01d68f4886 100644 --- a/src/Samples/Tests/Tests/UITestUtils.cs +++ b/src/Samples/Tests/Tests/UITestUtils.cs @@ -1,5 +1,6 @@ using System; using OpenQA.Selenium; +using Riganti.Selenium.Core; namespace DotVVM.Samples.Tests; public static class UITestUtils @@ -21,4 +22,10 @@ public static T StaleElementRetry(Func action, int attempts = 5) } public static void StaleElementRetry(Action action, int attempts = 5) => StaleElementRetry(() => { action(); return 0; }, attempts); + + + public static void WaitForIgnoringStaleElements(Action action, WaitForOptions options = null) + { + WaitForExecutor.WaitFor(() => StaleElementRetry(action), options); + } }