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

Dependencies generated from factories are not disposed #1025

Open
6 of 18 tasks
42shadow42 opened this issue Feb 13, 2018 · 2 comments
Open
6 of 18 tasks

Dependencies generated from factories are not disposed #1025

42shadow42 opened this issue Feb 13, 2018 · 2 comments

Comments

@42shadow42
Copy link

42shadow42 commented Feb 13, 2018

SpecFlow Version:

  • 2.2
  • 2.1
  • 2.0
  • 1.9

Used Test Runner

  • SpecFlow+Runner
  • MSTest
  • NUnit
  • Xunit

Version number:

Visual Studio Version

  • VS 2017
  • VS 2015
  • VS 2013

Are the latest Visual Studio updates installed?

  • Yes
  • No

.NET Framework:

  • >= .NET 4
  • before .NET 4

Test Execution Method:

  • Visual Studio Test Explorer
  • TFS/VSTS – Task – PLEASE SPECIFY THE NAME OF THE TASK
  • Command line – PLEASE SPECIFY THE FULL COMMAND LINE

<SpecFlow> Section in app.config

    <specFlow>
        <unitTestProvider name="MsTest" />
        <plugins>
            <add name="AutomationFramework" type="Runtime"></add>
        </plugins>
        <stepAssemblies>
            <stepAssembly assembly="AutomationFramework.SpecFlowPlugin" />
        </stepAssemblies>
        <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
    </specFlow>

Repro Project

using TechTalk.SpecFlow.Plugins;
using BoDi;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using AutomationFramework.SpecFlowPlugin;

[assembly: RuntimePlugin(typeof(Plugin))]

namespace AutomationFramework.SpecFlowPlugin
{
    public class Plugin : IRuntimePlugin
    {
        public void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginParameters runtimePluginParameters)
        {
            runtimePluginEvents.CustomizeScenarioDependencies += CustomizeScenarioDependencies;
        }

        private void CustomizeScenarioDependencies(object sender, CustomizeScenarioDependenciesEventArgs e)
        {
            e.ObjectContainer.RegisterFactoryAs(WebDriverFactory);
        }

        public static IWebDriver WebDriverFactory(IObjectContainer container)
        {
            return new ChromeDriver();
        }
    }
}

[Binding]
public class WebDriverTestSteps
{
    public WebDriverTestSteps(IWebDriver webDriver)
    {

    }
    
    [Given(@"I will use the browser")]
    public void GivenIWillUseTheBrowser()
    {
    }
}

Issue Description

When registering a dependency using a RegisterFactoryAs, it appears that the dependency is not disposed of properly during the test cleanup.

Note: This is a contrived example: What I really want to do is to be able to select the appropriate IWebDriver instance based on information obtained from IObjectContainer, so usage of RegisterInstanceAs is not appropriate.

Note: I have seen the example:

[Binding]
public class WebDriverSupport
{
  private readonly IObjectContainer objectContainer;

  public WebDriverSupport(IObjectContainer objectContainer)
  {
    this.objectContainer = objectContainer;
  }

  [BeforeScenario]
  public void InitializeWebDriver()
  {
    var webDriver = new FirefoxDriver();
    objectContainer.RegisterInstanceAs<IWebDriver>(webDriver);
  }
}

However because of #936, I cannot use the TestContext within a BeforeScenario hook

Steps to Reproduce

@SabotageAndi
Copy link
Contributor

fixed markdown in issue description

@SabotageAndi
Copy link
Contributor

@gasparnagy this is your expertise

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

No branches or pull requests

3 participants