2021-01-11 09:34:49 -08:00
---
2021-01-15 17:59:19 -08:00
id: intro
2022-07-21 00:57:09 +02:00
title: "Installation"
2021-01-11 09:34:49 -08:00
---
2023-06-02 14:13:02 -07:00
Playwright 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.
2021-07-22 19:17:29 +05:30
2022-07-21 00:57:09 +02:00
Playwright recommends using the official [Playwright Pytest plugin ](./test-runners.md ) to write end-to-end tests. It provides context isolation, running it on multiple browser configurations out of the box. Alternatively you can use the [library ](./library.md ) to manually write the testing infrastructure with your preferred test-runner. The Pytest plugin utilizes the sync version of Playwright, there is also an async version accessible via the library.
2021-01-11 09:34:49 -08:00
2022-07-21 00:57:09 +02:00
Get started by installing Playwright and running the example test to see it in action.
2021-01-11 09:34:49 -08:00
2023-08-09 15:43:02 +02:00
< Tabs
groupId="package-managers"
defaultValue="pypi"
values={[
{label: 'PyPI', value: 'pypi'},
{label: 'Anaconda', value: 'anaconda'}
]
}>
< TabItem value = "pypi" >
2022-07-21 00:57:09 +02:00
Install the [Pytest plugin ](https://pypi.org/project/pytest-playwright/ ):
2021-06-21 19:57:56 +02:00
2021-06-02 09:23:06 -07:00
```bash
2022-07-21 00:57:09 +02:00
pip install pytest-playwright
2021-01-11 09:34:49 -08:00
```
2023-08-09 15:43:02 +02:00
< / TabItem >
< TabItem value = "anaconda" >
Install the [Pytest plugin ](https://anaconda.org/Microsoft/pytest-playwright ):
```bash
conda config --add channels conda-forge
conda config --add channels microsoft
conda install playwright
```
< / TabItem >
< / Tabs >
2022-07-21 00:57:09 +02:00
Install the required browsers:
2021-06-21 19:57:56 +02:00
2021-06-03 15:07:43 +05:30
```bash
playwright install
```
2022-07-21 00:57:09 +02:00
## Add Example Test
2021-01-11 09:34:49 -08:00
2023-08-31 11:42:32 -04:00
Create a file that follows the `test_` prefix convention, such as `test_my_application.py` , inside the current working directory or in a sub-directory with the code below:
2021-01-11 09:34:49 -08:00
2023-08-31 11:42:32 -04:00
```py title="test_my_application.py"
2022-07-21 00:57:09 +02:00
import re
from playwright.sync_api import Page, expect
2021-01-11 09:34:49 -08:00
2022-08-03 15:03:22 -07:00
def test_homepage_has_Playwright_in_title_and_get_started_link_linking_to_the_intro_page(page: Page):
2022-07-21 00:57:09 +02:00
page.goto("https://playwright.dev/")
2021-01-11 09:34:49 -08:00
2022-07-21 00:57:09 +02:00
# Expect a title "to contain" a substring.
expect(page).to_have_title(re.compile("Playwright"))
2021-01-11 09:34:49 -08:00
2022-07-21 00:57:09 +02:00
# create a locator
2022-11-11 16:24:26 +01:00
get_started = page.get_by_role("link", name="Get started")
2021-01-11 09:34:49 -08:00
2022-07-21 00:57:09 +02:00
# Expect an attribute "to be strictly equal" to the value.
expect(get_started).to_have_attribute("href", "/docs/intro")
2021-01-11 09:34:49 -08:00
2022-07-21 00:57:09 +02:00
# Click the get started link.
get_started.click()
2021-01-11 09:34:49 -08:00
2023-08-31 11:42:32 -04:00
# Expects page to have a heading with the name of Installation.
expect(page.get_by_role("heading", name="Installation")).to_be_visible()
2021-01-11 09:34:49 -08:00
```
2022-07-21 00:57:09 +02:00
## Running the Example Test
2021-01-11 09:34:49 -08:00
2022-07-21 00:57:09 +02:00
By default tests will be run on chromium. This can be configured via the CLI options. Tests are run in headless mode meaning no browser UI will open up when running the tests. Results of the tests and test logs will be shown in the terminal.
2021-01-11 09:34:49 -08:00
2021-06-02 09:23:06 -07:00
```bash
2022-07-21 00:57:09 +02:00
pytest
2021-07-22 19:17:29 +05:30
```
2023-06-02 14:13:02 -07:00
## System requirements
2023-06-16 21:50:29 +02:00
- Python 3.8 or higher.
2023-06-02 14:13:02 -07:00
- Windows 10+, Windows Server 2016+ or Windows Subsystem for Linux (WSL).
- MacOS 12 Monterey or MacOS 13 Ventura.
2023-07-13 12:56:44 +02:00
- Debian 11, Debian 12, Ubuntu 20.04 or Ubuntu 22.04.
2023-06-02 14:13:02 -07:00
2022-07-21 00:57:09 +02:00
## What's next
2021-04-30 16:44:30 +02:00
2022-07-21 00:57:09 +02:00
- [Write tests using web first assertions, page fixtures and locators ](./writing-tests.md )
2022-10-21 09:52:36 -07:00
- [Run single test, multiple tests, headed mode ](./running-tests.md )
2022-07-21 00:57:09 +02:00
- [Generate tests with Codegen ](./codegen.md )
2022-08-10 14:34:27 +02:00
- [See a trace of your tests ](./trace-viewer-intro.md )