Search code examples
c#seleniumbddspecflow

Specflow tests not initiating


I keep getting this error when trying to run my Specflow tests. I've tried deleting the bin, deleted all nuget packages and reinstalled them, modified the

app.config, but this error still persist 


Test Name:  CreateAnEmailCampaign

Result Message: 
OneTimeSetUp: System.Configuration.ConfigurationErrorsException : Configuration system failed to initialize
  ----> System.Configuration.ConfigurationErrorsException : Unrecognized configuration section sectionGroup. (C:\Users\bin\Debug\Demo.dll.config line 11)


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
  </configSections>


  <sectionGroup name="NUnit">
    <section name="TestRunner" type="System.Configuration.NameValueSectionHandler" />
  </sectionGroup>
  <NUnit>
    <TestRunner>
      <!-- Valid values are STA,MTA. Others ignored. -->
      <add key="ApartmentState" value="STA" />
    </TestRunner>
  </NUnit>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <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 --><!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --><unitTestProvider name="NUnit" /></specFlow></configuration>

Solution

  • In the appconfig you have posted, the element sectionGroup is not a child of configSections and thus the error -

    Unrecognized configuration section sectionGroup.

    To solve this problem, move the sectionGroup inside the configSections as shown below.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <sectionGroup name="NUnit">
          <section name="TestRunner" type="System.Configuration.NameValueSectionHandler" />
        </sectionGroup>
        <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
      </configSections>
      <NUnit>
        <TestRunner>
          <!-- Valid values are STA,MTA. Others ignored. -->
          <add key="ApartmentState" value="STA" />
        </TestRunner>
      </NUnit>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <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 -->
        <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
        <unitTestProvider name="NUnit" />
      </specFlow>
    </configuration>