Calling page objects from steps

Now that we have create page objects and moved the actual code of doing text enter, click buttons etc on to the pages, the step classes should be just calling the methods from these pages.

What that means is your ExampleSteps class should change to more of a delegator class to pages and look like the following

public class ExampleSteps {

WebDriver driver = new FirefoxDriver();

@Given("^the user is on landing page$")
public void setup() throws Throwable {

@When("^she chooses to sign up$")
public void she_chooses_to_sign_up() throws Throwable {
    new LandingPage(driver).she_chooses_to_sign_up();

@And("^she provides the first name as ([^\"]*)$")
public void she_provides_the_first_name_as(String firstName) throws Throwable {
    new SignupPage(driver).she_provides_the_first_name_as(firstName);

@And("^she provides the last name as ([^\"]*)$")
public void she_provides_the_last_name_as(String lastName) throws Throwable {
    new SignupPage(driver).she_provides_the_last_name_as(lastName);

@And("^she provides the email as ([^\"]*)$")
public void she_provides_the_email_as(String email) throws Throwable {
    new SignupPage(driver).she_provides_the_email_as(email);

@And("^she provides the password as ([^\"]*)$")
public void she_provides_the_password_as(String password) throws Throwable {
    new SignupPage(driver).she_provides_the_password_as(password);

@And("^she provides the confirm password again as ([^\"]*)$")
public void she_provides_the_confirm_password_again_as(String confirmPassword) throws Throwable {
    new SignupPage(driver).she_provides_the_confirm_password_again_as(confirmPassword);

@And("^she signs-up$")
public void she_signs_up() throws Throwable {
    new SignupPage(driver).she_signs_up();

@Then("^she should be logged in to the application$")
public void she_should_be_logged_in_to_the_application() throws Throwable {
    Assert.assertTrue(new HomePage(driver).isSignOutLinkDisplayed());

Now, notice how we create the driver in this class. And everytime we delegate a step to the page class method, we create a new page instance with the same driver.


results matching ""

    No results matching ""