Skip to content
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

Page Object Model for Playwright tests #737

Merged
merged 16 commits into from
Sep 13, 2024
Merged

Page Object Model for Playwright tests #737

merged 16 commits into from
Sep 13, 2024

Conversation

jessabean
Copy link
Contributor

@jessabean jessabean commented Aug 22, 2024

Description

Adding page objects and fixtures for our existing Playwright tests. Hoping that this can be a template for creating readable e2e tests in the Playwright ecosystem.

This is a precursor to completing the test for filling out the WP, because that PR got huge and I would like for us to carefully review and comment on general approach in a more gradual fashion!

Related ticket(s)

N/A


How to test

  • Run the playwright tests
    • From the root of the MFP project, you can run yarn test:e2e or yarn test:e2e-ui
  • They should all pass

Notes

Some pros (imo)

  • functions that are specific to an area of the report (e.g., filling out specific fields) are contained to that area instead of plopped into one bit test
  • breaks up the many pages of a report so it feels easier to follow the user's journey in the test
  • shorter LOC in the tests because the area-specific functions are abstracted away into the page objects

Some cons (imo)

  • it's a lot of extra files, feels like more LOC === more complexity

Some questions

  • Thing to explore: using soft assertions
  • Should we start thinking about and documenting general e2e best practices and opinions somewhere?
    • For instance, while researching page object model for this PR, I saw many sources state that a best practice is to not use expect in page objects and keep them in the tests. I tried to follow that philosophy here (with the exception of the isReady() functions)

Resources:

Copy link
Contributor

@gmrabian gmrabian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the page model! I have some ideas/preferences that I noted below

tests/e2e/pages/sar/sarDashboard.page.ts Outdated Show resolved Hide resolved
tests/e2e/pages/wp/wpDashboard.page.ts Outdated Show resolved Hide resolved
tests/e2e/pages/wp/wpGeneral.page.ts Outdated Show resolved Hide resolved
tests/e2e/pages/sar/sarDashboard.page.ts Outdated Show resolved Hide resolved
tests/e2e/sar/create.spec.ts Outdated Show resolved Hide resolved
tests/e2e/wp/approve.spec.ts Outdated Show resolved Hide resolved
tests/e2e/wp/approve.spec.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@bangbay-bluetiger bangbay-bluetiger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the fixtures!

tests/e2e/pages/sar/sarDashboard.page.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@gmrabian gmrabian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm still a fan of having the path expectation part of isReady
await expect(wpDashboard.page).toHaveURL(wpDashboard.path);

looks good so far!

tests/e2e/wp/create.spec.ts Show resolved Hide resolved
gmrabian
gmrabian previously approved these changes Sep 12, 2024
Copy link
Contributor

@gmrabian gmrabian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking comments and curiosities below :)

tests/e2e/sar/create.spec.ts Outdated Show resolved Hide resolved
tests/e2e/utils/fixtures/base.ts Show resolved Hide resolved
tests/e2e/utils/pageObjects/sar/sarDashboard.page.ts Outdated Show resolved Hide resolved
Copy link

codeclimate bot commented Sep 13, 2024

Code Climate has analyzed commit 862fbc1 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (90% is the threshold).

This pull request will bring the total coverage in the repository to 92.6% (0.0% change).

View more on Code Climate.

@jessabean jessabean merged commit 6ed7650 into main Sep 13, 2024
22 checks passed
@jessabean jessabean deleted the je-playwright-pom branch September 13, 2024 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants