cypress e2e tests: page objects vs application actions vs custom commands
Should you use Application Actions when writing cypress tests? Or is the Page Objects pattern better? Or neither and just write tests and use cypress custom commands to share common selectors and user actions? Page Objects is a well established pattern. Create classes for pages in your app and put selectors in those classes. Then in your test use (and reuse) the page object classes methods to simulate user actions such as fill in a field or submit a form. This centralizes and reuses selector code. Application Actions pattern exposes the applications model as a property on window which can be directly edited in cypress test code. Now test setup to add todos so they can be toggled becomes basically like so: `window.appModel.addToDos([{}, {}])` The author provides examples of how to use Application actions including with async operations. Faster setup results in faster tests. And per the author better organized app code. The Application Actions post link argues that Page Objects are a ...