Skip to content

Commit e9e1075

Browse files
authored
docs(readme): update structure (microsoft#205)
1 parent 048cc22 commit e9e1075

File tree

1 file changed

+50
-68
lines changed

1 file changed

+50
-68
lines changed

README.md

Lines changed: 50 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# 🎭 [Playwright](https://github.com/microsoft/playwright) for Python
1+
# 🎭 [Playwright](https://playwright.dev) for Python [![PyPI version](https://badge.fury.io/py/playwright.svg)](https://pypi.python.org/pypi/playwright/) [![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://join.slack.com/t/playwright/shared_invite/enQtOTEyMTUxMzgxMjIwLThjMDUxZmIyNTRiMTJjNjIyMzdmZDA3MTQxZWUwZTFjZjQwNGYxZGM5MzRmNzZlMWI5ZWUyOTkzMjE5Njg1NDg)
22

3-
[![PyPI version](https://badge.fury.io/py/playwright.svg)](https://pypi.python.org/pypi/playwright/) [![PyPI pyversions](https://img.shields.io/pypi/pyversions/playwright.svg)](https://pypi.python.org/pypi/playwright/) [![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://join.slack.com/t/playwright/shared_invite/enQtOTEyMTUxMzgxMjIwLThjMDUxZmIyNTRiMTJjNjIyMzdmZDA3MTQxZWUwZTFjZjQwNGYxZGM5MzRmNzZlMWI5ZWUyOTkzMjE5Njg1NDg) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-86.0.4238.0-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-80.0b8-blue.svg?logo=mozilla-firefox)](https://www.mozilla.org/en-US/firefox/new/)<!-- GEN:stop --> [![WebKit version](https://img.shields.io/badge/webkit-14.0-blue.svg?logo=safari)](https://webkit.org/)
3+
#### [Docs](#documentation) | [Website](https://playwright.dev/) | [Python API reference](https://microsoft.github.io/playwright-python/)
44

5-
##### [Docs](#documentation) | [Playwright API reference](https://playwright.dev/#?path=docs/api.md) | [Playwright Python API Docs](https://microsoft.github.io/playwright-python/)
6-
7-
Playwright is a Python library to automate [Chromium](https://www.chromium.org/Home), [Firefox](https://www.mozilla.org/en-US/firefox/new/) and [WebKit](https://webkit.org/) with a single API. Playwright is built to enable cross-browser web automation that is **ever-green**, **capable**, **reliable** and **fast**.
5+
Playwright is a Python library to automate [Chromium](https://www.chromium.org/Home), [Firefox](https://www.mozilla.org/en-US/firefox/new/) and [WebKit](https://webkit.org/) browsers with a single API. Playwright delivers automation that is **ever-green**, **capable**, **reliable** and **fast**. [See how Playwright is better](https://playwright.dev/#path=docs%2Fwhy-playwright.md&q=).
86

97
| | Linux | macOS | Windows |
108
| :--- | :---: | :---: | :---: |
@@ -14,38 +12,29 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H
1412

1513
Headless execution is supported for all the browsers on all platforms.
1614

17-
## Installation
15+
* [Usage](#usage)
16+
- [Sync API](#sync-api)
17+
- [Async API](#async-api)
18+
- [With pytest](#with-pytest)
19+
- [Interactive mode (REPL)](#interactive-mode-repl)
20+
* [Examples](#examples)
21+
- [Mobile and geolocation](#mobile-and-geolocation)
22+
- [Evaluate JS in browser](#evaluate-js-in-browser)
23+
- [Intercept network requests](#intercept-network-requests)
24+
* [Documentation](#documentation)
25+
26+
## Usage
1827

1928
```
2029
pip install playwright
2130
python -m playwright install
2231
```
2332

24-
This installs Playwright and browser binaries for Chromium, Firefox and WebKit. Once installed, you can `import` Playwright in a Python script and automate web browser interactions. Playwright requires Python 3.7+.
25-
26-
## Capabilities
27-
28-
Playwright is built to automate the broad and growing set of web browser capabilities used by Single Page Apps and Progressive Web Apps.
29-
30-
* Scenarios that span multiple page, domains and iframes
31-
* Auto-wait for elements to be ready before executing actions (like click, fill)
32-
* Intercept network activity for stubbing and mocking network requests
33-
* Emulate mobile devices, geolocation, permissions
34-
* Support for web components via shadow-piercing selectors
35-
* Native input events for mouse and keyboard
36-
* Upload and download files
33+
This installs Playwright and browser binaries for Chromium, Firefox and WebKit. Playwright requires Python 3.7+.
3734

38-
## Usage
39-
40-
### Pytest
41-
42-
Playwright can be used as a library in your application or as a part of the testing solution. We recommend using our [Pytest plugin](https://github.com/microsoft/playwright-pytest#readme) for testing.
35+
Playwright offers both sync (blocking) API and async API. They are identical in terms of capabilities and only differ in how one consumes the API.
4336

44-
As a library, Playwright offers both blocking (synchronous) API and asyncio API (async/await). You can pick the one that works best for you. They are identical in terms of capabilities and only differ in a way one consumes the API.
45-
46-
Below are some of the examples on how these variations of the API can be used:
47-
48-
#### Sync variant
37+
#### Sync API
4938

5039
```py
5140
from playwright import sync_playwright
@@ -59,7 +48,7 @@ with sync_playwright() as p:
5948
browser.close()
6049
```
6150

62-
#### Async variant
51+
#### Async API
6352

6453
```py
6554
import asyncio
@@ -77,7 +66,9 @@ async def main():
7766
asyncio.get_event_loop().run_until_complete(main())
7867
```
7968

80-
#### Using pytest-playwright
69+
#### With pytest
70+
71+
Use our [pytest plugin for Playwright](https://github.com/microsoft/playwright-pytest#readme).
8172

8273
```py
8374
def test_playwright_is_visible_on_google(page):
@@ -87,27 +78,23 @@ def test_playwright_is_visible_on_google(page):
8778
page.waitForSelector("text=microsoft/Playwright")
8879
```
8980

90-
For more information on pytest-playwright, see [GitHub](https://github.com/microsoft/playwright-pytest#readme).
91-
92-
#### REPL support without context managers
93-
94-
For scripting purposes, it is also possible to start and stop Playwright manually without relying on the indentation of the REPL.
81+
#### Interactive mode (REPL)
9582

9683
```py
97-
from playwright import sync_playwright
98-
99-
playwright = sync_playwright().start()
100-
for browser_type in [playwright.chromium, playwright.firefox, playwright.webkit]:
101-
browser = browser_type.launch()
102-
page = browser.newPage()
103-
page.goto("http://whatsmyuseragent.org/")
104-
page.screenshot(path=f"example-{browser_type.name}.png")
105-
browser.close()
106-
107-
playwright.stop()
84+
>>> from playwright import sync_playwright
85+
>>> playwright = sync_playwright().start()
86+
87+
# Use playwright.chromium, playwright.firefox or playwright.webkit
88+
# Pass headless=False to see the browser UI
89+
>>> browser = playwright.chromium.launch()
90+
>>> page = browser.newPage()
91+
>>> page.goto("http://whatsmyuseragent.org/")
92+
>>> page.screenshot(path="example.png")
93+
>>> browser.close()
94+
>>> playwright.stop()
10895
```
10996

110-
## More examples
97+
## Examples
11198

11299
#### Mobile and geolocation
113100

@@ -132,7 +119,8 @@ with sync_playwright() as p:
132119
browser.close()
133120
```
134121

135-
The asyncio variant:
122+
<details>
123+
<summary>Async variant</summary>
136124

137125
```py
138126
import asyncio
@@ -156,8 +144,9 @@ async def main():
156144

157145
asyncio.get_event_loop().run_until_complete(main())
158146
```
147+
</details>
159148

160-
#### Evaluate in browser context
149+
#### Evaluate JS in browser
161150

162151
This code snippet navigates to example.com in Firefox, and executes a script in the page context.
163152

@@ -178,8 +167,8 @@ with sync_playwright() as p:
178167
print(dimensions)
179168
browser.close()
180169
```
181-
182-
The asyncio variant:
170+
<details>
171+
<summary>Async variant</summary>
183172

184173
```py
185174
import asyncio
@@ -202,6 +191,7 @@ async def main():
202191

203192
asyncio.get_event_loop().run_until_complete(main())
204193
```
194+
</details>
205195

206196
#### Intercept network requests
207197

@@ -224,8 +214,8 @@ with sync_playwright() as p:
224214
page.goto('http://todomvc.com')
225215
browser.close()
226216
```
227-
228-
The asyncio variant:
217+
<details>
218+
<summary>Async variant</summary>
229219

230220
```py
231221
import asyncio
@@ -248,16 +238,15 @@ async def main():
248238

249239
asyncio.get_event_loop().run_until_complete(main())
250240
```
241+
</details>
251242

252243
## Documentation
253244

254-
We are in the process of converting the [documentation](https://playwright.dev/) from the Node.js form to the Python one. But you can go ahead and use the Node.js documentation because the API is pretty much the same. You might have noticed that Playwright uses non-Python naming conventions, `camelCase` instead of the `snake_case` for its methods. We recognize that this is not ideal, but it was done deliberately, so that you could rely upon the stack overflow answers and the documentation of the Playwright for Node.js.
245+
We are in the process of converting our [documentation](https://playwright.dev/) from the Node.js form to Python. You can go ahead and use the Node.js documentation since the API is pretty much the same. Playwright uses non-Python naming conventions (`camelCase` instead of `snake_case`) for its methods. We recognize that this is not ideal, but it was done deliberately, so that you could rely upon Stack Overflow answers and existing documentation.
255246

256-
### Understanding examples from the JavaScript documentation
247+
### Named arguments
257248

258-
You can use all the same methods and arguments as [documented](https://playwright.dev/), just remember that since Python allows named arguments, we didn't need to put `options` parameter into every call as we had to in the Node.js version:
259-
260-
So when you see example like this in JavaScript
249+
Since Python allows named arguments, we didn't need to put the `options` parameter into every call as in the Node.js API. So when you see example like this in JavaScript
261250

262251
```js
263252
await webkit.launch({ headless: false });
@@ -269,7 +258,7 @@ It translates into Python like this:
269258
webkit.launch(headless=False)
270259
```
271260

272-
If you are using an IDE, it'll suggest parameters that are available in every call.
261+
If you are using an IDE, it will suggest parameters that are available in every call.
273262

274263
### Evaluating functions
275264

@@ -340,11 +329,4 @@ with page.expect_response("**/api/fetch_data"):
340329

341330
Yes, Playwright for Python is ready. We are still not at the version v1.0, so minor breaking API changes could potentially happen. But a) this is unlikely and b) we will only do that if we know it improves your experience with the new library. We'd like to collect your feedback before we freeze the API for v1.0.
342331

343-
> Note: We don't yet support some of the edge-cases of the vendor-specific APIs such as collecting chromium trace, coverage report, etc.
344-
345-
## Resources
346-
347-
* [Documentation](https://github.com/microsoft/playwright/blob/master/docs/README.md)
348-
* [API reference](https://github.com/microsoft/playwright/blob/master/docs/api.md)
349-
* [Example recipes](https://github.com/microsoft/playwright/blob/master/docs/examples/README.md)
350-
* [Contributing](CONTRIBUTING.md)
332+
> Note: We don't yet support some of the edge-cases of the vendor-specific APIs such as collecting Chromium trace, coverage report, etc.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy