user5199
user5199

Reputation: 369

Running Specrun and using 'Baseclass.contrib.Specflow' for cross browser parameterized tests in VS2015

I would like to use SpecRunner along with the library 'Baseclass.Contrib.SpecFlow.Selenium.NUnit.' When I added SpecRunner for SpecFlow 2 from Manage Nuget Packages, the unit test provider was 'SpecRun' in app.config. Then when added to 'Baseclass.Contrib.SpecFlow.Selenium.NUnit' to the solution using Manage Nuget Package, it also added a unit test provider of 'SeleniumNUnit. When I created my feature files and step definitions and tried to run the tests with each feature annotated with a browser tag like '@Browser: Chrome' and use the 'Browser.Current' syntax as the webdriver in my binding methods, it gave me an error. The error was first that I had two unit test providers in the app.config, and that the app.config can only have one unit test provider. SO I commented out the first unit test provider, and received another set of errors:

*Error 2 #error: 'Generation error: Could not load file or assembly 'TechTalk.SpecFlow, Version=1.9.0.77, Culture=neutral, PublicKeyToken=0778194805d6db41' or one of its dependencies. The system cannot find the file specified.' C:\Users\amaddox\documents\visual studio 2013\Projects\SpecFlow\SpecFlow\SpecFlowFeature1.feature.cs 1 8 SpecFlow *

*Error 33 Custom tool error: Generation error: Could not load file or assembly 'TechTalk.SpecFlow, Version=1.9.0.77, Culture=neutral, PublicKeyToken=0778194805d6db41' or one of its dependencies. The system cannot find the file specified. C:\Users\amaddox\documents\visual studio 2013\Projects\SpecFlow\SpecFlow\SpecFlowFeature1.feature 2 2 SpecFlow *

So then I tried to uncomment the first and comment the second unit test provider. Same issue. How can I run SpecRun in visual Studio 2015 along with the flexibility of parameterized cross browser tests functionality that 'Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings' has to offer? It appears that it wants me to go back to a previous version of Specflow (1.9) and I am using Specflow 2. Not sure how to do this. How do I solve this issue?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
  <section name="autofac" type="Autofac.Configuration.SectionHandler, Autofac.Configuration" /></configSections>
  <specFlow>
    <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
  <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --><!-- use unit test provider SpecRun+NUnit or SpecRun+MsTest for being able to execute the tests with SpecRun and another provider --><unitTestProvider name="SpecRun" /><plugins>
      <add name="SpecRun" />
    <add name="Baseclass.Contrib.SpecFlow.Selenium.NUnit" path="..\packages\Baseclass.Contrib.SpecFlow.Selenium.NUnit.1.3.1\tools" /></plugins><unitTestProvider name="SeleniumNUnit" /><stepAssemblies>
      <stepAssembly assembly="Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings" />
    </stepAssemblies></specFlow>
<appSettings>
    <add key="seleniumBaseUrl" value="http://localhost:58909" />
  </appSettings><autofac>
    <components>
      <component name="IE" type="OpenQA.Selenium.IE.InternetExplorerDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
      </component>
      <component name="Chrome" type="OpenQA.Selenium.Chrome.ChromeDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
      </component>
      <component name="Firefox" type="OpenQA.Selenium.Firefox.FirefoxDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
      </component>
      <!-- Example of using an injected RemoteDriver:
      <component
              name="IE"
              type="Baseclass.Contrib.SpecFlow.Selenium.NUnit.RemoteWebDriver, Baseclass.Contrib.SpecFlow.Selenium.NUnit.SpecFlowPlugin"
              service="OpenQA.Selenium.IWebDriver, WebDriver"
              instance-scope="per-dependency">
        <parameters>
          <parameter name="url" value="http://127.0.0.1:4444/wd/hub" />
          <parameter name="browser" value="InternetExplorer">
          </parameter>
        </parameters>
      </component>-->
    </components>
  </autofac>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="TechTalk.SpecFlow" publicKeyToken="0778194805d6db41" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

*

Upvotes: 0

Views: 509

Answers (2)

unickq
unickq

Reputation: 3446

I rewrote Baseclass.Contrib.SpecFlow.Selenium.NUnit for 2.1 support.

New codebase, @ignore tag support for nunit3 and several testing services like BrowserStack, SauceLabs, TestingBot.

Upvotes: 0

Andreas Willich
Andreas Willich

Reputation: 5835

After a short look at Baseclass.Contrib.SpecFlow.Selenium.NUnit it depends on SpecFlow 1.9. If you want to use it, you have to stick on SpecFlow 1.9. Additionally it looks like they create their own GeneratorPlugin to generate custom code behind files.

That does not work together with SpecFlow+Runner as it has its own generator.

And two unitTestProviders in the config does not work.

But the SpecFlow+Runner has a feature called "Targets" see http://www.specflow.org/plus/documentation/SpecFlowPlus-Runner-Profiles and search for it there.

You can create a target for each of your browsers and use the ConfigFileTransformation Step to adjust your config for your different browsers.

Another way, but I am not sure if this work. SpecFlow+Runner has support for SpecFlow 1.9 and can execute NUnit tests. Use the SpecRun.SpecFlow.1-9-0 nuget package and configure the unitTestProvider to the one of baseClass. If they generate the standard NUnit attributes, the SpecFlow+Runner should find the tests and can execute them. But be aware, that you are losing some features with that method.

Full disclosure: I am one of the developers of SpecFlow and SpecFlow+

Upvotes: 0

Related Questions