baseclass / Contrib.SpecFlow.Selenium.NUnit

Test class generator to drive automated web ui tests with Selenium and SpecFlow
http://www.nuget.org/packages/Baseclass.Contrib.SpecFlow.Selenium.NUnit/
22 stars 13 forks source link

Method Initialize in GeneratorPlugin does not have implementation #15

Open ashish-grover opened 6 years ago

ashish-grover commented 6 years ago

After setting up a basic google search test case, upon build I am receiving the following error.

error: 'Generation error: Method 'Initialize' in type 'Baseclass.Contrib.SpecFlow.Selenium.NUnit.GeneratorPlugin' from assembly 'Baseclass.Contrib.SpecFlow.Selenium.NUnit.SpecFlowPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.'

Is there anything I may have to do extra which I haven't done already?

unickq commented 6 years ago

@ashish-grover what specflow version do you use?

karunakar1008 commented 6 years ago

I am also having the same problem. Did you resolve this issue.

karunakar1008 commented 6 years ago

When I install Baseclass.Contrib.SpecFlow.Selenium.NUnit I am getting the issue

unickq commented 6 years ago

@karunakar1008 It's not developed anymore. 2.2.0 is not supported. You can switch to another tool

619steve commented 6 years ago

I have fixed this issue using the new Initialize methods in both the IGeneratorPlugin and the IRuntimePlugin with Specflow 2.0+.

First I had to clone this repo, then update the specflow version to 2.1 The interfaces only have 1 method now Initialize, this is what I did to initialize them

[assembly: RuntimePlugin(typeof(Baseclass.Contrib.SpecFlow.Selenium.NUnit.RuntimePlugin))]

namespace Baseclass.Contrib.SpecFlow.Selenium.NUnit
{
    public class RuntimePlugin : IRuntimePlugin
    {
        public void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginParameters runtimePluginParameters)
        {
            runtimePluginEvents.RegisterGlobalDependencies += this.RegisterDependencies;
        }
        public void RegisterDependencies(object sender, RegisterGlobalDependenciesEventArgs customizeGlobalDependenciesEventsArgs)
        {
            customizeGlobalDependenciesEventsArgs.ObjectContainer.RegisterTypeAs<NUnitRuntimeProvider, IUnitTestRuntimeProvider>("SeleniumNUnit");
        }
    }
}
[assembly: GeneratorPlugin(typeof(Baseclass.Contrib.SpecFlow.Selenium.NUnit.GeneratorPlugin))]

namespace Baseclass.Contrib.SpecFlow.Selenium.NUnit
{
    public class GeneratorPlugin : IGeneratorPlugin
    {
        public void Initialize(GeneratorPluginEvents generatorPluginEvents, GeneratorPluginParameters generatorPluginParameters)
        {
            generatorPluginEvents.RegisterDependencies += this.GeneratorPluginEventsOnRegisterDependencies;
        }
        private void GeneratorPluginEventsOnRegisterDependencies(object sender, RegisterDependenciesEventArgs registerDependenciesEventArgs)
        {
            registerDependenciesEventArgs.ObjectContainer.RegisterTypeAs<SeleniumNUnitTestGeneratorProvider, IUnitTestGeneratorProvider>("SeleniumNUnit");

        }
    }
}

SeleniumNUnitTestGeneratorProvider did not have to be changed much. I just had to implement the new method UnitTestGeneratorTraits in the interface IUnitTestGeneratorProvider

public virtual UnitTestGeneratorTraits GetTraits()
{
     return UnitTestGeneratorTraits.RowTests;
}

From there, I'm taking the pre-compiled dlls (2) Baseclass.Contrib.Specflow.Selenium.Nunit.SpecflowPlugin and Baseclass.Contrib.Specflow.Selenium.Nunit.Bindings and saving them in my automation solution. I am referencing them in my app.config like so:

 <specFlow>
    <unitTestProvider name="SeleniumNUnit" />
    <runtime>
      <dependencies>
        <register type="TechTalk.SpecFlow.UnitTestProvider.NUnitRuntimeProvider, TechTalk.SpecFlow" as="TechTalk.SpecFlow.UnitTestProvider.IUnitTestRuntimeProvider" name="SeleniumNUnit" />
      </dependencies>
    </runtime>
    <!--<generator allowRowTests="false" />-->
    <plugins>
      <add name="Baseclass.Contrib.SpecFlow.Selenium.NUnit" path="Baseclass.Contrib.SpecFlow.Selenium.NUnit" type="Generator" />
    </plugins>
    <stepAssemblies>
      <stepAssembly assembly="Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings" />
    </stepAssemblies>
  </specFlow>

I am currently using SpecFlow 2.1 with NUnit 3.6.1 and Selenium WebDriver 3.8.0

unickq commented 6 years ago

@619steve Check that out