cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.02k stars 3.18k forks source link

https://www.cypress.io/blog/2019/01/03/stop-using-page-objects-and-start-using-app-actions/ is harmful #5893

Closed lsdkjflasjflkdasj closed 4 years ago

lsdkjflasjflkdasj commented 4 years ago

After spending many many hours discussing architecture with the team, I feel that this article has misled them to believe that page objects should not be used AT ALL. There are many use cases of us needing to write tests with a heavily reused final (UI) step in tests. This re-used final step is checkout (like filling out first/last/credit card info etc). To have an app action for this complete credit card form checkout is pretty bad. Each field needs to be filled out atomically due to security concerns (storing info). We need this reusable "form fill out" function somewhere in our testing repo but the article only provided A LOT of confusion.
Here is what we discussed:

  1. just copy paste the "fill out form" code from test to test with raw selectors in it. Absolutely wrong because it will be infeasible to update hard coded selectors all across code.
  2. Make this a command. We discovered that using a command via autocomplete requires forward declarations for autocomplete(index.d.ts). For any "final step is reusable" testing such as the aforementioned checkout/"form fill out" function, this becomes unmaintainable with unrelated forward declarations tightly coupled with arbitrary command files in our testing repo.
  3. Copy and paste the function in every spec that requires final checkout steps. This is also not much better then 1.
  4. Page objects with regular old imports. Because of this article, the team is resistant to using it, even though this solves all of our problems. They see that it's an article officially from Cypress and and reluctant to use page objects because they are misled to believe that app business functions are a substitute, not to mention that the article says page objects are bad. Nowhere in that article does it state that there are valid use cases for page objects while using Cypress.. It instead says that app actions are better. Clearly, in this common use case of checkout or "bottom heavy" reusable tests, it is not.

In short, the article is misleading and harmful. Please at least change the title of it.

lsdkjflasjflkdasj commented 4 years ago

"Do not despair! I will also show an alternative to page objects that I call “Application Actions” that our end-to-end tests can use. I believe application actions solve the above problems very well, making end-to-end tests fast and productive."

Here is the other offending text which basically implies that "Application Actions" are actually an alternative to page objects. They don't replace the behavior of page objects at all.

  1. javascript minification. Mangled names won't work.
  2. Applications that do not use React won't use the model described in the document.
  3. The availability of a javascript executor which can do this in most other browser automating frameworks. This is nothing new actually.
jennifer-shehane commented 4 years ago

Hey @lsdkjflasjflkdasj, Cypress as a product and a team are opinionated. It's part of our culture and we often recommend pathways that we feel are best to use or best to avoid. Being an opinionated product, we also hear lots of opposing opinions from the community and are listening.

I would not take the blog as the end all truth on Cypress. If you find that Page Objects work best for your team then go for it. Thanks for sharing your opinion. It'd be great to see a blog on the solutions you come up with and how Page Objects work for you.

Issues in our GitHub repo are reserved for potential bugs or feature requests, so this issue will be closed since it is neither a bug nor a feature request.

lsdkjflasjflkdasj commented 4 years ago

The documentation clearly states that page object is not to be used and that application actions are the alternative. Yes, this may be an opinion, but when the VP of engineering turns around and says, "yes you can use page object", people are going to be confused. If you say "yes" and "no" at the same time, it's meaningless.

lsdkjflasjflkdasj commented 4 years ago

Logical contradictions in actual officially written documentation should not be there. The bug is this.

jennifer-shehane commented 4 years ago

@lsdkjflasjflkdasj Please feel free to share my above comment with your team. I speak for the Cypress team in saying that if you find Page Objects work best for your team then use them. The blog was an opinion piece.