在测试浏览器c#

时间:2019-01-30 10:12:20

标签: c# visual-studio selenium specflow xunit

发布问题之前,我已经进行了很多研究,但找不到解决问题的解决方案。

我正在尝试使用硒来进行自动化测试,但是问题是我的测试浏览器由于某种原因未进行Specflow测试。

这是我正在使用的:

  • c#.net核心项目
  • Specflow
  • Xunit
  • 硒驱动器
  • Selenium Chrome驱动程序

我已安装的NuGet软件包:

  • Selenium.Support
  • Selenium.WebDriver
  • Selenium.WebDriver.ChromeDriver
  • Specflow
  • Specflow.NetCore
  • Specflow.xUnit
  • SpecRun.Runner
  • xunit
  • xunit.core
  • xunit.runner.visualstudio

我还安装了Visual Studio 2017的Specflow。

我已经安装和卸载了NuGet软件包,以尝试解决此问题。有人可以帮助我吗?

3 个答案:

答案 0 :(得分:1)

经过大量尝试,我终于解决了。删除其中一个运行程序SpecRun之后,我添加了Specflow.Tools.MSbuild.Generation NuGet软件包,它解决了该问题。

希望对遇到同样问题的人有用!

答案 1 :(得分:1)

如果遇到问题,并且已经在项目中安装了Specflow.Tools.MSBuid.Generation NuGet软件包,则您 间歇性地丢失您生成的测试,那么您应该知道 Specflow.Tools.MSBuild.Generation Version = 2.3.2

中存在错误

您可以升级到Specflow.Tools.MSBuild.Generation的较新版本。 或应用解决方法。

解决方法是编辑.csproj并在AfterUpdateFeatureFilesInProject之后添加一个部分。

<Target Name="AfterUpdateFeatureFilesInProject">
  <ItemGroup>
    <Compile Include="@(SpecFlowGeneratedFiles)" />
  </ItemGroup>
</Target>

<!-- Workaround Specflow 2.3 MSBuild bug. SpecFlowGeneratedFiles 
     is not set if UpdateFeatureFilesInProject is up-to-date
   causing tests not to be discovered, as they are not included in the project -->
<ItemGroup>
  <Compile Include="**/*.feature.cs" Exclude="@(SpecFlowGeneratedFiles)">
    <DependentUpon>%(Filename)</DependentUpon>
  </Compile>
</ItemGroup>

答案 2 :(得分:0)

在我看来,您可能会缺少对TechTalk.SpecRun.Common的引用。请检查是否在您的解决方案参考中。

如果被引用,则您的测试适配器缓存可能已损坏。尝试查看以下步骤: Troubleshooting Visual Studio Integration