-1

I am trying to run test cases created through Specflow, but I am having an error. The idea behind the code is that I have a Feature file, a Step Definition file and a Page file. I am able to open the browser, but when it is supposed to enter the credentials in the Login page, it keeps getting the error: Cannot convert type 'int' to 'string' in the line that is commented in the Step Definition file.

The feature file:

Feature: Login in the website

  Scenario Outline: Login with the credentials

    Given That I am on the Login page
    When User enters
     | email                        | password     |
     | gt862@student.gqwiypoh.se    | 12345        |
    Then The client will be on the account page

The Step Definition file:

 LoginPage loginpage = null;


        [Given(@"That I am on the Login page")]
        public void GivenThatIAmOnTheLoginPage()
        {
            IWebDriver webDriver = new ChromeDriver();
            webDriver.Navigate().GoToUrl("http://automationpractice.com/index.php?controller=authentication&back=my-account");
            loginpage = new LoginPage(webDriver);   
        }

        [When(@"User enters")]
        public void WhenUserEnters(Table table) //This is the method that I keep having problems
        {
            dynamic data = table.CreateDynamicInstance();

            loginpage.Login((string)data.email, (string)data.password);
        }


        [Then(@"The client will be on the account page")]
        public void ThenTheClientWillBeOnTheAccountPage()
        {
            loginpage.LoginButton();
        }

    }

The Page file of the login where I get the names of the textboxes and button:

 public IWebDriver Webdriver { get; }

        public LoginPage(IWebDriver webdriver)
        {
            Webdriver = webdriver;
        }

        //UI Elements
        public IWebElement txtEmail => Webdriver.FindElement(By.Name("email"));

        public IWebElement txtPassword => Webdriver.FindElement(By.Name("passwd"));

        public IWebElement btnLogin => Webdriver.FindElement(By.CssSelector("#SubmitLogin > span"));

        public void Login(string Email, string Password)
        {
            txtEmail.SendKeys(Email);
            txtPassword.SendKeys(Password);

        }

        public void LoginButton() => btnLogin.Submit();
    }

Below is also a screenshot of the test report.

enter image description here

May I ask you what may be the problem and how can I fix it?

Thank you all in advance.

GerRax
  • 59
  • 1
  • 8

1 Answers1

0

I would say that CreateDynamicInstance is recognizing 12345 as int and not as string.

Changing the binding to the following should work:

[When(@"User enters")]
public void WhenUserEnters(Table table) //This is the method that I keep having problems
{
    dynamic data = table.CreateDynamicInstance();

    loginpage.Login(data.email.ToString(), data.password.ToString());
}
Andreas Willich
  • 5,665
  • 3
  • 15
  • 22