Page Object Selenium Testing Pattern

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite
2












I'm trying to nail down on some best practices for automation testing with a large test suite.



What I have is a set of page objects (e.g. LoginPage.java, HomePage.java), which all inherit from AbstractPage.java (used for common functionality). These are in the pages package



All the page objects are initialized in PageInitializer.java, which calls their constructor. The cucumber step definition files (e.g. LoginSteps.java, HomePageSteps.java) inherit from PageInitializer.java, so that they have access to the methods and fields from the page objects when running the tests. These are in the steps package.



I've added a generic example of the implementation:



AbstractPage.java



package pages; 

public abstract class AbstractPage

AbstractPage()

void click(String name, By locator) /* generic click method */



LoginPage.java



package pages; 

public class LoginPage extends AbstractPage

private static final By locatorLoginButton = By.id("login);

public LoginPage() super();

public void clickLogin()
abstractPage.click("login button", locatorLoginButton);




PageInitializer.Java



package steps; 

public class PageInitializer

private LoginPage loginPage;

LoginPage loginPage()
if (this.loginPage == null)
loginPage = new LoginPage();
return loginPage;

return this.loginPage;




LoginSteps.java



package steps; 

public class LoginSteps extends PageInitializer

@When("I click login button$")
public void iClickLoginButton()
loginPage.clickLogin()




In reality, there's over 10 pages inheriting from AbstractPage.java, all of which are initialized in PageInitializer.java. There is a similar number of step definition files.



My question is, what best practices can I apply to my test suite to improve the quality of the code, and are there any issues with the way I am currently doing things?







share|improve this question



























    up vote
    0
    down vote

    favorite
    2












    I'm trying to nail down on some best practices for automation testing with a large test suite.



    What I have is a set of page objects (e.g. LoginPage.java, HomePage.java), which all inherit from AbstractPage.java (used for common functionality). These are in the pages package



    All the page objects are initialized in PageInitializer.java, which calls their constructor. The cucumber step definition files (e.g. LoginSteps.java, HomePageSteps.java) inherit from PageInitializer.java, so that they have access to the methods and fields from the page objects when running the tests. These are in the steps package.



    I've added a generic example of the implementation:



    AbstractPage.java



    package pages; 

    public abstract class AbstractPage

    AbstractPage()

    void click(String name, By locator) /* generic click method */



    LoginPage.java



    package pages; 

    public class LoginPage extends AbstractPage

    private static final By locatorLoginButton = By.id("login);

    public LoginPage() super();

    public void clickLogin()
    abstractPage.click("login button", locatorLoginButton);




    PageInitializer.Java



    package steps; 

    public class PageInitializer

    private LoginPage loginPage;

    LoginPage loginPage()
    if (this.loginPage == null)
    loginPage = new LoginPage();
    return loginPage;

    return this.loginPage;




    LoginSteps.java



    package steps; 

    public class LoginSteps extends PageInitializer

    @When("I click login button$")
    public void iClickLoginButton()
    loginPage.clickLogin()




    In reality, there's over 10 pages inheriting from AbstractPage.java, all of which are initialized in PageInitializer.java. There is a similar number of step definition files.



    My question is, what best practices can I apply to my test suite to improve the quality of the code, and are there any issues with the way I am currently doing things?







    share|improve this question























      up vote
      0
      down vote

      favorite
      2









      up vote
      0
      down vote

      favorite
      2






      2





      I'm trying to nail down on some best practices for automation testing with a large test suite.



      What I have is a set of page objects (e.g. LoginPage.java, HomePage.java), which all inherit from AbstractPage.java (used for common functionality). These are in the pages package



      All the page objects are initialized in PageInitializer.java, which calls their constructor. The cucumber step definition files (e.g. LoginSteps.java, HomePageSteps.java) inherit from PageInitializer.java, so that they have access to the methods and fields from the page objects when running the tests. These are in the steps package.



      I've added a generic example of the implementation:



      AbstractPage.java



      package pages; 

      public abstract class AbstractPage

      AbstractPage()

      void click(String name, By locator) /* generic click method */



      LoginPage.java



      package pages; 

      public class LoginPage extends AbstractPage

      private static final By locatorLoginButton = By.id("login);

      public LoginPage() super();

      public void clickLogin()
      abstractPage.click("login button", locatorLoginButton);




      PageInitializer.Java



      package steps; 

      public class PageInitializer

      private LoginPage loginPage;

      LoginPage loginPage()
      if (this.loginPage == null)
      loginPage = new LoginPage();
      return loginPage;

      return this.loginPage;




      LoginSteps.java



      package steps; 

      public class LoginSteps extends PageInitializer

      @When("I click login button$")
      public void iClickLoginButton()
      loginPage.clickLogin()




      In reality, there's over 10 pages inheriting from AbstractPage.java, all of which are initialized in PageInitializer.java. There is a similar number of step definition files.



      My question is, what best practices can I apply to my test suite to improve the quality of the code, and are there any issues with the way I am currently doing things?







      share|improve this question













      I'm trying to nail down on some best practices for automation testing with a large test suite.



      What I have is a set of page objects (e.g. LoginPage.java, HomePage.java), which all inherit from AbstractPage.java (used for common functionality). These are in the pages package



      All the page objects are initialized in PageInitializer.java, which calls their constructor. The cucumber step definition files (e.g. LoginSteps.java, HomePageSteps.java) inherit from PageInitializer.java, so that they have access to the methods and fields from the page objects when running the tests. These are in the steps package.



      I've added a generic example of the implementation:



      AbstractPage.java



      package pages; 

      public abstract class AbstractPage

      AbstractPage()

      void click(String name, By locator) /* generic click method */



      LoginPage.java



      package pages; 

      public class LoginPage extends AbstractPage

      private static final By locatorLoginButton = By.id("login);

      public LoginPage() super();

      public void clickLogin()
      abstractPage.click("login button", locatorLoginButton);




      PageInitializer.Java



      package steps; 

      public class PageInitializer

      private LoginPage loginPage;

      LoginPage loginPage()
      if (this.loginPage == null)
      loginPage = new LoginPage();
      return loginPage;

      return this.loginPage;




      LoginSteps.java



      package steps; 

      public class LoginSteps extends PageInitializer

      @When("I click login button$")
      public void iClickLoginButton()
      loginPage.clickLogin()




      In reality, there's over 10 pages inheriting from AbstractPage.java, all of which are initialized in PageInitializer.java. There is a similar number of step definition files.



      My question is, what best practices can I apply to my test suite to improve the quality of the code, and are there any issues with the way I am currently doing things?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jan 16 at 22:51
























      asked Jan 16 at 21:52









      fralewsmi

      13




      13

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f185259%2fpage-object-selenium-testing-pattern%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f185259%2fpage-object-selenium-testing-pattern%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Chat program with C++ and SFML

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          Will my employers contract hold up in court?