3

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.

Error:

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.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
Ade Bakre
  • 139
  • 1
  • 2
  • 8
  • Which blog? http://www.radicalgeek.co.uk/Post/14/acceptance-test-driven-development-of-an-mvc-web-application-using-specflow-and-selenium-webdriver. I've got the same issue as yourself, though things seemed to run to a certain point. – Andez Jul 06 '15 at 15:13
  • Yes it's the same post. How did you get things to run for you? – Ade Bakre Jul 08 '15 at 12:49

1 Answers1

1

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 scenarios 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>

Example:

@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 |
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Xena
  • 378
  • 2
  • 12