How do I pass the values between two steps in cucumber JVM?
In the following scenario, I want to access username provided When step in Then step. How do I pass the values between two steps in cucumber JVM? Currently I'm accessing those by saving that value into a public variable. Is the approach correct (or) any other way I can access those between the steps?
Scenario:
Given user is on login page When user enters username as user1 and password as pass1 And clicked on login button Then post login page is displayed
@When("^user enters username as ([^\"]*) and password as ([^\"]*)$")
public void enterLoginDetails(String username,String password){
driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
}
In the following step definition, I want to access username from the previous step definition
@Then("^post login page is displayed$")
public void postLoginValidation(){
// i would like access username and verify username is displayed
}
Thanks in Advance