[DISCUSS] Create FollowerIndexFormPageObject and apply it to follower_index_add tests#34805
[DISCUSS] Create FollowerIndexFormPageObject and apply it to follower_index_add tests#34805cjcenizal wants to merge 2 commits intoelastic:masterfrom
Conversation
… tests. - Create form_helpers and react_router_helpers.
|
Pinging @elastic/es-ui |
💔 Build Failed |
|
Hey, CJ. This is pretty interesting. I have never seen a jest style Page Object Model. Same concept but uses the loading of components in place of searching for selectors. I like it. Definitely want to talk to you more in depth about it when I get back. |
|
Hey @cjcenizal thanks for bringing this. So I will start with my conclusion 😊 and explain my thoughts from there. To me, this comes all down to a developer preference and code style. As such, I don't think we should impose a pattern to how test helpers should be written and have our focus on writing tests that are easy to read and to reason about (whichever the helpers used). With that said, I do think that bringing this PR with the page object pattern opens the discussion to see how we could still improve the readability of the current tests or future tests. But I don't think it is necessary to go in a completely different direction to achieve that. And, to repeat, it would only come down to preference at the end. So.... everything I'll say below this line is my preference and is subjective. 😊 To be able to compare apples with apples I created a "follower_index_form.page_object-v2.js" file that has the same functionality as the one you added but with much fewer lines of code (43 lines vs 83).
And I, personnaly, read it better: expect(exists('loadingRemoteClusters')).toBe(true);
// vs
expect(followerIndexPage.getLoadingRemoteClusters().length).toBe(1);And for the "developer experience", it is also (again for me) better. "Need to add a new page object?": add a line in the
With the v2 version, I bring you can see that it comes down to 2 lines. Instead of a
I would need more context to understand this, otherwise, I would say "yagni" 😊 To conclude I would say: I prefer to give the devs a low-level API with helpers for their testing (the "testBed") and then it is free to them to create a small abstraction and expose page object to their tests if they want. But I would not impose a pattern, and I don't think there is a need to refactor the current tests other than for a preference (although I do think we could improve and create the boundaries like the example I give in "v2"). From this conversation, I am thinking of converting the testBed to Typescript in order to get this |
💔 Build Failed |
|
I think I favor the more functional approach here as opposed to the page object one. The only modification I might suggest is to establish constants for the test subject names, but if that can be accomplished as a typescript thing as @sebelga shows in the v2 screenshot, that would be nifty too. |
|
@sebelga It sounds like we agree on a couple things we can move forward with. Let's do this:
How does this sound? Let me know if you'd like help with any of this! I'm closing this issue because it's served its purpose, but if anyone else has thoughts to share feel free to add them here. |
|
Sounds great @cjcenizal I actually started this work already and hopefully should have a PR by the end of the day. I am not sure though about moving the testbed method to a different repo. I actually moved (for now) the |


I'm creating this to share some ideas with the team and gather feedback. I wanted to try architecting Seb's test helpers a bit differently, to see if it would yield any benefits.
I was inspired by the Page Object pattern used in functional tests when I explored this direction. In that context, they act as an abstraction layer between your tests and the UI being tested. The intention is to make tests more expressive and less dependent upon HTML-level implementation details (e.g. test subject selectors). I'm not sure if this is an intended benefit but I've also always liked how I can scan the page object and "see" what I'm capable of doing with a particular UI.
After I applied the pattern to our tests, I spotted what I think are three main benefits:
initTestBed,initUserActions,registerTestBed, andgetUserActions, helpers are pure functions which are only consumed by the page object and not used directly within the tests.@elastic/elastic-ui, @silne30, and Seb, I'd love to hear everyone's thoughts on this.