Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does SpecFlow testing platform support async Tasks?

Async/Await support for Specflow Steps => I would like to use SpecFlow with the Async Await Features of C#, windows phone 8, SpecFlow with MSTest can execute Code using async / await but doesn't wait for the Results.

I've changed BindingInvoker.cs and upgraded to .NET 4, in order to support async tasks, and receiving now IOC is not initialized errors.

https://github.com/robfe/SpecFlow/commit/507368327341e71b2f5e2a4a1b7757e0f4fb809d

like image 807
Tootim Avatar asked Feb 16 '14 08:02

Tootim


People also ask

Can a test method be async?

It's permissible for an async method to return void, but it's not recommended because it's very difficult to consume (or test) an async void method. The task instance returned from an async method is managed by the state machine.

What is async task in asp net?

In general, you should make a method asynchronous if the synchronous method blocks the ASP.NET request thread while doing no work. By making the call asynchronous, the ASP.NET request thread is not blocked doing no work while it waits for the web service request to complete.

Should async method return task?

For methods other than event handlers that don't return a value, you should return a Task instead, because an async method that returns void can't be awaited. Any caller of such a method must continue to completion without waiting for the called async method to finish.


1 Answers

Yes. SpecFlow does support async steps
See https://docs.specflow.org/projects/specflow/en/latest/Bindings/Asynchronous-Bindings.html
For example:

[When(@"I want to get the web page '(.*)'")]
public async Task WhenIWantToGetTheWebPage(string url)
{
    await _webDriver.HttpClientGet(url);
}

It will not continue to the next step until this step was finished but it will release the thread to perform other tests

like image 141
Liraz Shay Avatar answered Dec 06 '22 15:12

Liraz Shay