【问题标题】:Running Specrun and using 'Baseclass.contrib.Specflow' for cross browser parameterized tests in VS2015在 VS2015 中运行 Specrun 并使用“Baseclass.contrib.Specflow”进行跨浏览器参数化测试
【发布时间】:2017-01-13 00:10:36
【问题描述】:

我想将 SpecRunner 与“Baseclass.Contrib.SpecFlow.Selenium.NUnit”库一起使用。当我从 Manage Nuget Packages 添加 SpecFlow 2 的 SpecRunner 时,单元测试提供程序是 app.config 中的“SpecRun”。然后,当使用 Manage Nuget Package 将“Baseclass.Contrib.SpecFlow.Selenium.NUnit”添加到解决方案时,它还添加了“SeleniumNUnit”的单元测试提供程序。当我创建我的功能文件和步骤定义并尝试使用带有“@Browser:Chrome”之类的浏览器标签注释的每个功能运行测试并在我的绑定方法中使用“Browser.Current”语法作为网络驱动程序时,它给了我一个错误。错误首先是我在 app.config 中有两个单元测试提供程序,而 app.config 只能有一个单元测试提供程序。所以我注释掉了第一个单元测试提供者,并收到另一组错误:

*错误 2 #error: '生成错误: 无法加载文件或程序集'TechTalk.SpecFlow, Version=1.9.0.77, Culture=neutral, PublicKeyToken=0778194805d6db41' 或其依赖项之一。该系统找不到指定的文件。' C:\Users\amaddox\documents\visual studio 2013\Projects\SpecFlow\SpecFlow\SpecFlowFeature1.feature.cs 1 8 SpecFlow *

*错误 33 自定义工具错误:生成错误:无法加载文件或程序集“TechTalk.SpecFlow,版本=1.9.0.77,文化=中性,PublicKeyToken=0778194805d6db41”或其依赖项之一。该系统找不到指定的文件。 C:\Users\amaddox\documents\visual studio 2013\Projects\SpecFlow\SpecFlow\SpecFlowFeature1.feature 2 2 SpecFlow *

然后我尝试取消注释第一个并注释第二个单元测试提供程序。同样的问题。如何在 Visual Studio 2015 中运行 SpecRun 以及“Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings”必须提供的参数化跨浏览器测试功能的灵活性?它似乎希望我回到以前版本的 Specflow (1.9),我正在使用 Specflow 2。不知道该怎么做。我该如何解决这个问题?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
  <section name="autofac" type="Autofac.Configuration.SectionHandler, Autofac.Configuration" /></configSections>
  <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 --><!-- use unit test provider SpecRun+NUnit or SpecRun+MsTest for being able to execute the tests with SpecRun and another provider --><unitTestProvider name="SpecRun" /><plugins>
      <add name="SpecRun" />
    <add name="Baseclass.Contrib.SpecFlow.Selenium.NUnit" path="..\packages\Baseclass.Contrib.SpecFlow.Selenium.NUnit.1.3.1\tools" /></plugins><unitTestProvider name="SeleniumNUnit" /><stepAssemblies>
      <stepAssembly assembly="Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings" />
    </stepAssemblies></specFlow>
<appSettings>
    <add key="seleniumBaseUrl" value="http://localhost:58909" />
  </appSettings><autofac>
    <components>
      <component name="IE" type="OpenQA.Selenium.IE.InternetExplorerDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
      </component>
      <component name="Chrome" type="OpenQA.Selenium.Chrome.ChromeDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
      </component>
      <component name="Firefox" type="OpenQA.Selenium.Firefox.FirefoxDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
      </component>
      <!-- Example of using an injected RemoteDriver:
      <component
              name="IE"
              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://127.0.0.1:4444/wd/hub" />
          <parameter name="browser" value="InternetExplorer">
          </parameter>
        </parameters>
      </component>-->
    </components>
  </autofac>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="TechTalk.SpecFlow" publicKeyToken="0778194805d6db41" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

*

【问题讨论】:

    标签: specrun


    【解决方案1】:

    在简要了解 Baseclass.Contrib.SpecFlow.Selenium.NUnit 之后,它依赖于 SpecFlow 1.9。如果你想使用它,你必须坚持使用 SpecFlow 1.9。 此外,看起来他们创建了自己的 GeneratorPlugin 以在文件后面生成自定义代码。

    这不能与 SpecFlow+Runner 一起使用,因为它有自己的生成器。

    并且配置中的两个 unitTestProviders 不起作用。

    但 SpecFlow+Runner 有一个名为“Targets”的功能,请参阅http://www.specflow.org/plus/documentation/SpecFlowPlus-Runner-Profiles 并在那里搜索它。

    您可以为每个浏览器创建一个目标,并使用 ConfigFileTransformation 步骤为您的不同浏览器调整配置。

    另一种方式,但我不确定这是否有效。 SpecFlow+Runner 支持 SpecFlow 1.9 并且可以执行 NUnit 测试。 使用 SpecRun.SpecFlow.1-9-0 nuget 包并将 unitTestProvider 配置为 baseClass 之一。如果它们生成标准的 NUnit 属性,SpecFlow+Runner 应该会找到测试并执行它们。但请注意,使用该方法会丢失一些功能。

    全面披露:我是 SpecFlow 和 SpecFlow+ 的开发者之一

    【讨论】:

    • 哇,安德烈亚斯,知道这很酷。我在linkedin上向您发送了linkedIn请求,以便希望与您联系。我会试试你的建议。
    • 是否有使用目标进行跨浏览器测试的示例?我不确定我是否关注您发送的网站
    【解决方案2】:

    I rewrote Baseclass.Contrib.SpecFlow.Selenium.NUnit for 2.1 support.

    新的代码库、对 nunit3 的 @ignore 标记支持以及 BrowserStack、SauceLabs、TestingBot 等多个测试服务。

    【讨论】:

      猜你喜欢
      • 2012-08-03
      • 1970-01-01
      • 2019-05-02
      • 2011-11-14
      • 1970-01-01
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      相关资源
      最近更新 更多