Architecture (like File structure) of a Selenium webdriver projects(Java) which is easy to maintain and not using any build tool [closed]

StackOverflow https://stackoverflow.com/questions/22961564

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
有帮助吗?

解决方案

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;
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top