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

I am currently trying to use Selenium Grid 2 to run automation tests across multiple browsers. During my research, I came across using Baseclass.Contrib.Specflow, which allows me to use browsers as tags in function files without declaring them in my main driver class. The problem is that one of the blogs I read had the following code:

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

      

The appearance of the application configuration file 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 am getting an error when I try to run a script using the above installation method.

Mistake:

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

The blog where I got this solution doesn't seem to answer the questions related to this, so I'm a little desperate. Basically this will allow me to include in the file functions and run tests based on the tag

@Browser:Firefox
@Browser:Chrome

      

Hope this is enough to give me some advice.

+3


source to share


1 answer


The mistake you are making here is annotating your entire function file with a tag @Browser

.

Baseclass.Contrib.Specflow

allows you to annotate scripts with browser-compatible script. Therefore, you must annotate each script.

If you don't, there is no current browser for this test and trying to access it Browser.Current

will throw System.Collections.Generic.KeyNotFoundException

.

You know you are doing it right when the generated device tests 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 |

      

+1


source







All Articles