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.22k stars 751 forks source link

ScenarioContext.Current gives obsolete warning but does not offer alternative #2729

Open Ewan88 opened 6 months ago

Ewan88 commented 6 months ago

SpecFlow Version

3.9.74

Which test runner are you using?

NUnit

Test Runner Version Number

3.13.3

.NET Implementation

.NET 6.0

Project Format of the SpecFlow project

Sdk-style project format

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

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

No response

Issue Description

Consider the following code.

    [AfterStep]
    public static async Task TearDown()
    {
#pragma warning disable CS0618 // Type or member is obsolete
      if (ScenarioContext.Current.TestError != null)
      {
        Console.WriteLine("Failed");
      }
#pragma warning restore CS0618 // Type or member is obsolete
    }
  }

I am trying to trigger a function as a test has failed.

I can reach the console log succesfully when a test fails, however I am presented with a warning that refers to a piece of documentation - that documentation does not exist when I search for it.

Steps to Reproduce

See description.

Using ScenarioContext.Current gives a warning despite working as intended.

Link to Repro Project

No response

ajeckmans commented 4 months ago

See https://docs.specflow.org/projects/specflow/en/latest/Bindings/ScenarioContext.html#migrating-from-scenariocontext-current

With SpecFlow 3.0, we marked ScenarioContext.Current obsolete, to make clear that you that you should avoid using these properties in future. The reason for moving away from these properties is that they do not work when running scenarios in parallel.

The obsolete message contains (ScenarioContext.cs:29) a link "Please get the ScenarioContext via Context Injection - https://go.specflow.org/Migrate-ScenarioContext-Current" which for me correctly redirects to the link I posted above.