-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[gh11318] Documentation for working with Playwright #11322
Open
ahaywood
wants to merge
3
commits into
main
Choose a base branch
from
ad-docs-playwright
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Playwright | ||
|
||
[Playwright](https://playwright.dev/) is a great tool for end-to-end testing. | ||
|
||
Ideally, you continue to use Jest tests for writing unit tests for all your components, cells, layouts, and pages. Then, you can use Playwright to write end-to-end tests to test how everything integrates and works together. | ||
|
||
## Installation | ||
|
||
### 1. Within the Terminal, run: | ||
|
||
```sh | ||
yarn create playwright | ||
``` | ||
|
||
:::info | ||
You can find additional information about [installing Playwright on their documentation.](https://playwright.dev/docs/intro) | ||
::: | ||
|
||
Then, the install command will prompt you with a few questions: | ||
|
||
- **Do you want to use TypeScript or JavaScript?** | ||
- **Where to put your end-to-end tests?** I'd recommend putting your test files inside the `web/src/e2e` directory. | ||
- **Add a GitHub Actions workflow?** This will create a **.github/workflows/playwright.yml** file. | ||
- **Install Playwright browsers (can be done manually via `yarn playwright install`)?** | ||
|
||
![/img/playwright/04-install-browsers.png]() | ||
|
||
### 2. Add a `script` to the `package.json` file within the root of your project directory. | ||
|
||
::info | ||
RedwoodJS has 3 `package.json` files. One inside the `api` directory, one inside the `web` directory, and one inside the root of your project. This script lives in the `package.json` file within the root of your project. | ||
:: | ||
|
||
```json | ||
"scripts": { | ||
"test:e2e": "npx playwright test -c ./playwright.config.ts --trace on --workers 1 --reporter=list" | ||
} | ||
``` | ||
|
||
This script utilizes several flags: | ||
|
||
| Flag | Description | | ||
| ----------------- | -------------------------------- | | ||
| `--trace on` | | | ||
| `--workers 1` | Disables parallelization | | ||
| `--reporter=list` | Command line report output style | | ||
|
||
To run playwright, you can use: | ||
|
||
```sh | ||
yarn test:e2e | ||
``` | ||
|
||
:::info | ||
When running the test, I'm _not_ using `yarn rw`, simply `yar test:e2e` | ||
::: | ||
|
||
![/img/playwright/running-tests.png]() | ||
|
||
## Writing your first test | ||
|
||
```sh | ||
npx playwright codegen | ||
``` | ||
|
||
This will open a browser window and allow you to interact with the website. As you interact with the website, Playwright will generate the code for you. | ||
|
||
![/img/playwright/generating-a-test.png]() | ||
|
||
### You can also run your tests in UI mode: | ||
|
||
```sh | ||
npx playwright test --ui | ||
``` | ||
|
||
This will open a separate window that provides a GUI for interacting with your tests. | ||
|
||
![/img/playwright/playwright-ui.png]() | ||
|
||
### Run your tests in headed mode: | ||
|
||
This will give you the ability to visually see how Playwright interacts with the website. | ||
|
||
```sh | ||
npx playwright test --headed | ||
``` | ||
|
||
By default, Playwright launches browsers in headless mode. | ||
|
||
:::info | ||
On Linux agents, headed execution requires [Xvfb](https://en.wikipedia.org/wiki/Xvfb) to be installed. | ||
::: |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
yarn