Skip to content

Commit fe5d9ce

Browse files
meravimeraviyouknowriadhimanshupathak95Mamaduka
authored
Docs: Remove Puppeteer references and update to Playwright (WordPress#76766)
Co-authored-by: meravi <ravikhadka@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: himanshupathak95 <abcd95@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
1 parent 4eeb1d5 commit fe5d9ce

File tree

5 files changed

+18
-55
lines changed

5 files changed

+18
-55
lines changed

docs/contributors/code/e2e/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ It's slow to set states manually before or after tests, especially when they're
7979

8080
### Avoid global variables
8181

82-
Previously in our Jest + Puppeteer E2E tests, `page` and `browser` are exposed as global variables. This makes it harder to work with when we have multiple pages/tabs in the same test, or if we want to run multiple tests in parallel. `@playwright/test` has the concept of [fixtures](https://playwright.dev/docs/test-fixtures) which allows us to inject `page`, `browser`, and other parameters into the tests.
82+
In the previous E2E setup, `page` and `browser` were global variables, which made working with multiple pages or parallel tests harder.
83+
84+
`@playwright/test` uses fixtures to inject `page`, `browser`, and other parameters into tests.
8385

8486
### Make explicit assertions
8587

docs/contributors/code/testing-overview.md

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,7 @@ There is an ongoing effort to add integration tests to the native mobile project
506506

507507
## End-to-end testing
508508

509-
Most existing End-to-end tests currently use [Puppeteer](https://github.com/puppeteer/puppeteer) as a headless Chromium driver to run the tests in `packages/e2e-tests`, and are otherwise still run by a [Jest](https://jestjs.io/) test runner.
510-
511-
There's an ongoing [project](https://github.com/WordPress/gutenberg/issues/38851) to migrate them from Puppeteer to Playwright. **It's recommended to write new e2e tests in Playwright whenever possible**. The sections below mostly apply to the old Jest + Puppeteer framework. See the dedicated [guide](/docs/contributors/code/e2e/README.md) if you're writing tests with Playwright.
509+
End-to-end tests use [Playwright](https://playwright.dev/) as the testing framework. See the dedicated [End-to-End Testing guide](/docs/contributors/code/e2e/README.md) for best practices and detailed instructions.
512510

513511
### Using wp-env
514512

@@ -521,46 +519,14 @@ npm run test:e2e
521519
or interactively
522520
523521
```bash
524-
npm run test:e2e:watch
525-
```
526-
527-
Sometimes it's useful to observe the browser while running tests. Then, use this command:
528-
529-
```bash
530-
npm run test:e2e:watch -- --puppeteer-interactive
531-
```
532-
533-
You can control the speed of execution with `--puppeteer-slowmo`:
534-
535-
```bash
536-
npm run test:e2e:watch -- --puppeteer-interactive --puppeteer-slowmo=200
537-
```
538-
539-
You can additionally have the devtools automatically open for interactive debugging in the browser:
540-
541-
```bash
542-
npm run test:e2e:watch -- --puppeteer-devtools
543-
```
544-
545-
### Using alternate environment
546-
547-
If using a different setup than `wp-env`, you first need to symlink the e2e test plugins to your test site, from your site's plugins directory run:
548-
549-
```bash
550-
ln -s gutenberg/packages/e2e-tests/plugins/* .
551-
```
552-
553-
Then to run the tests, specify the base URL, username, and passwords for your site. For example, if your test site is at `http://wp.test`, use:
554-
555-
```bash
556-
WP_BASE_URL=http://wp.test npm run test:e2e -- --wordpress-username=admin --wordpress-password=password
522+
npm run test:e2e -- --ui
557523
```
558524
559525
### Scenario testing
560526
561527
If you find that end-to-end tests pass when run locally, but fail in GitHub Actions, you may be able to isolate a CPU- or network-bound race condition by simulating a slow CPU or network:
562528
563-
```
529+
```bash
564530
THROTTLE_CPU=4 npm run test:e2e
565531
```
566532

docs/explanations/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
- [Modularity and WordPress Packages](/docs/explanations/architecture/modularity.md).
88
- [Block Editor Performance](/docs/explanations/architecture/performance.md).
99
- What are the design decisions behind the Data Module?
10-
- [Why is Puppeteer the tool of choice for end-to-end tests?](/docs/explanations/architecture/automated-testing.md)
10+
- [Why is Playwright the tool of choice for end-to-end tests?](/docs/explanations/architecture/automated-testing.md)
1111
- [What’s the difference between the different editor packages? What’s the purpose of each package?](/docs/explanations/architecture/modularity.md#whats-the-difference-between-the-different-editor-packages-whats-the-purpose-of-each-package)
1212
- [Template and template parts flows](/docs/explanations/architecture/full-site-editing-templates.md)

docs/explanations/architecture/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ Let’s look at the big picture and the architectural and UX principles of the b
1515

1616
- [Modularity and WordPress Packages](/docs/explanations/architecture/modularity.md).
1717
- [Understand the repository folder structure](/docs/contributors/folder-structure.md).
18-
- **Outdated!** [Why is Puppeteer the tool of choice for end-to-end tests?](/docs/explanations/architecture/automated-testing.md).
18+
- [Why is Playwright the tool of choice for end-to-end tests?](/docs/explanations/architecture/automated-testing.md).
19+
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
# Automated Testing
22

3-
## Why is Puppeteer the tool of choice for end-to-end tests?
3+
## Why is Playwright the tool of choice for end-to-end tests?
44

5-
There exists a rich ecosystem of tooling available for web-based end-to-end automated testing. Thus, it's a common question: "Why does Gutenberg use [Puppeteer](https://developers.google.com/web/tools/puppeteer/) instead of ([Cypress](https://cypress.io/), [Selenium](https://www.selenium.dev/), [Playwright](https://github.com/microsoft/playwright), etc)?". Given some historical unreliability of the build results associated with end-to-end tests, it's especially natural to weigh this question in considering whether our tools are providing more value than the effort required in maintaining them. While we should always be comfortable in reevaluating earlier decisions, there were and continue to be many reasons that Puppeteer is the best compromise of the options available for end-to-end testing.
5+
There exists a rich ecosystem of tooling available for web-based end-to-end automated testing. Gutenberg uses [Playwright](https://playwright.dev/) as its end-to-end testing framework. The project previously used [Puppeteer](https://pptr.dev/) but has since fully migrated to Playwright. Here are the reasons Playwright was chosen:
66

7-
These include:
7+
- **Multi-browser support**. Playwright supports Chromium, Firefox, and WebKit out of the box, providing broader browser coverage compared to Puppeteer's Chrome-only approach.
8+
- **Built-in test runner**. `@playwright/test` provides a powerful test runner with parallel execution, [fixtures](https://playwright.dev/docs/test-fixtures), and auto-waiting, reducing flakiness and improving developer experience.
9+
- **Auto-waiting and web-first assertions**. Playwright automatically waits for elements to be actionable before performing actions, reducing the need for manual `waitFor*` calls while still surfacing legitimate performance issues that affect users.
10+
- **Better debugging tools**. Playwright offers a [trace viewer](https://playwright.dev/docs/trace-viewer), [UI mode](https://playwright.dev/docs/test-ui-mode), and a built-in [inspector](https://playwright.dev/docs/debug#playwright-inspector) for step-by-step debugging.
11+
- **Fixtures over global variables**. Playwright's fixture model injects `page`, `browser`, and other parameters into tests, making it easier to work with multiple pages or tabs and to run tests in parallel.
12+
- **Page Object Model**. Playwright encourages the [Page Object Model](https://playwright.dev/docs/pom) pattern for reusable utility functions, improving test readability and maintainability.
813

9-
- **Interoperability with existing testing framework**. Puppeteer is "just" a tool for controlling a Chrome browser, and makes no assumptions about how it's integrated into a testing environment. While this requires some additional effort in ensuring the test environment is available, it also allows for cohesion in how it integrates with an existing setup. Gutenberg is able to consistently use Jest for both unit testing and end-to-end testing. This is contrasted with other solutions like Cypress, which provide their own testing framework and assertion library as part of an all-in-one solution.
10-
- **An expressive but predictable API**. Puppeteer strikes a nice balance between low-level access to browser behavior, while retaining an expressive API for issuing and awaiting responses to those commands using modern JavaScript [`async` and `await` syntax](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await). This is contrasted with other solutions, which either don't support or leverage native language async functionality, don't expose direct access to the browser, or leverage custom domain-specific language syntaxes for expressing browser commands and assertions. The fact that Puppeteer largely targets the Chrome browser is non-ideal in how it does not provide full browser coverage. On the other hand, the limited set of browser targets offers more consistent results and stronger guarantees about how code is evaluated in the browser environment.
11-
- **Surfacing bugs, not obscuring them**. Many alternative solutions offer options to automatically await settled network requests or asynchronous appearance of elements on the page. While this can serve as a convenience in accounting for unpredictable delays, it can also unknowingly cause oversight of legitimate user-facing issues. For example, if an element will only appear on the page after some network request or computation has completed, it may be easy to overlook that these delays can cause unpredictable and frustrating behavior for users ([example](https://github.com/WordPress/gutenberg/pull/11287)). Given that developers often test on high-end hardware and stable network connections, consideration of resiliency on low-end hardware or spotty network availability is not always on the forefront of one's considerations. Puppeteer forces us to acknowledge these delays with explicit `waitFor*` expressions, putting us in much greater alignment with the real-world experience of an end-user.
12-
- **Debugging**. It's important that in that case that a test fails, there should be straight-forward means to diagnose and resolve the issue. While its offerings are rather simplistic relative to the competition, Puppeteer does expose options to run tests as "headful" (with the browser visible) and with delayed actions. Combined with the fact that it interoperates well with native language / runtime features (e.g. debugger statements or breakpoints), this provides developers with sufficient debugging access.
13-
14-
For more context, refer to the following resources:
15-
16-
- [Testing Overview: End-to-End Testing](/docs/contributors/code/testing-overview.md#end-to-end-testing)
17-
- [Testing: Experiment with Puppeteer for E2E testing](https://github.com/WordPress/gutenberg/pull/5618)
18-
- In early iterations, the contributing team opted to use Cypress for end-to-end testing. This pull request outlines problems with the approach, and proposed the initial transition to Puppeteer.
19-
- [JavaScript Chat Summary: January 28, 2020](https://make.wordpress.org/core/2020/02/04/javascript-chat-summary-january-28-2020/)
20-
- Playwright is a new offering created by many of the original contributors to Puppeteer. It offers increased browser coverage and improved reliability of tests. While still early in development at the time of this writing, there has been some interest in evaluating it for future use as an end-to-end testing solution.
14+
For more details on writing end-to-end tests, see the [End-to-End Testing guide](/docs/contributors/code/e2e/README.md).

0 commit comments

Comments
 (0)