SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.23k stars 751 forks source link

Hooks async await support #1969

Open xmegacorel opened 4 years ago

xmegacorel commented 4 years ago

It's possible to add support async/await for any kind of Hooks. I have some case to setup specflow tests. 1) I want to start my services in docker-compose env 2) => I have some code that process in loop to ping all services, I have to wait with timeout that all services will startup and give me /version or /healthz good response. So, in brief I have this code: [BeforeTestRun] public static Task BeforeTestRun() { ..... // to check that code below execute only once ..... PermissionService.SetUpAuthorizedUserRoleAsync(FindServiceUrl(Names.PermissionService)).GetAwaiter().GetResult(); }

async Task SetUpAuthorizedUserRoleAsync(..) { // for example var tasks = services.Select(x => checker.CheckAsync(url)).ToList(); await Task.WaitAll(tasks); // if some task fail, test engine don't respond. // but if I change code that: Task.WaitAll(tasks).GetAwaiter().GetResult(); // ok }

SpecFlow Version:

Used Test Runner

Version number: Version=2.4.1

Project Format of the SpecFlow project

.feature.cs files are generated using

Visual Studio Version

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

Are the latest Visual Studio updates installed?

.NET Framework:

Test Execution Method:

<SpecFlow> Section in app.config or content of specflow.json

{
  "bindingCulture": {
    "language": "en-us"
  },
  "language": {
    "feature": "en-us"
  },
  "ApiUrls": [
    {
      "ApiUrl": "http://localhost:5005",
      "DataBaseName": "",
      "Name": "AuthService"
    },
.....
   }
}
eliitzh17 commented 3 years ago

@SabotageAndi Hey, there is any update on the subject?

SabotageAndi commented 3 years ago

No, sadly not.

william-li-ry commented 2 years ago

@SabotageAndi Sorry if this is not related, however does it mean we can't bind an async operation in a [BeforeFeature] hook as well? Thanks

septst commented 1 year ago

@SabotageAndi Sorry if this is not related, however does it mean we can't bind an async operation in a [BeforeFeature] hook as well? Thanks

I am using Specflow.xunit v3.9.74 and am able to use as below

    public static async Task CleanupOnStart()
    {
        await DoSomethingAsync();
        await DoSomethingElseAsync();
    }
Rayzbam commented 1 year ago

Any update ?