For writing maintainable and scalable E2E Test.
Switch branches/tags
Nothing to show
Clone or download
Failed to load latest commit information. Update Jun 19, 2017


Our goal is to get together Selenium best practices. Feedback is welcome. If you see anything wrong or know better way open an issue or create a pull request, just fork it and change it. We are open to learn and hear new ideas.


Selenium is a portable software testing framework for web applications. It also provides a test domain-specific language to write tests in a number of popular programming languages, including Java, C#, Groovy, Perl, PHP, Python and Ruby.

Use PageObjects Pattern

Page Object is a Design Pattern which has become popular in test automation for enhancing test maintenance and reducing code duplication. An implementation of the page object model can be achieved by separating the abstraction of the test object and the test scripts.

Advantages of using Page Object Pattern:

  • Easy to Maintain
  • Easy Readability of scripts
  • Reduce or Eliminate duplicacy
  • Re-usability of code
  • Reliability
  • There is a clean separation between test code and page specific code such as locators and layout.

Use multi config for each environment. Make it changeable. Read your test case value from config. Don't use a static.


  • Don't use magic strings.
  • Separate to WebPageElement, WebPageObject, WebTest.

Prefered Selector Order

Preferred selector order : id > name >links text> css > xpath

CSS and XPath are location based selectors, they are slower than other selectors.

  • Id and name are often the easiest and sure way.
  • CSS = Id + name.
  • Last solution should be xpath.

Create Ordered Tests

import org.junit.runners.MethodSorters;

//Running tests in order of method names in ascending order
//Running tests in order of method names in ascending order

Get Name of the Running Test

import org.junit.rules.TestName;

public TestName name = new TestName();

//example usage; writes every test name before it runs.
    public void logBeforeTestsStart() {;

Do not use Magic Strings

It improves readability of the code and it's easier to maintain.

WebDriver driver = new HtmlUnitDriver();
// Don't use, create Constants each element name
WebElement element = driver.findElement("sample"));

Behavior Driven Design

BDD is principally an idea about how software development should be managed by both business interests and technical insight, the practice of BDD assumes the use of specialized software tools to support the development process. Think all test scenarios.

Example BDD

Feature: Sign up

Sign up should be quick.
Write all steps.
1- Open Browser
2-Navigate to Url
3-Click Sign Up Button
4-Write Valid Username and Password
5-Click Register.

Scenario: Successful sign up
New users should get a confirmation email and be greeted
personally by the site once signed in.

Given I have chosen to sign up
When I sign up with valid details
Then I should receive a confirmation email
And I should see a personalized greeting message

Scenario: Duplicate email

Where someone tries to create an account for an email address
that already exists.

Given I have chosen to sign up
But I enter an email address that has already registered
Then I should be told that the email is already registered
And I should be offered the option to recover my password

###Simple Example

##Page Element Class

//Write clear class  name.
public class WebLoginPageElement {

    private String emailInputId;
    private String passwordInputId;
    public WebLoginPageElement() {
        this.emailInputId = "Email";
        this.passwordInputId = "Password";
    public String getEmailInputId() {
        return emailInputId;}
    public String getPasswordInputId() {
        return passwordInputId;}

##Page Object Class

public class WebLoginPage extends Function {

   //Make own custom WebElement Class.
   private WebElementFactory elementFactory;
   private IWebAction elementAction;
   private WebLoginPageElement loginPageElement;

   public WebLoginPage() {
     elementFactory = new WebElementFactory(driver);
     elementAction = new WebAction(driver);
     loginPageElement = new WebLoginPageElement();

   public WebLoginPage login(String email, String password) {
    WebElement emailInputElement = 
      elementAction.sendKeys(emailInputElement, email);

    WebElement passwordInputElement = 
      elementAction.sendKeys(passwordInputElement, password);

    WebElement loginSubmitButton =
        return this;}

##Test Class

public class WebLoginTest extends Function {

    private static org.apache.log4j.Logger log = Logger.getLogger(WebLoginTest.class);
    WebElementFactory elementFactory = new WebElementFactory(driver);
    private static WebLoginPageElement loginPageElement = new WebLoginPageElement();
    public TestName name = new TestName();

    public static void setUpBeforeClass() throws Exception {
    public static void tearDownAfterClass() throws Exception {
    //Test all scenarios. 
    public void loginWithEmptyUsername() throws Exception {
        //Call loginPage 
        new WebLoginPage().login(
    public void loginWithWrongFormat(){
    public void loginWithWrongFormatId(){