Selenium webdriver 上下文菜单中缺少Specflow生成步骤定义

Selenium webdriver 上下文菜单中缺少Specflow生成步骤定义,selenium-webdriver,visual-studio-2013,specflow,Selenium Webdriver,Visual Studio 2013,Specflow,我在要素文件上单击鼠标右键,应该可以获得生成步骤定义的选项。它不在上下文菜单中。 我做了一个搜索,它说要为nunit安装specrun。 我尝试从Manage NuGet软件包安装SpecRun.Nunit 我得到一个错误: Severity Code Description Project File Line Suppression State Error Unable to load the service index for source http:/

我在要素文件上单击鼠标右键,应该可以获得生成步骤定义的选项。它不在上下文菜单中。 我做了一个搜索,它说要为nunit安装specrun。 我尝试从Manage NuGet软件包安装SpecRun.Nunit

我得到一个错误:

Severity    Code    Description Project File    Line    Suppression State
Error       Unable to load the service index for source 
http://packagesource.
An error occurred while sending the request.
The remote name could not be resolved: 'packagesource'          0   
我已安装Visual Studio Enterprise 2017。 我已经安装了SeleniumWebDriver,Specflow


请告诉我如何解决此问题,谢谢。

您需要从菜单项“工具”->“扩展和更新…”安装specflow nuget软件包以及Visual Studio集成软件包。

以下是我要做的事情,以使该选项显示在VS2019的上下文菜单中

  • 我正常安装了Specflow,从扩展->管理扩展, 然后搜索Visual Studio 2019的Specflow
  • 已安装软件包并重新启动VS
  • 然后我创建了一个新项目,一个C#Test
  • 初始设置就绪后,从 解决方案资源管理器我选择了“添加->新建项目…”并选择了“SpecFlow” “功能文件”,我在功能文件中键入了所需的信息
  • 在任何一行小黄瓜上,我都右键单击以获取上下文 菜单并选择“转到定义”。显示一个对话框,告诉我 没有匹配项,但我可以将行保存在剪贴板中。我 选择是
  • 然后再次在解决方案资源管理器上(如步骤4),右键单击 “添加->新建项目…”,但现在选择了“SpecFlow步骤定义”。这个 步骤定义为计算器测试的步骤定义
  • 现在有个窍门:

    • 删除所有步骤,将主类保留为空
    像这样:

    using System;
    using TechTalk.SpecFlow;
    
    namespace SpecflowFirst
    {
        [Binding]
        public class SpecFlowFeature1Steps
        {
    
        }
    }
    
    using System;
    using TechTalk.SpecFlow;
    
    namespace SpecflowFirst
    {
        [Binding]
        public class SpecFlowFeature1Steps
        {
            [Given(@"I navigated to the github login page")]
            public void GivenINavigatedToTheGithubLoginPage()
            {
                ScenarioContext.Current.Pending();
            }
        }
    }
    
    • 然后将从对话框中获得的代码片段粘贴到主 阶级
    像这样:

    using System;
    using TechTalk.SpecFlow;
    
    namespace SpecflowFirst
    {
        [Binding]
        public class SpecFlowFeature1Steps
        {
    
        }
    }
    
    using System;
    using TechTalk.SpecFlow;
    
    namespace SpecflowFirst
    {
        [Binding]
        public class SpecFlowFeature1Steps
        {
            [Given(@"I navigated to the github login page")]
            public void GivenINavigatedToTheGithubLoginPage()
            {
                ScenarioContext.Current.Pending();
            }
        }
    }
    
    这将触发编译中的错误。如果您指向“ScenarioContext”中的错误并显示“可能的修复”,其中一个修复将是安装“Sprecflow extension”。使用此选项,您将安装剩余的集成,该集成现在将在关联菜单中显示该选项


    这解决了我的问题,现在我可以在上下文菜单中看到“生成步骤定义”

    我遵循了Kyon的出色演练,但这对我不起作用。尽管SpecFlow安装正确,但它没有识别以下库,也没有提出任何“修复此问题”的建议:

    然后我注意到,有了一个全新的MsTest项目和最新的VS2019(截至2020年10月),您需要安装稍早版本的SpecFlow(v2.1比v2.4)

    因此,如果您在显示这个虚幻的“生成步骤定义”菜单项时遇到问题,请查看您的Dependencies\Packages中是否有感叹号