Trumpf.Coparoo.Waiting
1.2.0
dotnet add package Trumpf.Coparoo.Waiting --version 1.2.0
NuGet\Install-Package Trumpf.Coparoo.Waiting -Version 1.2.0
<PackageReference Include="Trumpf.Coparoo.Waiting" Version="1.2.0" />
paket add Trumpf.Coparoo.Waiting --version 1.2.0
#r "nuget: Trumpf.Coparoo.Waiting, 1.2.0"
// Install Trumpf.Coparoo.Waiting as a Cake Addin #addin nuget:?package=Trumpf.Coparoo.Waiting&version=1.2.0 // Install Trumpf.Coparoo.Waiting as a Cake Tool #tool nuget:?package=Trumpf.Coparoo.Waiting&version=1.2.0
Trumpf.Coparoo.Waiting
Trumpf.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.
Features
- Polls conditions and shows a visual waiting dialog.
- Red dialog indicates a false condition.
- Green dialog indicates a true condition.
- Grey dialog for manual intervention (e.g., safety-critical acknowledgements).
- Supports automatic and semi-automated testing.
- Improves test analysis and video clarity by showing real-time feedback.
Installation
You can install the package via NuGet:
dotnet add package Trumpf.Coparoo.Waiting
Usage
Waiting for a Condition
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).
Handling Timeout and Exceptions
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
}
Example with Manual Intervention
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));
Repeating Conditions
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))
);
Test Cases
The library includes a series of tests to validate its functionality, including:
- Positive cases: Waiting until the condition is true without errors.
- Negative cases: Testing conditions where the timeout is exceeded or the condition is null/false.
- Manual interventions: Using the grey dialog to prompt the user for actions.
- Nested waits: Handling conditions with multiple nested waiting dialogs.
Example Test Cases
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)); }
Contributing
Feel free to submit pull requests or report issues via the GitHub repository. Contributions are welcome!
License
This library is licensed under the Apache License, Version 2.0. See the LICENSE file for more information.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0-windows7.0 is compatible. |
.NET Framework | net451 is compatible. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.5.1
- No dependencies.
-
net8.0-windows7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.