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

Teardown [AfterFeature] fails in a multi-scenario feature file #2743

Open
dusloth opened this issue Mar 15, 2024 · 0 comments
Open

Teardown [AfterFeature] fails in a multi-scenario feature file #2743

dusloth opened this issue Mar 15, 2024 · 0 comments
Labels

Comments

@dusloth
Copy link

dusloth commented Mar 15, 2024

SpecFlow Version

3.9.74

Which test runner are you using?

NUnit

Test Runner Version Number

4.0.1

.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

TearDown method fails after final scenario is ran in a [BeforeFeature] and [AfterFeature] setup.

  • Step definitions have a single [BeforeScenario] init of Page Objects
    -- Steps class inherits hook class to access driver.Value in steps
  • Works fine using [BeforeScenario] and [AfterScenario] and does the exact same using IWebDriver instead of ThreadLocal

Error

TearDown failed for test fixture ConsoleApp2.Features.TestingThingFeature
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
StackTrace: --TearDown
   at ConsoleApp2.Misc.test.TearDown() in C:\Users\user\source\repos\ConsoleApp2\ConsoleApp2\Misc\test.cs:line 32
   at InvokeStub_Action`1.Invoke(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType hookType)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnFeatureEnd()
   at TechTalk.SpecFlow.TestRunner.OnFeatureEnd()
   at ConsoleApp2.Features.TestingThingFeature.FeatureTearDown()
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Steps to Reproduce

Hook

[Binding]
 internal class test
 {

     public static ThreadLocal<IWebDriver> driver = new ThreadLocal<IWebDriver>();
     //public static IWebDriver driver;

     [BeforeFeature]
     public static void SetUp()
     {
         new DriverManager().SetUpDriver(new ChromeConfig());
         driver.Value = new ChromeDriver();
     }

     [AfterFeature]
     public static void TearDown()
     {
         driver.Value.Close();
         driver.Value.Quit();
     }

 }

Feature File

Feature: TestingThing

@Thingy1
Scenario: Go to SS Fitness and click btn
	Given I navigate to SS Fitness
	And I wait for page load
	When I click the thing button
	Then I verify page changes properly

Scenario: Go to SS Fitness and click btnn1
	Given I navigate to SS Fitness
	And I wait for page load
	When I click the thing button
	Then I verify page changes properly

Link to Repro Project

No response

@dusloth dusloth added the Bug label Mar 15, 2024
@dusloth dusloth changed the title Teardown fails in a multi-scenario feature file Teardown [AfterFeature] fails in a multi-scenario feature file Mar 15, 2024
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

1 participant