首页 > 解决方案 > 为什么我会为步骤“鉴于我输入密码详细信息”找到不明确的步骤定义 c# specflow

问题描述

在 VS 2019 中使用 c# 是 specflow 的新手。已经实现了我的步骤并生成了一个步骤定义文件,如下所示。实在想不通 Given, When, Then。我发现并且对于大多数登录页面很常见的示例是,您通常会获得一个需要用户名和密码的登录页面。但是在我的情况下,它们位于两个单独的页面上,即首先使用用户名登录,然后通过密码作为第二页登录。出于某种原因,我认为这就是混乱所在,是我不明白我应该在我的代码中放置 2-3 个给定语句的位置,因此出现错误并且只能将 sendkeys() 发送到用户名并且无法单击登录按钮。

错误:为步骤“鉴于我输入密码详细信息”找到了不明确的步骤定义

此步骤无法执行,因为我的步骤不正确。

[Binding]
    public sealed class HomeSteps
    {
        LoginPage loginPage = null;

        [Given(@"I launch the application")]
        public void GivenILaunchTheApplication()
        {
            IWebDriver webDriver = new ChromeDriver(@"C:\Users\Peter\Desktop\chromedriver_win32");
            webDriver.Navigate().GoToUrl("https://mycompany.com/app/auth/login");
            loginPage = new LoginPage(webDriver);
        }


        [Given(@"I enter the username details")]
        public void GivenIEnterTheUserNameDetails(Table table)
        {
            dynamic data = table.CreateDynamicInstance();
            loginPage.enterUsername((string)data.username);
            
        }
        [When(@"I click the login button")]
        public void AndIClickTheLogin()
        {
            loginPage.ClickLoginButton();
        }
        [Then(@"I should see the login link")]
        public void ThenIShouldSeeTheLoghinLink()
        {
            Assert.That(loginPage.IsMicrosoftPageExist(), Is.True);
        }

        [Given(@"I enter the password details")]
        public void AndIEnterThePaswordDetails(Table table)
        {
            dynamic data = table.CreateDynamicInstance();
            loginPage.enterPassword((string)data.password);
        }

        [When(@"I click the sign in button")]
        public void WhenIClickTheSignInButton()
        {
            loginPage.ClickSignInButton();
        }

        [Then(@"I should see the login link")]
        public void ThenIShouldSeeTheLoghinLink1()
        {
            Assert.That(loginPage.IsCompanyPageExist(),Is.True);
        }
    }

请帮忙??

场景是:

Scenario: Perform login to EA web site
    Given I launch the application
    And I enter the username details
    | username |
    | amyemail@email.com |
    When I click the login button
    When I shoukld see the microsoft logo
    When I enter the password details
    | password |
    | ...      |
    When I click the sign in button
    Then I should see the company page

标签: c#specflow

解决方案


错误消息说明了一切:

为步骤“鉴于我输入密码详细信息”找到了不明确的步骤定义

SpecFlow 不支持同一步骤的多个步骤定义。[Given(@"I enter the password details")]无论您有多少个步骤定义类,您的步骤定义文件中只能出现一次。

在您的步骤定义类中查找此定义存在的其他位置。选择一个,删除所有其他。


推荐阅读