To me the Locator is the one exposing technical implementation(the CSS selector .todo-list li) and it's nice to have a page object like findTodoItems() to return that, disregarding the implementation detail and its fragile nature.
The second part Assertion is, by looking at its raw cypress commands should('have.length', 2), pretty straightforward. Adding another page object layer like validateTodoCount(expectedLength) seems to be an overkill.
As such, I feel we don't always need to include straightforward assertions into page object. Instead, in some assertion that is comprised of couple checks/steps/hacky things, page object assertion-function calls may be easier to understand and let us focus on the higher level business outcome.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I am not sure if we should wrap every single expectation into the page object function call.
For example in the todo list count example you mentioned, the check can be broken into two parts Locator and Assertion
To me the Locator is the one exposing technical implementation(the CSS selector
.todo-list li
) and it's nice to have a page object likefindTodoItems()
to return that, disregarding the implementation detail and its fragile nature.The second part
Assertion
is, by looking at its raw cypress commandsshould('have.length', 2)
, pretty straightforward. Adding another page object layer likevalidateTodoCount(expectedLength)
seems to be an overkill.As such, I feel we don't always need to include straightforward assertions into page object. Instead, in some assertion that is comprised of couple checks/steps/hacky things, page object assertion-function calls may be easier to understand and let us focus on the higher level business outcome.