playwright/docs/src/intro-js.md

300 lines
6.7 KiB
Markdown
Raw Normal View History

2021-01-01 15:17:27 -08:00
---
id: intro
title: "Installation"
2021-01-01 15:17:27 -08:00
---
2023-09-11 18:54:34 +02:00
## Introduction
Playwright Test was created specifically to accommodate the needs of end-to-end testing. Playwright supports all modern rendering engines including Chromium, WebKit, and Firefox. Test on Windows, Linux, and macOS, locally or on CI, headless or headed with native mobile emulation of Google Chrome for Android and Mobile Safari.
2021-06-18 10:09:38 -07:00
**You will learn**
- [How to install Playwright](/intro.md#installing-playwright)
- [What's Installed](/intro.md#whats-installed)
- [How to run the example test](/intro.md#running-the-example-test)
- [How to open the HTML test report](/intro.md#html-test-reports)
## Installing Playwright
Get started by installing Playwright using npm, yarn or pnpm. Alternatively you can also get started and run your tests using the [VS Code Extension](./getting-started-vscode.md).
2021-06-18 10:09:38 -07:00
<Tabs
defaultValue="npm"
values={[
{label: 'npm', value: 'npm'},
{label: 'yarn', value: 'yarn'},
{label: 'pnpm', value: 'pnpm'}
]
}>
<TabItem value="npm">
```bash
2022-03-07 19:30:03 +01:00
npm init playwright@latest
```
</TabItem>
<TabItem value="yarn">
```bash
2022-07-14 16:19:55 +02:00
yarn create playwright
```
</TabItem>
<TabItem value="pnpm">
```bash
pnpm create playwright
```
</TabItem>
</Tabs>
2021-06-18 10:09:38 -07:00
Run the install command and select the following to get started:
- Choose between TypeScript or JavaScript (default is TypeScript)
- Name of your Tests folder (default is tests or e2e if you already have a tests folder in your project)
- Add a GitHub Actions workflow to easily run tests on CI
- Install Playwright browsers (default is true)
2021-06-18 10:09:38 -07:00
## What's Installed
Playwright will download the browsers needed as well as create the following files.
2021-06-18 10:09:38 -07:00
```bash
playwright.config.ts
package.json
package-lock.json
tests/
example.spec.ts
2022-07-14 16:19:55 +02:00
tests-examples/
demo-todo-app.spec.ts
```
The [playwright.config](./test-configuration.md) is where you can add configuration for Playwright including modifying which browsers you would like to run Playwright on. If you are running tests inside an already existing project then dependencies will be added directly to your `package.json`.
The `tests` folder contains a basic example test to help you get started with testing. For a more detailed example check out the `tests-examples` folder which contains tests written to test a todo app.
## Running the Example Test
By default tests will be run on all 3 browsers, chromium, firefox and webkit using 3 workers. This can be configured in the [playwright.config file](./test-configuration.md). Tests are run in headless mode meaning no browser will open up when running the tests. Results of the tests and test logs will be shown in the terminal.
<Tabs
defaultValue="npm"
values={[
{label: 'npm', value: 'npm'},
{label: 'yarn', value: 'yarn'},
{label: 'pnpm', value: 'pnpm'}
]
}>
<TabItem value="npm">
```bash
npx playwright test
```
</TabItem>
<TabItem value="yarn">
```bash
yarn playwright test
```
</TabItem>
<TabItem value="pnpm">
```bash
pnpm exec playwright test
```
</TabItem>
</Tabs>
2023-09-11 18:54:34 +02:00
![tests running in command line](https://github.com/microsoft/playwright/assets/13063165/981c1b2b-dc7e-4b85-b241-272b44da6628)
See our doc on [Running Tests](./running-tests.md) to learn more about running tests in headed mode, running multiple tests, running specific tests etc.
## HTML Test Reports
After your test completes, an [HTML Reporter](./test-reporters.md#html-reporter) will be generated, which shows you a full report of your tests allowing you to filter the report by browsers, passed tests, failed tests, skipped tests and flaky tests. You can click on each test and explore the test's errors as well as each step of the test. By default, the HTML report is opened automatically if some of the tests failed.
2023-04-25 20:09:52 +02:00
<Tabs
defaultValue="npm"
values={[
{label: 'npm', value: 'npm'},
{label: 'yarn', value: 'yarn'},
{label: 'pnpm', value: 'pnpm'}
]
}>
<TabItem value="npm">
2023-04-25 20:09:52 +02:00
```bash
npx playwright show-report
2023-04-25 20:09:52 +02:00
```
2023-09-11 18:54:34 +02:00
</TabItem>
<TabItem value="yarn">
```bash
yarn playwright show-report
```
</TabItem>
<TabItem value="pnpm">
```bash
pnpm exec playwright show-report
```
</TabItem>
</Tabs>
![HTML Report](https://github.com/microsoft/playwright/assets/13063165/38ec17a7-9e61-4002-b137-a93812765501)
2023-04-25 20:09:52 +02:00
## Running the Example Test in UI Mode
Run your tests with [UI Mode](./test-ui-mode.md) for a better developer experience with time travel debugging, watch mode and more.
<Tabs
defaultValue="npm"
values={[
{label: 'npm', value: 'npm'},
{label: 'yarn', value: 'yarn'},
{label: 'pnpm', value: 'pnpm'}
]
}>
<TabItem value="npm">
```bash
npx playwright test --ui
```
</TabItem>
<TabItem value="yarn">
```bash
yarn playwright test --ui
```
</TabItem>
<TabItem value="pnpm">
```bash
pnpm exec playwright test --ui
```
</TabItem>
</Tabs>
![UI Mode](https://github.com/microsoft/playwright/assets/13063165/c5b501cc-4f5d-485a-87cc-66044c651786)
2023-10-03 03:52:33 -04:00
Check out or [detailed guide on UI Mode](./test-ui-mode.md) to learn more about its features.
2023-09-11 18:54:34 +02:00
## Updating Playwright
To update Playwright to the latest version run the following command:
<Tabs
defaultValue="npm"
values={[
{label: 'npm', value: 'npm'},
{label: 'yarn', value: 'yarn'},
{label: 'pnpm', value: 'pnpm'}
]
}>
<TabItem value="npm">
2023-09-11 18:54:34 +02:00
```bash
npm install -D @playwright/test@latest
# Also download new browser binaries and their dependencies:
npx playwright install --with-deps
2023-09-11 18:54:34 +02:00
```
</TabItem>
<TabItem value="yarn">
```bash
yarn add --dev @playwright/test@latest
# Also download new browser binaries and their dependencies:
yarn playwright install --with-deps
```
</TabItem>
<TabItem value="pnpm">
```bash
pnpm install --save-dev @playwright/test@latest
# Also download new browser binaries and their dependencies:
pnpm exec playwright install --with-deps
```
</TabItem>
</Tabs>
2023-09-11 18:54:34 +02:00
You can always check which version of Playwright you have by running the following command:
<Tabs
defaultValue="npm"
values={[
{label: 'npm', value: 'npm'},
{label: 'yarn', value: 'yarn'},
{label: 'pnpm', value: 'pnpm'}
]
}>
<TabItem value="npm">
2023-09-11 18:54:34 +02:00
```bash
npx playwright --version
```
2022-03-30 09:31:35 -07:00
</TabItem>
<TabItem value="yarn">
```bash
yarn playwright --version
```
</TabItem>
<TabItem value="pnpm">
```bash
pnpm exec playwright --version
```
</TabItem>
</Tabs>
## System requirements
- Node.js 18+
- Windows 10+, Windows Server 2016+ or Windows Subsystem for Linux (WSL).
- MacOS 12 Monterey, MacOS 13 Ventura, or MacOS 14 Sonoma.
2024-06-03 12:47:16 +02:00
- Debian 11, Debian 12, Ubuntu 20.04 or Ubuntu 22.04, Ubuntu 24.04, on x86-64 and arm64 architecture.
## What's next
- [Write tests using web first assertions, page fixtures and locators](./writing-tests.md)
- [Run single test, multiple tests, headed mode](./running-tests.md)
- [Generate tests with Codegen](./codegen-intro.md)
- [See a trace of your tests](./trace-viewer-intro.md)