1

my feature file is like:

Given User is on Home Page
    When User Navigate to LogIn Page
    And User enters Credentials to LogIn
    | Username   | Password |
    | testuser_1 | Test@153 |
    | testuser_2 | Test@154 |
    Then Message displayed Login Successfully

Step Definition is:

public void user_enters_testuser_and_Test(List<Credentials>  usercredentials) throws Throwable {

        //Write the code to handle Data Table
        for (Credentials credentials : usercredentials) {           
            driver.findElement(By.id("log")).sendKeys(credentials.getUsername()); 
            driver.findElement(By.id("pwd")).sendKeys(credentials.getPassword());
            driver.findElement(By.id("login")).click();
            }       
    }

Here is the customized Object argument:

public class Credentials {
    private String username;
    private String password;

    public String getUsername() {
        return username;
    }
    public String getPassword() {
        return password;
    }   
}

when I run the code I always got this error:

cucumber.runtime.CucumberException: Could not convert arguments for step [^User enters Credentials to LogIn$] defined at 'stepDefinitions.ConsumerServiceEnquiry.ConsumerSteps.user_enters_testuser_and_Test(Credentials>) in file:/C:/Users/jxz36/eclipse-workspace/SDBCucumberTestng/bin/'.

I have searched everywhere, and see a lot of similar example. so I think it must be some basic error or missing configuration. Please can anybody help me out of this? Much appreciated!

Jamie Zhai
  • 33
  • 1
  • 3

1 Answers1

0

I think you are on cucumber 3 and above. If so refer to this - Cucumber-JVM - io.cucumber.datatable.UndefinedDataTableTypeException

Replace the existing converter to this.

registry.defineDataTableType(new DataTableType(Credentials.class, new TableEntryTransformer<Credentials>() {
            @Override
            public Credentials transform(Map<String, String> entry) {
                return new Credentials(entry.get("Username"),entry.get("Password"));
            }
        }));

And also add the constructors to the Credentials class

 public Credentials() {
    }
    public Credentials(String username, String password) {
        this.username = username;
        this.password = password;

}

Grasshopper
  • 8,908
  • 2
  • 17
  • 32
  • Thank you Grasshopper so much. Yes I figured it out yesterday and it's cucumber version problem. and I have downgraded to version 2.3.0. and the issue is gone! Thanks! – Jamie Zhai Jun 20 '18 at 23:43
  • It is not a version problem, just the way automatic conversions are been handled has been upgraded. As xstream has been removed due to incompatibility with java9, this is the new way of handling conversions. – Grasshopper Jun 21 '18 at 05:46