使用Browser.Current在C#中使用Baseclass.Contrib.Specflow调用浏览器

使用Browser.Current在C#中使用Baseclass.Contrib.Specflow调用浏览器,c#,selenium,specflow,baseclass-contrib,C#,Selenium,Specflow,Baseclass Contrib,我目前正在尝试使用SeleniumGrid2在多个浏览器上运行自动化测试。在我的研究过程中,我遇到了使用Baseclass.Contrib.Specflow的情况,它使我能够在功能文件中使用浏览器作为标记,而无需在我的主驱动程序类中声明它。我遇到的问题是,我读过的一个博客的设置代码如下 [SetUp] public void Test_Setup(){ CurrentDriver = Browser.Current;} 我的应用程序配置文件包含以下内容: <components&g

我目前正在尝试使用SeleniumGrid2在多个浏览器上运行自动化测试。在我的研究过程中,我遇到了使用Baseclass.Contrib.Specflow的情况,它使我能够在功能文件中使用浏览器作为标记,而无需在我的主驱动程序类中声明它。我遇到的问题是,我读过的一个博客的设置代码如下

[SetUp]
public void Test_Setup(){
CurrentDriver = Browser.Current;}
我的应用程序配置文件包含以下内容:

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

希望这些信息足以给我提供建议。

您在这里犯的错误是,您用标签
@Browser
注释了整个功能文件

Baseclass.Contrib.Specflow
允许您使用支持场景的浏览器对场景进行注释。因此,您必须对每个场景进行注释

如果不这样做,则没有为该测试设置当前浏览器,并尝试访问
浏览器。当前
将抛出
System.Collections.Generic.KeyNotFoundException

当生成的单元测试将包含浏览器名称作为单元测试名称的一部分时,您知道您做得很好,如

<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 |
@浏览器:IE
@浏览器:Chrome
@浏览器:Firefox
场景大纲:添加两个数字
>假设我导航到/使用
我已经输入了summandOne计算器
我已经输入了Summand2计算器
当我按add时
然后结果应该显示在屏幕上
情节:
|求和一|求和二|结果|
| 10 | 20 | 30 |
| 3 | 4 | 7 |

哪个博客。我和你有同样的问题,尽管事情似乎发展到了一定程度。是的,这是同一篇文章。你是如何让事情为你运转的?
@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 |