-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add page object structure for User creation tests #3219
Conversation
I think that's a very valuable approach. Historically, we tend to be explicit in tests and don't use too many helpers or abstractions; nevertheless in this case our previous approach went a bit too far and some benefit was lost, in my opinion. I want to discuss a bit about the problems page objects are blamed for bringing to a cypress codebase.
The hard part to maintain is the cypress selectors, and we will have that problem anyway. The worst I see is we just move them to another file.
This is true and it's very dangerous because it hides knowledge from the test cases and makes them hard to understand. However, you don't have to save any state into the object. If any method has no effect on the others, we still have an explicit interface (beware that this is not 100% true because methods act on the same page via the
I don't expect more logic than the one required to access page elements and interact with them. Things like HTTP request intercept, timers, etc should be kept on the test case.
I don't know if I get this right. All our tests go through the UI anyway, isn't it? In the end, I propose the following pattern:
Something like this: // dashboard-po.js
export * from './base-po.js' // if you want to keep inheritance, but it can be removed
const usernameInputField = 'input[autocomplete="username"]';
const passwordInputField = 'input[autocomplete="current-password"]';
...
export function login(username, password) {
cy.get(usernameInputField).type(username);
cy.get(passwordInputField).type(password);
return clickSubmitLoginButton();
}
export function clickSubmitLoginButton() {
...
}
... What do you think? |
I'll reply point by point :)
As an example:
with this, without even knowing how to code you get what the test does, the page object gives you context and the function name describes what it does
Regarding using the modules structure instead of a class I think we can try it, as in the end, we can achieve the same objective still The base page object is basically for common stuff (navigation menu) or generic functions that can be Last but not least, a big win with this approach is that it helps a lot to maintain the tests isolated from each other. Now, you can run any test on this file independently without the need to execute some others previously, which will make our lives easier in case of a failure. |
|
btw, the module structure has been commited & pushed :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow that's a huge PR. It's incredibly nice to have this. I honestly didn't read all the code, but as @balanza was pointing out the new module structure is great!
Description
While there are different opinions on using the Page Object pattern in Cypress, I believe it offers a more maintainable approach given the size of our test suite. It allows us to keep app actions and functions organized within dedicated classes, rather than spreading them across the
commands.js
file or directly in the test files. This structure improves readability, as test files should clearly communicate what our product does without unnecessary noise or distractions.No changes required in docs.
Fixes # (issue)
Did you add the right label?
Remember to add the right labels to this PR.
How was this tested?
Describe the tests that have been added/changed for this new behavior.
Did you update the documentation?
Remember to ask yourself if your PR requires changes to the following documentation:
Add a documentation PR or write that no changes are required for the documentation.