Skip to content

Commit

Permalink
ui tests: avoid stale ements in ApiTests
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Nov 2, 2022
1 parent 9aafca0 commit ea2af16
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Samples/Tests/Tests/Feature/ApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Riganti.Selenium.DotVVM;
using Xunit;
using Xunit.Abstractions;
using static DotVVM.Samples.Tests.UITestUtils;

namespace DotVVM.Samples.Tests.Feature
{
Expand All @@ -28,15 +29,15 @@ 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");
});

var idToDelete = browser.FindElements(".id-order")[2].GetAttribute("data-order-id"); // every order has two elements (read-only and edit)

// 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);
});
Expand All @@ -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");
});
Expand Down
7 changes: 7 additions & 0 deletions src/Samples/Tests/Tests/UITestUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using OpenQA.Selenium;
using Riganti.Selenium.Core;

namespace DotVVM.Samples.Tests;
public static class UITestUtils
Expand All @@ -21,4 +22,10 @@ public static T StaleElementRetry<T>(Func<T> 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);
}
}

0 comments on commit ea2af16

Please sign in to comment.