Closed gkalnytskyi closed 2 years ago
@gkalnytskyi I noticed this in my PR: https://github.com/SpecFlowOSS/SpecFlow/pull/2579 which should resolve this issue
@rossmasday , I'll double check after the release. Thank you.
Confirmed fixed in v3.9.74. Haven't checked other versions between v3.9.22 and v3.9.74.
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.
SpecFlow Version
3.9.22
Which test runner are you using?
NUnit
Test Runner Version Number
4.0.0
.NET Implementation
.NET 5.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
N/A
Issue Description
I am trying to figure out why
Dispose()
method ofIDisposable
is not executed after scenario has completed when Autofac is used as DI container for Specflow (with Specflow.Autofac package). This causes Chrome Driver process to keep running even after execution of scenario has completed.This behavior only happens when
BrowserDriver
class (as described in Specflow documentation) is registered asSingleInstance()
in container builder method (see). On the other hand,Dispose
is invoked and Chrome Driver is successfully closed whenBrowserDriver
is registered asInstancePerLifeTimeScope
.My observations tell me that new container builder is created for each of the scenarios, also Autofac documentation states that it should be calling
Dispose()
method when theIDisposable
dependency is no longer in use (see). So, there shouldn't be any notable differences betweenSingleInstance()
andInstancePerLifetimeScope()
in context of Specflow.The other point is that Specflow documentation recommends using
SingleInstance()
lifetime for step classes, which might "force" people to make lifetime ofBrowserDriver
also to beSingleInstance()
, as it would be captured anyway, thus causing the number of chromedriver processes to multiply.Am I misunderstanding anything about
IDisposable
pattern, lifetimes, Autofac container behavior, or Specflow.Autofac registration?Steps to Reproduce
See attached repository with project to reproduce (
DriverLifetime
tag has the most succinct example).BrowserDriver
class asSingleInstance()
.chromedriver.exe
process is still running.Link to Repro Project
https://github.com/gkalnytskyi/BrowserStackDemoTest