【问题标题】:TechTalk.SpecFlow.BindingException: Ambiguous step definitions found for step [duplicate]TechTalk.SpecFlow.BindingException:为步骤找到不明确的步骤定义[重复]
【发布时间】:2020-12-12 06:59:37
【问题描述】:

我有 2 个功能使用相同的 Given 步骤并传递用户名 Given I navigate to the HomePage with the <user>

当我尝试运行测试时,我得到以下信息:

TechTalk.SpecFlow.BindingException: 'Ambiguous step definitions found for step 'Given I navigate to the SourceForge HomePage with the user1

功能 1:

Feature: UploadProjectFileFeature
    In order to to be to add project documentation
    I want to be able to upload project file(s) to the correct project repository
@mytag
Scenario: Upload Project File(S) to the correct project repository
    Given I navigate to the HomePage with the <user>
    And I Log into the application with <username> and <password>
    When I navigate to the <project> page and I upload File(s)
    Then the file should upload successfully

    Examples:
        | user  | username | password     | project         |
        | user1 | username | Passtest.123 | TestAutomationP |

功能 2:

Feature: UserLogin
    In order to access my account
    As a user of the website
   I want to log into the website

@mytag1
Scenario: Successful Login with Correct user
    Given I navigate to the HomePage with the <user>
    And I Navigate to the LoginPage
    When I Log into the application with <username> and <password>
    And I Navigate to the Profile Page
    Then <user> and <username> should be displayed correctly


    Examples:
    | user  | username| password     |
    | user1| username| Passtest.123 |

我尝试创建一个基类,然后使用标签和虚拟并覆盖作为解决方法,但我一直收到同样的错误

基类:

  public  class FeatureBaseClass
    {
        
        [Given(@"I navigate to the HomePage with (.*)")]
        public virtual void GivenINavigateToTheSourceForgeHomePageWith(string user)
        {
   
            string User = user;
        }

测试:

    [Binding]
  [Scope(Feature = "UserLogin")]
    public class UserLogin : FeatureBaseClass
    {
        
       
        [Given(@"I navigate to the HomePage with (.*)")]
    [Scope(Feature = "UserLogin", Scenario = "Successful Login with Correct user")]
    public override void GivenINavigateToTheSourceForgeHomePageWith(string user)
        {
            Console.WriteLine("Launched Browser with " + user);
 
        }
    [Binding]
   [Scope(Feature = "UploadProjectFileFeature")]
    public class UploadProjectFile : FeatureBaseClass
    {
      
        [Given(@"I navigate to the HomePage with (.*)")]
        [Scope(Feature = "UploadProjectFileFeature", Scenario = "Upload Project File(S) to the correct project repository")]
        public  override void GivenINavigateToTheSourceForgeHomePageWith(string user)
        {
            Console.WriteLine("Launched Browser with " + user);
            
 
        }

谁能看出我哪里出错了?或者任何人都可以提出更好的解决方案?

【问题讨论】:

  • 是的,这是我提出解决方案的帖子。但无论出于何种原因未能成功复制

标签: c# automated-tests cucumber specflow gherkin


【解决方案1】:

“不明确的步骤定义”意味着您有 2 个或更多具有相同定义的步骤,因此 specflow 不知道您要运行哪一个。每一步都必须是独一无二的。在您的情况下,您有 2 个相同的 Given 语句,如下所示:

 [Given(@"I navigate to the HomePage with (.*)")]

在两个不同的班级。删除其中一个,它应该会运行。

【讨论】:

  • 是的,我知道这一点。但我试图想出一个解决方案,我不必为所有测试用例重新命名相同的步骤
  • 你不必,它可以读取任何步骤定义文件中的步骤。您只需要 1 个步骤定义副本即可在任何功能文件中使用它
  • 这成功了!谢谢你:)
猜你喜欢
  • 1970-01-01
  • 2014-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多