Gopi Kumar
Gopi Kumar

Reputation: 11

How can i use step for both optional and value in parameters in cucumber

Can anyone help me out. It should for both scenarios mentioned below when we pass parameters or empty.

Given User is on login screen

When User performs login with existing user account that has players in the account with <username> and <password>

  | username          | password|
  | [email protected] | invalid |
  | [email protected] |         |

Steps

@When("^User performs login with existing user account that has players in the account with (.+) and (.+)$")
    public void user_performs_login_with_existing_user_user_account_that_has_players_in_the_account(String username,String password) throws Throwable {
        try {           
                loginScreenCoreLogic.performLogin(username, password);
        } catch (Exception e) {
            ErrorReporter.reportError(e);
        }
    }

Upvotes: 0

Views: 89

Answers (1)

Nandan A
Nandan A

Reputation: 2922

You can do that by using right cucumber expressions.

.* is greedy, meaning that it will ignore the next delimiter of your regex until it itself is not fulfilled, unless the regex following .* is against the end of the target string.

Feature:

@Regression
  Scenario Outline: Test scenario
    Given User is on login screen
    Then verify the message "File Upload Successful." in create a consent or do not call or wrong number file page

Examples: 
  | username          | password |
  | [email protected] | invalid  |
  | [email protected] |          |

Stepdefinition:

@When("User performs login with existing user account that has players in the account with (.*) and (.*)$")
public void test(String username,String password) {      
           System.out.println("Output: "+username +","+ password);
}

Output:

Output: [email protected],invalid
Output: [email protected],

Upvotes: 1

Related Questions