Page Object Selenium Testing Pattern
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
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?
java selenium webdriver integration-testing cucumber
add a comment |Â
up vote
0
down vote
favorite
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?
java selenium webdriver integration-testing cucumber
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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?
java selenium webdriver integration-testing cucumber
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?
java selenium webdriver integration-testing cucumber
edited Jan 16 at 22:51
asked Jan 16 at 21:52
fralewsmi
13
13
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password