SmartWait 2.2.0.5

dotnet add package SmartWait --version 2.2.0.5
                    
NuGet\Install-Package SmartWait -Version 2.2.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SmartWait" Version="2.2.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SmartWait" Version="2.2.0.5" />
                    
Directory.Packages.props
<PackageReference Include="SmartWait" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SmartWait --version 2.2.0.5
                    
#r "nuget: SmartWait, 2.2.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SmartWait@2.2.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SmartWait&version=2.2.0.5
                    
Install as a Cake Addin
#tool nuget:?package=SmartWait&version=2.2.0.5
                    
Install as a Cake Tool

SmartWait

Each SmartWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions whilst waiting

NuGet.org Nuget Build status .NET Actions Status

Installation

Install with NuGet Package Manager Console
Install-Package SmartWait
Install with .NET CLI
dotnet add package SmartWait

Example:

WaitFor.Condition(waitCondition, timeoutMessage);
                     
WaitFor.Condition(waitCondition, builder=>builder
                                   .SetMaxWaitTime(maxWaitTime)
                                   .SetCallbackForSuccessful(callback)
                                   .SetNotIgnoredExceptionType(notIgnoredExceptionType)
                                   .Build(), timeoutMessage);
                                   
 static async Task<bool> Expected()
 {
     await Task.Delay(TimeSpan.FromSeconds(1));
     return true;
 }
 
 await WaitFor.Condition(Expected, DefaultTimeOutMessage, timeLimit);
 
In case when you use WaitFor.Condition if the given condition is not met will be rise exception

Screenshot

In case when some exceptions happen and we got not expected value we can read information about a number of exceptions and where it happened

Screenshot

In case when you use WaitFor.For this function wait until the specified condition is met and return the value that we expected. To do this, you must specify the actions in case of failure using the method OnFailure

 var result = WaitFor.For(() => 0)
                .Become(a => a == 5)
                .OnFailure(_ => 1, fail => fail is NotExpectedValue<int>)
                .OnFailure(_ => -2);
                
 //asynchronous option         
  var result = WaitFor.ForAsync(async () =>
     {
         await Task.Delay(10);
         return 0;
     })
     .Become(a => a == 5)
     .OnFailure(_ => 1, fail => fail is NotExpectedValue<int>)
     .OnFailure(_ => -2);                

Using the OnSuccess method, you can specify actions on the value in case of a successful result

var res = WaitFor.For(() => actual).Become(a => a == 3)
              .OnSuccess(x => $"New result {x}")
              .OnFailureThrowException();
// "New result 3"
Result On Failure can be in two cases:
  • get not expected value
    • returns NotExpectedValue<T> type.
  • due to some exceptions
    • returns ExceptionsHappened type.

We have methods that can help to handle these cases:

  • WhenNotExpectedValue and DoWhenNotExpectedValue
  • WhenWasExceptions and DoWhenWasExceptions
 var res = WaitFor.For(() => 3)
               .Become(a => a == 4)
               .WhenNotExpectedValue(x => x.ActuallyValue)
               .OnFailure(_ => 0);
Console.WriteLine(res) //3

 WaitFor.For(() => 3)
               .Become(a => a == 4)
               .DoWhenNotExpectedValue(x => Console.WriteLine(x))
               .OnFailure(_ => 0);
//  Console output :
//  Timeout after 30.6826992 second(s) and NUMBER OF ATTEMPTS 17 
//  Expected: (a) => a == 4, but parameter 'a': 3

var testClass = new SomeClass
{
    SomeNumber = 3,
    Child = new OtherClass
    {
       SomeNumber = 5
    }
};

_ = WaitFor.For(() => testClass)
     .Become(a => a.Child.SomeNumber == 1 && a.SomeNumber == 3)
     .DoWhenNotExpectedValue(x => Console.WriteLine(x));
/*  Console output :      
   Timeout after 30.6749663 second(s) and NUMBER OF ATTEMPTS 17 
   Expected: (a) => a.Child.SomeNumber(5) == 1 && a.SomeNumber(3) == 3
*/

If you use OnFailureThrowException , exception will be throw with next message

await WaitFor.ForAsync(Expected)
              .Become(a => a.Child.SomeNumber == 1 && a.SomeNumber == 3)
              .OnFailureThrowException();

Screenshot

You can use the predefined algorithm like LogarithmStep and ParabolaStep which calculate delay steps
var res = WaitFor.For(() => actual,
                  w => w.SetLogarithmStep(Time.FromSeconds).Build())
                 .Become(a => a == 3)
                 .OnFailureThrowException();
Also, you can use your custom algorithm for delayed steps
var res = WaitFor.For(() => actual, 
                      b => b.SetTimeBetweenStep(retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
                     .Build())
                     .Become(a => a == 5);
For additional information look in Tests Cases
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SmartWait:

Package Downloads
VF.Serenity.AutomationFramework

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.0.5 55 2/27/2026
2.2.0.4 47 2/27/2026
2.2.0.3 53 2/27/2026
2.2.0.2 160,803 11/5/2021
2.2.0.1 11,926 7/22/2021
2.2.0 624 7/20/2021
2.0.0.7 593 6/30/2021
2.0.0.6 3,795 4/22/2021
2.0.0.5 688 1/13/2021
2.0.0.4 641 1/8/2021
2.0.0.3 703 1/8/2021
2.0.0.2 676 1/8/2021
2.0.0.1 632 1/8/2021
1.1.0 66,293 4/15/2020
1.0.9 8,311 12/27/2019
1.0.8 1,683 8/8/2019
1.0.7 772 8/8/2019
1.0.5 819 8/6/2019
1.0.4 802 8/5/2019
1.0.3 815 8/5/2019
Loading failed

update packages