문제

For example, if I were to test Google search, what is the benefit of the Page Object model returning new Google Search Page Object?

E.g.

public class SearchPage {
    private final WebDriver driver;

    public SearchPage(WebDriver driver) {
        this.driver = driver;
    }

    public SearchPage search(String query) {
        WebElement e = driver.findElement(By.name("q")).sendKeys(query);
        e.submit();

        return new SearchPage(driver);
    }
}

vs

public class SearchPage {
    private final WebDriver driver;

    public SearchPage(WebDriver driver) {
        this.driver = driver;
    }

    public void search(String query) {
        WebElement e = driver.findElement(By.name("q")).sendKeys(query);
        e.submit();
    }
}

Thanks for the help!

도움이 되었습니까?

해결책

One thing that comes to my mind is chaining the methods from SearchPage class. When you would have lets say some higher level class that is responsible for running the tests you could use sth like this:

String actualText = searchPage.search("q").openFirstResult().selectItemFromCombo().checkName().getNameText() 

etc. etc.

This makes reading your code very easy, looks almost like a sentence and it is understandable for othe people.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top