Search code examples
cucumber-junitcucumber-java

java cucumber pass date as string error


Java - cucumber

I am new to writing cucumber test, getting error on given method signature can some one help pls ?

following is my feature file entry

@txn
Feature: ORP

  Scenario Outline: Save a ORP
    Given when i pass start date <start date> and end date <end date>
    When the user saves a ORP
    Then the PROP is saved
    Examples:
    | start date  | end date  |
    | 1-1-2016    | 1-1-2017  |

and step file as following signature to get given start and end date

@Given ("^when i pass start date (.+) and end date (.+)$")
public void processOPR(String, start, String end){...}

when i run my test i get the following error

Exception

    @Given("^when i pass start date (\\d+)-(\\d+)-(\\d+) and end date (\\d+)-(\\d+)-(\\d+)$")
public void when_i_pass_start_date_and_end_date(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();

I want to pass date "1/1/2016" in one variable not in 3 different variables.


Solution

  • found solution as following

    @Given ("^when i pass start date (.+) and end date (.+)$")
    public void processOPR(@Format("dd-MM-yyyy")Date start, @Format("dd-MM-yyyy") Date end){...}