Added RetryFactAttribute

This commit is contained in:
2025-11-15 23:04:37 +01:00
parent 07aaf468a8
commit 72b0ecf04f
6 changed files with 56 additions and 7 deletions

View File

@@ -42,7 +42,7 @@ public class AssetsPageTests : IDisposable
css.ForEach(selector => _driver.FindElement(By.CssSelector(selector)));
}
[Fact]
[RetryFact(5)]
public void AssetsPage_ShouldCreateAndShowDetailAndUpdateAndDeleteAsset()
{
AppHelper.Login(_driver);

View File

@@ -40,7 +40,7 @@ public class GroupsPageTests : IDisposable
css.ForEach(selector => _driver.FindElement(By.CssSelector(selector)));
}
[Fact]
[RetryFact(5)]
public void GroupsPage_ShouldCreateAndUpdateAndDeleteGroup()
{
string randomName = $"RESERVED_TEST_{AppHelper.GetRandomName()}";

View File

@@ -33,7 +33,7 @@ public class InventoryPageTests : IDisposable
_driver.FindElement(By.Id("scanBarcodeButton"));
}
[Fact]
[RetryFact(5)]
public void InventoryPage_ShouldShowCompleteViewModal()
{
AppHelper.Login(_driver);
@@ -62,7 +62,7 @@ public class InventoryPageTests : IDisposable
Assert.NotEmpty(_driver.FindElement(By.Id("detailPurchaseBy")).GetAttribute("value") ?? "");
}
[Fact]
[RetryFact(5)]
public void InventoryPage_ShouldShowSuccessToastOnInformationCorrect()
{
AppHelper.Login(_driver);
@@ -79,7 +79,7 @@ public class InventoryPageTests : IDisposable
Assert.True(AppHelper.TryRetryFindSuccessToast(_driver));
}
[Fact]
[RetryFact(5)]
public void InventoryPage_ShouldShowSuccessToastOnInformationUpdate()
{
AppHelper.Login(_driver);

View File

@@ -40,7 +40,7 @@ public class LocationsPageTests : IDisposable
css.ForEach(selector => _driver.FindElement(By.CssSelector(selector)));
}
[Fact]
[RetryFact(5)]
public void LocationsPage_ShouldCreateAndUpdateAndDeleteGroup()
{
string randomName = $"RESERVED_LOCATION_{AppHelper.GetRandomName()}";

View File

@@ -0,0 +1,49 @@
using System;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Berufsschule_HAM.E2ETests;
[XunitTestCaseDiscoverer("YourNamespace.RetryFactDiscoverer", "YourAssemblyName")]
public class RetryFactAttribute(int maxRetries = 5) : FactAttribute
{
public int MaxRetries { get; } = maxRetries;
}
public class RetryTestCase : XunitTestCase
{
private int _maxRetries;
[Obsolete("Called by the de-serializer", true)]
public RetryTestCase() { }
public RetryTestCase(int maxRetries, ITestMethod testMethod)
: base(new NullMessageSink(), TestMethodDisplay.Method, TestMethodDisplayOptions.None, testMethod)
{
_maxRetries = maxRetries;
}
public override async Task<RunSummary> RunAsync(
IMessageSink diagnosticMessageSink,
IMessageBus messageBus,
object[] constructorArguments,
ExceptionAggregator aggregator,
CancellationTokenSource cancellationTokenSource)
{
var summary = new RunSummary();
for (int i = 1; i <= _maxRetries; i++)
{
var result = await base.RunAsync(
diagnosticMessageSink, messageBus, constructorArguments, aggregator, cancellationTokenSource);
summary.Aggregate(result);
if (result.Failed == 0)
break; // success, stop retrying
}
return summary;
}
}

View File

@@ -42,7 +42,7 @@ public class UsersPageTests : IDisposable
css.ForEach(selector => _driver.FindElement(By.CssSelector(selector)));
}
[Fact]
[RetryFact(5)]
public void UsersPage_ShouldCreateAndShowDetailAndUpdateAndDeleteUser()
{
AppHelper.Login(_driver);