Trumpf.Coparoo.Waiting is a .NET library for C# that provides intuitive waiting methods for automated tests. This core library includes Wait, TryWait, and SilentWaiter for polling conditions with configurable timeouts. Cross-platform compatible. For Windows Forms-based visual dialogs, use the Trumpf.Coparoo.Waiting.WinForms package.
$ dotnet add package Trumpf.Coparoo.WaitingTrumpf.Coparoo.Waiting is a .NET library for C# that simplifies the process of waiting for conditions in automated tests. It provides a visual dialog to indicate the current state of the condition being evaluated, making it easier for testers to understand what is happening during test execution. The dialog will display in different colors to indicate whether the condition is true, false, or requires manual intervention.
You can install the package via NuGet:
dotnet add package Trumpf.Coparoo.Waiting
You can use the ConditionDialog.For() method to wait for a condition to become true. It displays a dialog showing the condition's state.
ConditionDialog.For(() => true, "Condition is true", TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(100));
This will wait until the condition is true or the timeout is reached. The dialog will show the current state of the condition (red for false, green for true).
If the condition is false when the timeout is reached, a WaitForTimeoutException will be thrown with a descriptive message.
try
{
ConditionDialog.For(() => false, "Condition is false", TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(100));
}
catch (WaitForTimeoutException ex)
{
Console.WriteLine(ex.Message); // Will print the timeout message
}
For tests that require manual intervention (e.g., user approval), the dialog will show grey with instructions:
ConditionDialog.For(() => false, "Manual intervention required", TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(100));
You can repeat the condition check for a number of iterations, making it easy to track ongoing changes:
Enumerable.Range(0, 50).ToList().ForEach(_ =>
ConditionDialog.For(() => true, "Repeated condition check", TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(100))
);
The library includes a series of tests to validate its functionality, including:
Basic Test: Wait until a condition is true, then continue.
[Test]
public void IfTheConditionIsTrue_ThenNoExceptionIsThrown()
{
ConditionDialog.For(() => true, "Condition is true", TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(100));
}
Timeout Test: Timeout occurs if the condition remains false.
[Test]
public void IfTheConditionIsFalse_ExceptionIsThrown_WithExceptionMessage()
{
Assert.Throws<WaitForTimeoutException>(() =>
{
ConditionDialog.For(() => false, "Condition is false", TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(100));
});
}
Manual Intervention Test: Show a grey dialog for user intervention.
[Test]
public void IfTheConditionRequiresManualIntervention_ThenGreyDialogIsShown()
{
ConditionDialog.For(() => false, "Manual intervention required", TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(100));
}
Feel free to submit pull requests or report issues via the GitHub repository. Contributions are welcome!
This library is licensed under the Apache License, Version 2.0. See the LICENSE file for more information.