2

Can anyone suggest the best architecture for a selenium webdriver project (Java) which is easy to maintain. Although there are design patterns available like Page Objects etc but I want to know which is the best i.e. what architecture or framework is used currently in professional projects.

Like for projects in which:

  1. Custom reporting are done
  2. It is easy to handle the changes in locators.
  3. Duplicate code is not there (like with Page Objects approach)
  4. Some standards are followed while checking or asserting the values or conditions
Chris
  • 5,442
  • 17
  • 30
Vikram
  • 31
  • 4
  • there are all kinds of frameworks out there, including the [getting started with selenium](https://github.com/ddavison/getting-started-with-selenium) project which is used by a couple companies, including Major League Gaming. It's sort of bare because it's designed for people like you wanting custom solutions, but something that has current programming paradigms like fluency, and inline validations. Though this project in particular doesn't match your requirements of the Page Object Pattern, custom reporting, and build tool. Again, it's supposed to be custom to your needs. – ddavison Apr 09 '14 at 12:56

1 Answers1

4

Few things which we have learned
1. Use Page Object to remove application specific redundant code
While designing Page Objects remember that its not necessary to map each page to class, you can map bunch of pages on single class. Don't create a separate class if page provides very little interaction.
2. Keep dynamic/changing things aside
We keep locators (type and value) in properties file so that we can change them later
like

login.username.identifier=id
login.username.expression=ctl00_MainContent_uxUserNameText

and have written generic method to find elements

  * Method to retrieve element
     * @param identifier to locate element
     * @param expression value
     * @return WebElement
     */
    public WebElement getElement(Identifier identifier, String expression) {
        By byElement = null;
        switch (identifier) {
        case xpath: {
            byElement = By.xpath(expression);
            break;
        }
        case id: {
            byElement = By.id(expression);
            break;
        }
        case name: {
            byElement = By.name(expression);
            break;
        }
        case classname: {
            byElement = By.className(expression);
            break;
        }
        case css: {
            byElement = By.cssSelector(expression);
            break;
        }
        case linktext: {
            byElement = By.linkText(expression);
            break;
        }
        case paritallinktext: {
            byElement = By.partialLinkText(expression);
            break;
        }
        case tagname: {
            byElement = By.tagName(expression);
            break;
        }
        }
        WebElement query = driver.findElement(byElement);
        return query;
    }

3. Reduce Selenium specific redundant code using reusable method
We have written methods for frequently used Selenium tasks

 * Method to check if alert is present
     * @return True/False
     */
    public boolean isAlertPresent() {
        boolean isPresent = true;
        try {
            driver.switchTo().alert();
        } catch (NoAlertPresentException e) {
            isPresent = false;
        }
        return isPresent;
    }
Ajinkya
  • 22,324
  • 33
  • 110
  • 161