Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Ewan88 opened this issue Dec 7, 2023 · 1 comment
Labels

Comments

@Ewan88
Copy link

Ewan88 commented Dec 7, 2023

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

@Ewan88 Ewan88 added the Bug label Dec 7, 2023
@ajeckmans
Copy link

ajeckmans commented Feb 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants