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

Add Playwright e2e test suite ready for incremental migration and visual regression testing #7671

Merged
merged 90 commits into from
Apr 19, 2024

Conversation

Jinksi
Copy link
Member

@Jinksi Jinksi commented Nov 9, 2023

Resolves #8177

Changes proposed in this Pull Request

This PR lays the foundation for Playwright e2e and visual regression testing, ready for incremental migration of existing Puppeteer e2e tests.

Migrating our e2e tests to use Playwright instead of Puppeteer will provide us benefits including, but not limited to:

  • Reduced test flakiness/increased test stability with auto-waiting and configurable test retries.
  • Easier to write robust and maintainable e2e tests with locators for targeting DOM elements using testing-library APIs (consistent with integration test APIs).
  • Visual regression testing to help us update component library dependencies with more confidence.

To aid in migration, this PR follows the WooCommerce Puppeteer to Playwright migration guide which adds a Playwright test suite alongside the existing Puppeteer test suite.

TODO

Notes/inclusions:

  • The fundamental Playwright boilerplate and config.
  • Authentication setup step for admin & customer with caching for local dev envs.
  • Some initial basic tests with visual regression snapshots.
  • Uses the existing e2e docker environment setup.
  • Uses many of the same conventions from the WC Puppeteer to Playwright migration guide (e.g. e2e-pw directory).
  • A GH action that runs e2e-pw on PRs to develop or trunk and outputs the Playwright HTML report as a GH action artefact (see this workflow run)
image

Testing instructions

  1. npm install
  2. Setup e2e environment
    1. npm run test:e2e-setup
    2. npm run test:e2e-up
  3. Run e2e tests with Playwright
    • npm run test:e2e-pw headless run from within a linux docker container.
    • npm run test:e2e-pw-ui runs tests in interactive UI mode from within a linux docker container – recommended for authoring tests and re-running failed tests.
    • npm run test:e2e-pw keyword runs tests only with a specific keyword in the file name, e.g. dispute or checkout.
    • npm run test:e2e-pw --update-snapshots updates snapshots.
  4. Ensure the GH check E2E Playwright Tests passes
    • View the summary of the GH check run and download the playwright-report.zip
    • Open the index.html locally in your browser to view the test report
  5. Ensure Puppeteer tests pass

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests
  • Tested on mobile N/A

Post merge

@botwoo
Copy link
Collaborator

botwoo commented Nov 9, 2023

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 7671 or branch name try/playwright-e2e-tests in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: 9cd9095
  • Build time: 2024-04-19 01:24:10 UTC

Note: the build is updated when a new commit is pushed to this PR.

Copy link
Contributor

github-actions bot commented Nov 9, 2023

Size Change: -3.73 kB (0%)

Total Size: 1.25 MB

Filename Size Change
release/woocommerce-payments/dist/blocks-checkout.js 56.3 kB -768 B (-1%)
release/woocommerce-payments/dist/bnpl-announcement.js 20 kB -19 B (0%)
release/woocommerce-payments/dist/cart-block.js 21.4 kB -45 B (0%)
release/woocommerce-payments/dist/cart.js 4.41 kB -117 B (-3%)
release/woocommerce-payments/dist/checkout.js 37.5 kB -325 B (-1%)
release/woocommerce-payments/dist/index.js 291 kB -382 B (0%)
release/woocommerce-payments/dist/multi-currency-switcher-block.js 59.5 kB -161 B (0%)
release/woocommerce-payments/dist/multi-currency.js 54.6 kB -154 B (0%)
release/woocommerce-payments/dist/order.js 41.8 kB -173 B (0%)
release/woocommerce-payments/dist/payment-gateways.js 38.6 kB -159 B (0%)
release/woocommerce-payments/dist/payment-request.js 12 kB -476 B (-4%)
release/woocommerce-payments/dist/product-details.js 17.2 kB -58 B (0%)
release/woocommerce-payments/dist/settings.js 202 kB -457 B (0%)
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 19.4 kB -9 B (0%)
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 693 B -17 B (-2%)
release/woocommerce-payments/dist/woopay-direct-checkout.js 4.56 kB -118 B (-3%)
release/woocommerce-payments/dist/woopay-express-button.js 21 kB -139 B (-1%)
release/woocommerce-payments/dist/woopay.js 70.8 kB -151 B (0%)
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.08 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.08 kB
release/woocommerce-payments/assets/css/success.css 158 B
release/woocommerce-payments/assets/css/success.rtl.css 158 B
release/woocommerce-payments/dist/blocks-checkout-rtl.css 2.02 kB
release/woocommerce-payments/dist/blocks-checkout.css 2.02 kB
release/woocommerce-payments/dist/bnpl-announcement-rtl.css 530 B
release/woocommerce-payments/dist/bnpl-announcement.css 531 B
release/woocommerce-payments/dist/checkout-rtl.css 599 B
release/woocommerce-payments/dist/checkout.css 599 B
release/woocommerce-payments/dist/index-rtl.css 40.4 kB
release/woocommerce-payments/dist/index.css 40.4 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.05 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 3.28 kB
release/woocommerce-payments/dist/multi-currency.css 3.29 kB
release/woocommerce-payments/dist/order-rtl.css 733 B
release/woocommerce-payments/dist/order.css 735 B
release/woocommerce-payments/dist/payment-gateways-rtl.css 1.21 kB
release/woocommerce-payments/dist/payment-gateways.css 1.21 kB
release/woocommerce-payments/dist/payment-request-rtl.css 155 B
release/woocommerce-payments/dist/payment-request.css 155 B
release/woocommerce-payments/dist/product-details-rtl.css 398 B
release/woocommerce-payments/dist/product-details.css 402 B
release/woocommerce-payments/dist/settings-rtl.css 11 kB
release/woocommerce-payments/dist/settings.css 10.8 kB
release/woocommerce-payments/dist/subscription-edit-page.js 669 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 527 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 527 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 18.5 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 236 B
release/woocommerce-payments/dist/tos.js 21 kB
release/woocommerce-payments/dist/woopay-express-button-rtl.css 155 B
release/woocommerce-payments/dist/woopay-express-button.css 155 B
release/woocommerce-payments/dist/woopay-rtl.css 4.44 kB
release/woocommerce-payments/dist/woopay.css 4.41 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 622 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 815 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.44 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.01 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 522 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 581 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/babel.config.js 160 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.css 2.37 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.js 13.5 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.rtl.css 2.37 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.03 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 291 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 403 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.6 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 299 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 742 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 572 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 411 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.4 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.8 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.83 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.52 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.6 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 502 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 355 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 429 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 781 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.27 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 392 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.05 kB

compressed-size-action

@haszari

This comment was marked as resolved.

@Jinksi Jinksi added the category: e2e Issues and PRs related to e2e tests. label Dec 15, 2023
@Jinksi Jinksi changed the title Use Playwright for e2e visual regression Exploration: Use Playwright for e2e visual regression Dec 15, 2023
Take a partial screenshot focusing only on the WCPay page element to avoid flakiness caused by general notices and banners.
To review required changes and refactors to also get rid of @woocommerce/e2e-utils
@Jinksi
Copy link
Member Author

Jinksi commented Mar 21, 2024

Thanks for taking a look @reykjalin 🙌

npm run test:e2e-setup fails
I don't think that's related to this PR so it's probably something in my environment

It shouldn't be impacted by this PR, how does this script go on develop?

I'd suggest running npm run test:e2e-reset and npm run test:e2e-setup if you haven't already.

@Jinksi Jinksi removed this from the Helix WooPayments 7.4 milestone Mar 21, 2024
Copy link
Contributor

@reykjalin reykjalin left a comment

Choose a reason for hiding this comment

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

This is all looking really good! Got this working in Rancher desktop too, so you don't even need Docker 🙌

npm run test:e2e-pw-ui only showed the auth tests though, not sure why that's happening?

@Jinksi Jinksi added this to the Helix WooPayments 7.5 milestone Mar 27, 2024
@Jinksi
Copy link
Member Author

Jinksi commented Mar 27, 2024

npm run test:e2e-pw-ui only showed the auth tests though, not sure why that's happening?

@reykjalin This might happen when restarting the container (re-running npm run test:e2e-pw-ui). A new ws key is generated for the UI each time.

E.g. localhost:8077/trace/uiMode.html?ws=7bebab541dcfed2157412f1461a5bca7

You can fix this by visited http://localhost:8077/ without the ws key.

@reykjalin
Copy link
Contributor

reykjalin commented Apr 1, 2024

You can fix this by visited http://localhost:8077/ without the ws key

Hmm, that doesn't seem to work 🤔 . npm run test:e2e-pw still runs all 13 tests just fine, but npm run test:e2e-pw-ui only has the auth tests. Not sure why tbh, but might not be super important?

@ismaeldcom
Copy link
Contributor

Hey @reykjalin, that's probably because Playwright UI only shows the first project by default, which is the setup part in our case.

Copy link
Contributor

@reykjalin reykjalin left a comment

Choose a reason for hiding this comment

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

Hey @reykjalin, that's probably because Playwright UI only shows the first project by default, which is the setup part in our case.

Oh, that's exactly it! I didn't even think to click that, and even if I had I wouldn't have thought to click "chromium". Is there a way we can change the name of the project?

image

Also, it seems that basic.spec.ts and auth.setup.ts serve a very similar purpose. Or at least they're basically the same tests. It's probably enough to keep only one of those? Or somehow merge them?

@ismaeldcom
Copy link
Contributor

Is there a way we can change the name of the project?

I think we could rename it here, AFAIK that's the actual name, the browser comes from the use property.

@Jinksi Jinksi removed this from the Helix WooPayments 7.5 milestone Apr 8, 2024
@Jinksi
Copy link
Member Author

Jinksi commented Apr 8, 2024

Reading the docs, PW projects lean towards being used to designate testing for multiple browsers, hence the default chromium project.

But I've attempted a merchant/shopper/setup/basic project outline in 07e31b6. This results in the snapshots moving into the /specs/merchant|shopper dir, which is all good.

image

It's probably enough to keep only one of those? Or somehow merge them?

I think basic is worth keeping since I've found it to be a "canary" that lets me know that something more fundamental is going wrong with my local env (e.g. if I forget npm run build).

I tried it merged with setup, but then it runs on every test run, which is a bother since basic takes a second or so to run while setup is instant after the initial auth.

Copy link
Contributor

@reykjalin reykjalin left a comment

Choose a reason for hiding this comment

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

LGTM, awesome work 👏 🚀

@Jinksi
Copy link
Member Author

Jinksi commented Apr 9, 2024

@achyuthajoy would you still like to re-review this PR?

Copy link
Contributor

@achyuthajoy achyuthajoy left a comment

Choose a reason for hiding this comment

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

Thanks for working @Jinksi. Tested the changes and works well.

LGTM 🚢

@Jinksi
Copy link
Member Author

Jinksi commented Apr 16, 2024

Thanks! I'll aim to merge this ASAP (Wednesday Friday 🤷).

@Jinksi
Copy link
Member Author

Jinksi commented Apr 19, 2024

Failing Compatibility and Code coverage GH checks are unrelated – due to #8662.

@Jinksi Jinksi added this pull request to the merge queue Apr 19, 2024
Merged via the queue into develop with commit b12c6c6 Apr 19, 2024
21 of 23 checks passed
@Jinksi Jinksi deleted the try/playwright-e2e-tests branch April 19, 2024 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: e2e Issues and PRs related to e2e tests. pr: ready to merge type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set up Playwright e2e test framework to improve test authoring and maintainability
7 participants