Invoking browsers with Baseclass.Contrib.Specflow in C# using Browser.Current


I'm currently trying to use Selenium Grid 2 to run automation tests on multiple browsers. During my research I came across using Baseclass.Contrib.Specflow which enables me to use the browsers as tags in the feature files without having to declare it in my main driver class. The problem I have is that one of the blogs I read had the following as the set up code

[SetUp] public void Test_Setup(){ CurrentDriver = Browser.Current;}

My app config file looks contains the following:

<components> <!-- <component name="Firefox" type="OpenQA.Selenium.Firefox.FirefoxDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency"> </component>--> <component name="Firefox" 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://localhost/wd/hub" /> <parameter name="browser" value="Firefox" /> </parameters> </component> <component name="Safari" 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://localhost/wd/hub" /> <parameter name="desiredCapabilities" value="Chrome" /> </parameters> </component>

I get an error when I try to run the script using the above Setup method.


System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary

The blog I got this solution from doesn't seem to answer questions regarding to this so I'm a bit desperate. This will basically allow me to to the following on the feature file and get tests to run based on the tag

@Browser:Firefox @Browser:Chrome

Hope this is enough information to give me advice.


The mistake you are making here is that you are annotating your entire feature file with the tag @Browser.

Baseclass.Contrib.Specflow allows you to annotate <em>scenarios</em> with scenario supporting Browsers. Therefore, you have to annotate each scenario.

If you don't do that, there is no Current Browser set for that test and trying to access Browser.Current will throw System.Collections.Generic.KeyNotFoundException.

You know you're doing it right when the generated Unit Tests will include the Browser name as part of the unit test name like

<Test Name> on <Browser> with: <parameters>


@Browser:IE @Browser:Chrome @Browser:Firefox Scenario Outline: Add Two Numbers >Given I navigated to / using And I have entered <summandOne> into summandOne calculator And I have entered <summandTwo> into summandTwo calculator When I press add Then the result should be <result> on the screen Scenarios: | summandOne| summandTwo|result| | 10 | 20 | 30 | | 3 | 4 | 7 |


  • OperaProfile object and Selenium RC (C#)
  • Java Selenium, storing updated page source after javascript activation
  • Again timeout creating new FirefoxDriver with Firefox 43 and above
  • Are there any good examples of how to take a screenshot in selenium webdriver C#, then crop and save
  • All open Chrome windows using Selenium Chrome driver
  • I am writing a Selenium script in Firefox but I am getting “Untrusted Certificate”
  • Running multiple classes in TestNG
  • Passing a string value to Javascript Executor in selenium
  • Could not find default Chrome binary
  • How to start appium test on iOS simulator?
  • How to test chat web app
  • Selenium ChromeDriver (C#) Crashes Only in Visual Studio Debug Mode
  • simulate a onclick with selenium python
  • Python - Remote Webdriver with Extension installed in it
  • Can you use multiple instances of Edge on a Selenium Grid Node?
  • what is browser's native support according to selenium webdriver
  • Imports in __init__.py and `import as` statement
  • Escaping single quotes in JDBC with MySql
  • Adding Parent and Child Nodes in TreeView from Sql Server 2008
  • Problems with toDataURL HTML5 other ways to get canvas data?
  • Specifying Castle WCF Integration Facility Endpoint Behavior per Endpoint
  • Chrome doesn't support silverlight anymore? How to solve this?
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Highlight one bar in a series in highcharts?
  • Display issues when we change from one jquery mobile page to another in firefox
  • Ajax jQuery multiple calls at the same time - long wait for answer and not able to cancel
  • Getting last autonumber in access
  • Is there a amazon webstore API for customers?
  • Why winpcap requires both .lib and .dll to run?
  • Calling of Constructors in a Java
  • Circular dependency while pushing http interceptor
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • PHP: When would you need the self:: keyword?
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Angular 2 constructor injection vs direct access
  • coudnt use logback because of log4j
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Binding checkboxes to object values in AngularJs