Specflow: Async / Await support

Created on 29 Jan 2016  Â·  22Comments  Â·  Source: SpecFlowOSS/SpecFlow

Hey guys,

I see that async/ await was added some time ago. Discussion is in issue #257 . Apparently, the modifications made with #287 have been removed by commit 8725c0B on Jan 26,2016

Was there a reason behind this change?

Feature-Request

Most helpful comment

Ups, we forgot to add this to the changelog.
2.2 has async/await support included.

We will update the information.

All 22 comments

We've upgraded to Specflow v2 just so that we could have access to these changes... I was wondering why methods that exposed Task still didn't work!

A lot of our code is using async/await and also many of the HTTP libraries only expose Async methods now. I think this is a key feature for any modern testing framework.

This is an issue for us as well, I was surprised to see the issue in v2 as I was sure I'd seen it working in v1.9 but had upgraded for the parallel test handling.

likewise - this is essential and it definitely used to work

Same desire here, the following code passed with the v2 NuGet when it should have failed:

[Then(@"nothing really happens")]
        public Task ThenNothingReallyHappens()
        {
            return Task.Run(() =>
            {
                Console.WriteLine("Starting then nothing happens at " + DateTime.Now);
                Thread.Sleep(TimeSpan.FromSeconds(2));
                Assert.Fail("Oops, something happened");
            });            
        }

As @gasparnagy and I created the 2.0 release, we looked at the changes from #287.
We came to the conclussion, that it does not handle all cases (particular at the exception handling). At least there could be more tests for it.
So we did not merged it into the 2.0 release.

I also think this is a needed feature, but at least I didn't had the time yet to complete it.
So if someone wants to contribute an implementation, we are happy to see a new PR for it.

I found this thread as I tried to use async/await with SpecFlow and then discovered that it doesn't work!

@ocsurfnut - is your branch ready for a PR?

It would be great to have this supported :-)

@stuartleeks it was pulled into the master a couple weeks ago -> https://github.com/techtalk/SpecFlow/pull/647 . I'm assuming it should be in the next SpecFlow release.

@ocsurfnut @stuartleeks yes, it will be included in the next release. You can access the interim builds from the CI NuGet feed: https://ci.appveyor.com/nuget/specflow-ci

That's great news. Any idea roughly when the next release will be?

:-)

@stuartleeks good question, but I think it will be sometime in September...

Hi @gasparnagy - since it's around mid-September, I thought I'd check back to see what the ETA is for async/await? :-)

@stuartleeks
We added first support for async/await with PR https://github.com/techtalk/SpecFlow/pull/647.
To use this, you have to use the nugets from our CI- feed.

Feedback if everything works or something is missing in the support would be appreciate.

Hello.
Async supprоt does not work in SpecFlow 2.1.0.0 at all. This specs should throw InvalidOperationException but they do not.

Async.feature

Feature: Async specs

Scenario: Result is async Task 
    When result is async Task

Scenario: Result is Task
    When result is Task

AsyncSteps.cs

``` C#
[Binding]
public class AsyncSteps
{
[When(@"result is async Task")]
public async Task WhenResultIsAsyncTask()
{
// Failure
await Task.Run(() =>
{
throw new InvalidOperationException();
});
}

    [When(@"result is Task")]
    public Task WhenResultIsTask()
    {
        // Failure
        return Task.Run(() =>
        {
            throw new InvalidOperationException();
        });
    }
}

```

It seems to be fixed in 2.2.0-preview,
I tested the following

        [Then(@"it fails asynchronously")]
        public async Task ThenItFailsAsynchronously()
        {
            Assert.Fail();
        }

and it passes in 1.19 & 2.1 but it fails in 2.2.0-preview :)

Any idea when the 2.2.0 stable NuGet will be available?

@aberbegall No, there is no plan when we will release 2.2.
There are still some changes open that I want to get into it.

But there is no problem to use the preview until then..

SpecFlow 2.2 was released on Tuesday.
http://specflow.org/2017/specflow-2-2-0-released/

Hi @SabotageAndi ,
Is included in the SpecFlow 2.2 the support for Async / Await operations commented here? The notes in http://specflow.org/2017/specflow-2-2-0-released/ doesnt mention anything about this issue number ;-)

Many thanks!

Ups, we forgot to add this to the changelog.
2.2 has async/await support included.

We will update the information.

Greetings from 2018. There doesn't seem to be any documentation saying that async/await is supported. I'm trying to get it working but it's failing and I don't know if it's my code or not.

https://specflow.org/documentation/Step-Definition-Styles/

Doesn't have any async/await examples. Google searching only leads me to GitHub PRs / feature requests but no published examples of it working.

Thanks. Maybe someone could add an example to the documentation. I've been using Specflow for years and no one on any of my teams knew that It supported async/await.

Matt

On 1 May 2018, at 17:14, Andreas Willich notifications@github.com wrote:

Did you had a look at the feature files?
https://github.com/techtalk/SpecFlow/blob/master/Tests/TechTalk.SpecFlow.Specs/Features/AsyncSupport.feature

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings