docs: move playwright module into api-body.md (#4827)

This commit is contained in:
Pavel Feldman 2020-12-26 15:33:29 -08:00 committed by GitHub
parent 15cdfd1cc1
commit 2cb5770183
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 102 additions and 143 deletions

View File

@ -1,3 +1,86 @@
# class: Playwright
Playwright module provides a method to launch a browser instance.
The following is a typical example of using Playwright to drive automation:
```js
const { chromium, firefox, webkit } = require('playwright');
(async () => {
const browser = await chromium.launch(); // Or 'firefox' or 'webkit'.
const page = await browser.newPage();
await page.goto('http://example.com');
// other actions...
await browser.close();
})();
```
By default, the `playwright` NPM package automatically downloads browser executables during installation. The `playwright-core` NPM package can be used to skip automatic downloads.
<!-- GEN:toc -->
<!-- GEN:stop -->
## property: Playwright.chromium
- type: <[BrowserType]>
This object can be used to launch or connect to Chromium, returning instances of [ChromiumBrowser].
## property: Playwright.devices
- type: <[Object]>
Returns a list of devices to be used with [`method: Browser.newContext`]() or [`method: Browser.newPage`](). Actual list of devices can be found in [src/server/deviceDescriptors.ts](https://github.com/Microsoft/playwright/blob/master/src/server/deviceDescriptors.ts).
```js
const { webkit, devices } = require('playwright');
const iPhone = devices['iPhone 6'];
(async () => {
const browser = await webkit.launch();
const context = await browser.newContext({
...iPhone
});
const page = await context.newPage();
await page.goto('http://example.com');
// other actions...
await browser.close();
})();
```
## property: Playwright.errors
- type: <[Object]>
- `TimeoutError` <[function]> A class of [TimeoutError].
Playwright methods might throw errors if they are unable to fulfill a request. For example, [`method: Page.waitForSelector`]()
might fail if the selector doesn't match any nodes during the given timeframe.
For certain types of errors Playwright uses specific error classes.
These classes are available via [`playwright.errors`](#playwrighterrors).
An example of handling a timeout error:
```js
try {
await page.waitForSelector('.foo');
} catch (e) {
if (e instanceof playwright.errors.TimeoutError) {
// Do something if this is a timeout.
}
}
```
## property: Playwright.firefox
- type: <[BrowserType]>
This object can be used to launch or connect to Firefox, returning instances of [FirefoxBrowser].
## property: Playwright.selectors
- type: <[Selectors]>
Selectors can be used to install custom selector engines. See [Working with selectors](#working-with-selectors) for more information.
## property: Playwright.webkit
- type: <[BrowserType]>
This object can be used to launch or connect to WebKit, returning instances of [WebKitBrowser].
# class: Browser # class: Browser
* extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter) * extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)

View File

@ -4,130 +4,4 @@
##### Table of Contents ##### Table of Contents
<!-- GEN:toc-top-level --> <!-- GEN:toc-top-level -->
- [Playwright module](#playwright-module)
- [class: Browser](#class-browser)
- [class: BrowserContext](#class-browsercontext)
- [class: Page](#class-page)
- [class: Frame](#class-frame)
- [class: ElementHandle](#class-elementhandle)
- [class: JSHandle](#class-jshandle)
- [class: ConsoleMessage](#class-consolemessage)
- [class: Dialog](#class-dialog)
- [class: Download](#class-download)
- [class: Video](#class-video)
- [class: FileChooser](#class-filechooser)
- [class: Keyboard](#class-keyboard)
- [class: Mouse](#class-mouse)
- [class: Touchscreen](#class-touchscreen)
- [class: Request](#class-request)
- [class: Response](#class-response)
- [class: Selectors](#class-selectors)
- [class: Route](#class-route)
- [class: WebSocket](#class-websocket)
- [class: TimeoutError](#class-timeouterror)
- [class: Accessibility](#class-accessibility)
- [class: Worker](#class-worker)
- [class: BrowserServer](#class-browserserver)
- [class: BrowserType](#class-browsertype)
- [class: Logger](#class-logger)
- [class: ChromiumBrowser](#class-chromiumbrowser)
- [class: ChromiumBrowserContext](#class-chromiumbrowsercontext)
- [class: ChromiumCoverage](#class-chromiumcoverage)
- [class: CDPSession](#class-cdpsession)
- [class: FirefoxBrowser](#class-firefoxbrowser)
- [class: WebKitBrowser](#class-webkitbrowser)
- [EvaluationArgument](#evaluationargument)
- [Environment Variables](#environment-variables)
- [Working with selectors](#working-with-selectors)
- [Working with Chrome Extensions](#working-with-chrome-extensions)
<!-- GEN:stop --> <!-- GEN:stop -->
### Playwright module
Playwright module provides a method to launch a browser instance.
The following is a typical example of using Playwright to drive automation:
```js
const { chromium, firefox, webkit } = require('playwright');
(async () => {
const browser = await chromium.launch(); // Or 'firefox' or 'webkit'.
const page = await browser.newPage();
await page.goto('http://example.com');
// other actions...
await browser.close();
})();
```
By default, the `playwright` NPM package automatically downloads browser executables during installation. The `playwright-core` NPM package can be used to skip automatic downloads.
<!-- GEN:toc -->
- [playwright.chromium](#playwrightchromium)
- [playwright.devices](#playwrightdevices)
- [playwright.errors](#playwrighterrors)
- [playwright.firefox](#playwrightfirefox)
- [playwright.selectors](#playwrightselectors)
- [playwright.webkit](#playwrightwebkit)
<!-- GEN:stop -->
#### playwright.chromium
- returns: <[BrowserType]>
This object can be used to launch or connect to Chromium, returning instances of [ChromiumBrowser].
#### playwright.devices
- returns: <[Object]>
Returns a list of devices to be used with [`method: Browser.newContext`]() or [`method: Browser.newPage`](). Actual list of devices can be found in [src/server/deviceDescriptors.ts](https://github.com/Microsoft/playwright/blob/master/src/server/deviceDescriptors.ts).
```js
const { webkit, devices } = require('playwright');
const iPhone = devices['iPhone 6'];
(async () => {
const browser = await webkit.launch();
const context = await browser.newContext({
...iPhone
});
const page = await context.newPage();
await page.goto('http://example.com');
// other actions...
await browser.close();
})();
```
#### playwright.errors
- returns: <[Object]>
- `TimeoutError` <[function]> A class of [TimeoutError].
Playwright methods might throw errors if they are unable to fulfill a request. For example, [`method: Page.waitForSelector`]()
might fail if the selector doesn't match any nodes during the given timeframe.
For certain types of errors Playwright uses specific error classes.
These classes are available via [`playwright.errors`](#playwrighterrors).
An example of handling a timeout error:
```js
try {
await page.waitForSelector('.foo');
} catch (e) {
if (e instanceof playwright.errors.TimeoutError) {
// Do something if this is a timeout.
}
}
```
#### playwright.firefox
- returns: <[BrowserType]>
This object can be used to launch or connect to Firefox, returning instances of [FirefoxBrowser].
#### playwright.selectors
- returns: <[Selectors]>
Selectors can be used to install custom selector engines. See [Working with selectors](#working-with-selectors) for more information.
#### playwright.webkit
- returns: <[BrowserType]>
This object can be used to launch or connect to WebKit, returning instances of [WebKitBrowser].

View File

@ -5,7 +5,7 @@
##### Table of Contents ##### Table of Contents
<!-- GEN:toc-top-level --> <!-- GEN:toc-top-level -->
- [Playwright module](#playwright-module) - [class: Playwright](#class-playwright)
- [class: Browser](#class-browser) - [class: Browser](#class-browser)
- [class: BrowserContext](#class-browsercontext) - [class: BrowserContext](#class-browsercontext)
- [class: Page](#class-page) - [class: Page](#class-page)
@ -43,10 +43,11 @@
- [Working with Chrome Extensions](#working-with-chrome-extensions) - [Working with Chrome Extensions](#working-with-chrome-extensions)
<!-- GEN:stop --> <!-- GEN:stop -->
### Playwright module
Playwright module provides a method to launch a browser instance. ### class: Playwright
The following is a typical example of using Playwright to drive automation:
Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright to drive automation:
```js ```js
const { chromium, firefox, webkit } = require('playwright'); const { chromium, firefox, webkit } = require('playwright');
@ -71,12 +72,12 @@ By default, the `playwright` NPM package automatically downloads browser executa
<!-- GEN:stop --> <!-- GEN:stop -->
#### playwright.chromium #### playwright.chromium
- returns: <[BrowserType]> - type: <[BrowserType]>
This object can be used to launch or connect to Chromium, returning instances of [ChromiumBrowser]. This object can be used to launch or connect to Chromium, returning instances of [ChromiumBrowser].
#### playwright.devices #### playwright.devices
- returns: <[Object]> - type: <[Object]>
Returns a list of devices to be used with [`browser.newContext([options])`](#browsernewcontextoptions) or [`browser.newPage([options])`](#browsernewpageoptions). Actual list of devices can be found in [src/server/deviceDescriptors.ts](https://github.com/Microsoft/playwright/blob/master/src/server/deviceDescriptors.ts). Returns a list of devices to be used with [`browser.newContext([options])`](#browsernewcontextoptions) or [`browser.newPage([options])`](#browsernewpageoptions). Actual list of devices can be found in [src/server/deviceDescriptors.ts](https://github.com/Microsoft/playwright/blob/master/src/server/deviceDescriptors.ts).
@ -97,16 +98,15 @@ const iPhone = devices['iPhone 6'];
``` ```
#### playwright.errors #### playwright.errors
- returns: <[Object]> - type: <[Object]>
- `TimeoutError` <[function]> A class of [TimeoutError]. - `TimeoutError` <[function]> A class of [TimeoutError].
Playwright methods might throw errors if they are unable to fulfill a request. For example, [`page.waitForSelector(selector[, options])`](#pagewaitforselectorselector-options) Playwright methods might throw errors if they are unable to fulfill a request. For example, [`page.waitForSelector(selector[, options])`](#pagewaitforselectorselector-options) might fail if the selector doesn't match any nodes during the given timeframe.
might fail if the selector doesn't match any nodes during the given timeframe.
For certain types of errors Playwright uses specific error classes. For certain types of errors Playwright uses specific error classes. These classes are available via [`playwright.errors`](#playwrighterrors).
These classes are available via [`playwright.errors`](#playwrighterrors).
An example of handling a timeout error: An example of handling a timeout error:
```js ```js
try { try {
await page.waitForSelector('.foo'); await page.waitForSelector('.foo');
@ -118,22 +118,20 @@ try {
``` ```
#### playwright.firefox #### playwright.firefox
- returns: <[BrowserType]> - type: <[BrowserType]>
This object can be used to launch or connect to Firefox, returning instances of [FirefoxBrowser]. This object can be used to launch or connect to Firefox, returning instances of [FirefoxBrowser].
#### playwright.selectors #### playwright.selectors
- returns: <[Selectors]> - type: <[Selectors]>
Selectors can be used to install custom selector engines. See [Working with selectors](#working-with-selectors) for more information. Selectors can be used to install custom selector engines. See [Working with selectors](#working-with-selectors) for more information.
#### playwright.webkit #### playwright.webkit
- returns: <[BrowserType]> - type: <[BrowserType]>
This object can be used to launch or connect to WebKit, returning instances of [WebKitBrowser]. This object can be used to launch or connect to WebKit, returning instances of [WebKitBrowser].
### class: Browser ### class: Browser
* extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter) * extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)

View File

@ -43,3 +43,4 @@ export { CDPSession } from './cdpSession';
export { WebKitBrowser } from './webkitBrowser'; export { WebKitBrowser } from './webkitBrowser';
export { FirefoxBrowser } from './firefoxBrowser'; export { FirefoxBrowser } from './firefoxBrowser';
export { Playwright } from './playwright';

View File

@ -428,7 +428,10 @@ function mergeDocumentation(mdDoc, jsDoc) {
else else
classes.push(mergeClasses(mdClass, jsClass)); classes.push(mergeClasses(mdClass, jsClass));
} }
// Root module types are overridden.
const c = mdDoc.classes.get('Playwright');
mdDoc.classes.delete('Playwright');
mdDoc.classesArray.splice(mdDoc.classesArray.indexOf(c), 1);
return mdDoc; return mdDoc;
} }