MrRabbit
MrRabbit

Reputation: 21

Why do I get Ambiguous step definitions found for step 'Given I enter the password details' c# specflow

New to specflow using c# in VS 2019. Have implemented my steps and generated a step definition file, as below. Can't really get my head around Given, When, Then. The example I found and is common for most log in pages is that you usually get a login page that requires both username and password. However in my case, they are on 2 separate pages i.e. login with username first, then login via password as second page. For some reason and I think this is where the confusion lies, is that I don't understand where I should put 2-3 given statements in my code, hence error and only getting to sendkeys() to username and not being able to click login button.

Error: Ambiguous step definitions found for step 'Given I enter the password details'

This step cannot be executed as my steps are not correct.

[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);
        }
    }

Please help??

Scenario is:

Scenario: Perform login to EA web site
    Given I launch the application
    And I enter the username details
    | username |
    | [email protected] |
    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

Upvotes: 1

Views: 2442

Answers (1)

Greg Burghardt
Greg Burghardt

Reputation: 18783

The error message says it all:

Ambiguous step definitions found for step 'Given I enter the password details'

SpecFlow does not support multiple step definitions for the same step. You can only have one occurrence of [Given(@"I enter the password details")] in your step definition files, regardless of how many step definition classes you have.

Find where else in your step definition classes this definition exists. Pick one, delete all the others.

Upvotes: 2

Related Questions