Backend/e-suite.Automation.UITests/ESuite.UI.E2E/Helpers/RetryHelper.cs
2026-01-20 21:50:10 +00:00

28 lines
851 B
C#

namespace ESuite.UI.E2E.Helpers
{
public class RetryHelper
{
public static void Retry(Action action, int maxRetries = 3, int delayInMilliseconds = 1500)
{
int attempts = 0;
while (true)
{
try
{
attempts++;
action();
return;
}
catch (Exception ex)
{
if (attempts >= maxRetries)
throw new Exception($"Action failed after {maxRetries} retries.", ex);
Console.WriteLine($"Attempt {attempts} failed: {ex.Message}. Retrying in {delayInMilliseconds}ms...");
Thread.Sleep(delayInMilliseconds);
}
}
}
}
}