Search code examples
javaselenium-webdrivercucumbercucumber-jvmgherkin

In cucumber/Selenium when I want to pass the multiple parameter as string I have an issue


I am getting this error:

as Step [Enter the Username and Password ] is defined with 2 parameters at 'stepdefenitions.loginstepdefenitions.enter_the_Username_String_username_and_Password_String_password(String,String) in file:/C:/Users/hai/eclipse-workspace/gherkins/bin/'. However, the gherkin step has 0 arguments.

My feature file

Feature: Reset functionality on login page of Application

 Scenario Outline: Verification of reset button with numbers of credential
  Given Open the Chrome and launch the application          
  When Enter the Username <String,username> and  Password <String,password> 
  Then Reset the credential 

  Examples:                             
  |username  |password         |        
  |User1     |password1        |        
  |User2     |password2        |

Solution

  • Try this in the specific feature file's step:

    When Enter the Username "<username>" and  Password "<password>"
    

    And in the Java step:

    @When("^Enter the Username \"([^\"]*)\" and Password \"([^\"]*)\"$")
    public void enterTheUsernameAndPassword(String usnm, String pswd) {
         System.out.println("The username is: " + usnm);
         System.out.println("The password is: " + pswd);
    }
    

    Check the documentation for further information here.