Let's consider an example from WebDriver where I create two different classes to deal with page object, one stores the element locator and other actual operations dealing with page -
public class ContactPageElements {
private By nameTextBox = By.id("name");
public static By getNameLocator() {
return nameTextBox;
}
}
public class ContactPage {
public ContactPage enterName(String name) {
findElement(ContactPageElements.getNameLocator()).sendKeys(name);
return this;
}
}
Now if I were to replace WebDriver with snazy new test framework then I would break the ContactPage class since it depends on By
object being returned from ContactPageElements class.
Hence it appears to me that ContactPageElements
class should not have a public method returning By object. But then what option am I left with?
I am hesitant to keep element locators in the ContactPage
as I may end up violating single responsibility principle.