I'm new to Cucumber. I want to test two login scenarios:
- With valid credentials where user should be able to login successfully
- With empty username and password where the user should not be able to login
I have the following code for the above scenario:
Scenario Outline: Test login with valid credentials
Given Open firefox and start application
When I enter "<username>" and "<password>"
Then User should be able to login successfully
Examples:
| username | password |
| ro | mech |
Scenario Outline: Test login with empty credentials
Given Open firefox and start application
When I enter "<username>" and "<password>" (this shows a warning)
Then User should be not able to login
Examples:
| username | password |
| | |
In the java file I have the following code:
@When("^I enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void I_enter_and_(String username, String password) throws Throwable {
driver.findElement(By.id("ember629")).sendKeys(username);
driver.findElement(By.id("ember640")).sendKeys(password);
}
My question is scenario 2 shows a warning message:
Step 'I enter "<username>" and "<password>"' does not have a matching glue code
Does this mean that for every scenario like valid, empty and invalid credentials I need to write a separate java function? Can't I use the same java function:
public void I_enter_and_(String username, String password)
for all the scenarios? If I run the feature file I get this output:
You can implement missing steps with the snippets below:
@When("^I enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void i_enter_and(String arg1, String arg2) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Is there any way to reuse the java function I_enter_and_
?