I
I
Ivan Petrov2017-06-23 00:13:52
Java
Ivan Petrov, 2017-06-23 00:13:52

How to properly use encapsulation in Page Object pattern?

Tell me how to properly use encapsulation in the Page Object pattern.
I read that only methods from PageObject, such as login , addToCart , etc., should be available to the client, and it's better not to use selenium methods, such as driver.click() , in tests .
But often in tests you need access to page elements, you just need to click on them, for example, or check visibility.
If you hide all page elements in a PageObject, the encapsulation becomes absurd, and you will have to write getters for each element or methods like addToCartButtonClick() .
It seems to be correct to hide elements inside PageObject and use only methods, but in practice it is very inconvenient. How to do it right?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Fat Lorrie, 2017-06-23
@bitande

encapsulation reaches the point of absurdity, and you have to write getters for each element or methods like addToCartButtonClick().

Supporting OOP with SOLID and other DRY is not very convenient at all, but what can you do?)
Another thing is that instead addToCartButtonClickthere should be a method addProductToChartwhere the PageObject already decides what it needs: press the button, pull the slider, etc., then this can be called encapsulation and the absurdity will disappear.
If you don't need getters for each element, then make them private. Obviously, a good OOP code tries to hide as much as possible in the class, make it static and constant, and expose the user only what is necessary and sufficient to solve his problems.

M
mipan, 2017-06-23
@mipan

PageObject means working with page elements in the test without calling the webdriver directly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question