docs: some syntax fixes (#2116)

This commit is contained in:
Vasilii Artemchuk 2020-05-07 22:33:35 +03:00 committed by GitHub
parent d39ec35cd7
commit 4c4fa8d38c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 45 additions and 46 deletions

View file

@ -157,23 +157,23 @@ npm run ftest -- --break-on-failure
- To run a specific test, substitute the `it` with `fit` (mnemonic rule: '*focus it*'): - To run a specific test, substitute the `it` with `fit` (mnemonic rule: '*focus it*'):
```js ```js
... ...
// Using "fit" to run specific test // Using "fit" to run specific test
fit('should work', async ({server, page}) => { fit('should work', async ({server, page}) => {
const response = await page.goto(server.EMPTY_PAGE); const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok).toBe(true); expect(response.ok).toBe(true);
}); });
``` ```
- To disable a specific test, substitute the `it` with `xit` (mnemonic rule: '*cross it*'): - To disable a specific test, substitute the `it` with `xit` (mnemonic rule: '*cross it*'):
```js ```js
... ...
// Using "xit" to skip specific test // Using "xit" to skip specific test
xit('should work', async ({server, page}) => { xit('should work', async ({server, page}) => {
const response = await page.goto(server.EMPTY_PAGE); const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok).toBe(true); expect(response.ok).toBe(true);
}); });
``` ```
- To run tests in non-headless (headful) mode: - To run tests in non-headless (headful) mode:

View file

@ -100,7 +100,7 @@ const { firefox } = require('playwright');
height: document.documentElement.clientHeight, height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio deviceScaleFactor: window.devicePixelRatio
} }
}) });
console.log(dimensions); console.log(dimensions);
await browser.close(); await browser.close();

View file

@ -1559,7 +1559,7 @@ Shortcut for [page.mainFrame().selectOption()](#frameselectoptionselector-values
- `html` <[string]> HTML markup to assign to the page. - `html` <[string]> HTML markup to assign to the page.
- `options` <[Object]> Parameters which might have the following properties: - `options` <[Object]> Parameters which might have the following properties:
- `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either: - `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either:
- `'load'` - consider setting content to be finished when the `load` event is fired. - `'load'` - consider setting content to be finished when the `load` event is fired.
- `'domcontentloaded'` - consider setting content to be finished when the `DOMContentLoaded` event is fired. - `'domcontentloaded'` - consider setting content to be finished when the `DOMContentLoaded` event is fired.
- `'networkidle'` - consider setting content to be finished when there are no network connections for at least `500` ms. - `'networkidle'` - consider setting content to be finished when there are no network connections for at least `500` ms.
@ -1760,7 +1760,7 @@ Shortcut for [page.mainFrame().waitForLoadState([options])](#framewaitforloadsta
- `options` <[Object]> Navigation parameters which might have the following properties: - `options` <[Object]> Navigation parameters which might have the following properties:
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
- `url` <[string]|[RegExp]|[Function]> A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. - `url` <[string]|[RegExp]|[Function]> A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either: - `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
- `'load'` - consider navigation to be finished when the `load` event is fired. - `'load'` - consider navigation to be finished when the `load` event is fired.
- `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms. - `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms.
@ -1892,9 +1892,9 @@ const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
An example of getting text from an iframe element: An example of getting text from an iframe element:
```js ```js
const frame = page.frames().find(frame => frame.name() === 'myframe'); const frame = page.frames().find(frame => frame.name() === 'myframe');
const text = await frame.$eval('.selector', element => element.textContent); const text = await frame.$eval('.selector', element => element.textContent);
console.log(text); console.log(text);
``` ```
<!-- GEN:toc --> <!-- GEN:toc -->
@ -2197,7 +2197,7 @@ console.log(frame === contentFrame); // -> true
- `url` <[string]> URL to navigate frame to. The url should include scheme, e.g. `https://`. - `url` <[string]> URL to navigate frame to. The url should include scheme, e.g. `https://`.
- `options` <[Object]> Navigation parameters which might have the following properties: - `options` <[Object]> Navigation parameters which might have the following properties:
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either: - `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
- `'load'` - consider navigation to be finished when the `load` event is fired. - `'load'` - consider navigation to be finished when the `load` event is fired.
- `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms. - `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms.
@ -2303,7 +2303,7 @@ frame.selectOption('select#colors', 'red', 'green', 'blue');
- `html` <[string]> HTML markup to assign to the page. - `html` <[string]> HTML markup to assign to the page.
- `options` <[Object]> Parameters which might have the following properties: - `options` <[Object]> Parameters which might have the following properties:
- `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either: - `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
- `'domcontentloaded'` - consider setting content to be finished when the `DOMContentLoaded` event is fired. - `'domcontentloaded'` - consider setting content to be finished when the `DOMContentLoaded` event is fired.
- `'load'` - consider setting content to be finished when the `load` event is fired. - `'load'` - consider setting content to be finished when the `load` event is fired.
- `'networkidle'` - consider setting content to be finished when there are no network connections for at least `500` ms. - `'networkidle'` - consider setting content to be finished when there are no network connections for at least `500` ms.
@ -2414,7 +2414,7 @@ await frame.waitForLoadState(); // The promise resolves after 'load' event.
- `options` <[Object]> Navigation parameters which might have the following properties: - `options` <[Object]> Navigation parameters which might have the following properties:
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
- `url` <[string]|[RegExp]|[Function]> URL string, URL regex pattern or predicate receiving [URL] to match while waiting for the navigation. - `url` <[string]|[RegExp]|[Function]> URL string, URL regex pattern or predicate receiving [URL] to match while waiting for the navigation.
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either: - `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider navigation succeeded, defaults to `load`. Events can be either:
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
- `'load'` - consider navigation to be finished when the `load` event is fired. - `'load'` - consider navigation to be finished when the `load` event is fired.
- `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms. - `'networkidle'` - consider navigation to be finished when there are no network connections for at least `500` ms.
@ -3822,7 +3822,7 @@ This methods attaches Playwright to an existing browser instance.
- returns: <[string]> A path where Playwright expects to find a bundled browser executable. - returns: <[string]> A path where Playwright expects to find a bundled browser executable.
#### browserType.launch([options]) #### browserType.launch([options])
- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields: - `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
- `headless` <[boolean]> Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true` unless the `devtools` option is `true`. - `headless` <[boolean]> Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true` unless the `devtools` option is `true`.
- `executablePath` <[string]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). Note that Playwright only works with the bundled Chromium, Firefox or WebKit, use at your own risk. - `executablePath` <[string]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). Note that Playwright only works with the bundled Chromium, Firefox or WebKit, use at your own risk.
- `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/). - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/).
@ -3855,7 +3855,7 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
#### browserType.launchPersistentContext(userDataDir, [options]) #### browserType.launchPersistentContext(userDataDir, [options])
- `userDataDir` <[string]> Path to a User Data Directory, which stores browser session data like cookies and local storage. More details for [Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md) and [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile). - `userDataDir` <[string]> Path to a User Data Directory, which stores browser session data like cookies and local storage. More details for [Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md) and [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile).
- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields: - `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
- `headless` <[boolean]> Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true` unless the `devtools` option is `true`. - `headless` <[boolean]> Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true` unless the `devtools` option is `true`.
- `executablePath` <[string]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk. - `executablePath` <[string]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk.
- `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/). - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/).
@ -3873,7 +3873,7 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
Launches browser instance that uses persistent storage located at `userDataDir`. Launches browser instance that uses persistent storage located at `userDataDir`.
#### browserType.launchServer([options]) #### browserType.launchServer([options])
- `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields: - `options` <[Object]> Set of configurable options to set on the browser. Can have the following fields:
- `headless` <[boolean]> Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true` unless the `devtools` option is `true`. - `headless` <[boolean]> Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true` unless the `devtools` option is `true`.
- `port` <[number]> Port to use for the web socket. Defaults to 0 that picks any available port. - `port` <[number]> Port to use for the web socket. Defaults to 0 that picks any available port.
- `executablePath` <[string]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk. - `executablePath` <[string]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk.
@ -4088,12 +4088,12 @@ const v8toIstanbul = require('v8-to-istanbul');
<!-- GEN:stop --> <!-- GEN:stop -->
#### chromiumCoverage.startCSSCoverage([options]) #### chromiumCoverage.startCSSCoverage([options])
- `options` <[Object]> Set of configurable options for coverage - `options` <[Object]> Set of configurable options for coverage
- `resetOnNavigation` <[boolean]> Whether to reset coverage on every navigation. Defaults to `true`. - `resetOnNavigation` <[boolean]> Whether to reset coverage on every navigation. Defaults to `true`.
- returns: <[Promise]> Promise that resolves when coverage is started - returns: <[Promise]> Promise that resolves when coverage is started
#### chromiumCoverage.startJSCoverage([options]) #### chromiumCoverage.startJSCoverage([options])
- `options` <[Object]> Set of configurable options for coverage - `options` <[Object]> Set of configurable options for coverage
- `resetOnNavigation` <[boolean]> Whether to reset coverage on every navigation. Defaults to `true`. - `resetOnNavigation` <[boolean]> Whether to reset coverage on every navigation. Defaults to `true`.
- `reportAnonymousScripts` <[boolean]> Whether anonymous scripts generated by the page should be reported. Defaults to `false`. - `reportAnonymousScripts` <[boolean]> Whether anonymous scripts generated by the page should be reported. Defaults to `false`.
- returns: <[Promise]> Promise that resolves when coverage is started - returns: <[Promise]> Promise that resolves when coverage is started

View file

@ -46,8 +46,7 @@ const context = await browser.newContext({
}); });
// Resize viewport for individual page // Resize viewport for individual page
await page.setViewportSize( await page.setViewportSize({ width: 1600, height: 1200 });
{ 'width': 1600, 'height': 1200 });
// Emulate high-DPI // Emulate high-DPI
const context = await browser.newContext({ const context = await browser.newContext({
@ -155,7 +154,7 @@ const context = await browser.newContext({
Change the location later: Change the location later:
```js ```js
await context.setGeolocation({ longitude: 29.979097, latitude: 31.134256 }; await context.setGeolocation({ longitude: 29.979097, latitude: 31.134256 });
``` ```
**Note** you can only change geolocation for all pages in the context. **Note** you can only change geolocation for all pages in the context.

View file

@ -207,10 +207,10 @@ Simple version produces a single character. This character is case-sensitive, so
```js ```js
// <input id=name></input> // <input id=name>
await page.press('#name', 'Shift+A'); await page.press('#name', 'Shift+A');
// <input id=name></input> // <input id=name>
await page.press('#name', 'Shift+ArrowLeft'); await page.press('#name', 'Shift+ArrowLeft');
``` ```
@ -242,9 +242,9 @@ await page.setInputFiles('input#upload', []);
// Upload buffer from memory // Upload buffer from memory
await page.setInputFiles('input#upload', { await page.setInputFiles('input#upload', {
name: 'file.txt', name: 'file.txt',
mimeType: 'text/plain', mimeType: 'text/plain',
buffer: Buffer.from('this is test') buffer: Buffer.from('this is test')
}); });
``` ```

View file

@ -26,8 +26,8 @@ These browsers will take few hundreds of megabytes of the disk space when instal
```sh ```sh
du -hs ./Library/Caches/ms-playwright/* du -hs ./Library/Caches/ms-playwright/*
281M chromium-XXXXXX 281M chromium-XXXXXX
187M firefox-XXXX 187M firefox-XXXX
180M webkit-XXXX 180M webkit-XXXX
``` ```
You can override default behavior using environment variables. When installing Playwright, ask it to download browsers into a specific location: You can override default behavior using environment variables. When installing Playwright, ask it to download browsers into a specific location:

View file

@ -14,7 +14,7 @@
Use npm or Yarn to install Playwright in your Node.js project. Playwright requires Node.js 10 or higher. Use npm or Yarn to install Playwright in your Node.js project. Playwright requires Node.js 10 or higher.
``` ```sh
npm i playwright npm i playwright
``` ```

View file

@ -40,8 +40,8 @@ You can also use [`browserContext.setHTTPCredentials`](./api.md#browsercontextse
```js ```js
const [ download ] = await Promise.all([ const [ download ] = await Promise.all([
page.waitForEvent('download'), // <-- start waiting for the download page.waitForEvent('download'), // <-- start waiting for the download
page.click('button#delayed-download') // <-- perform the action that directly or indirectly initiates it. page.click('button#delayed-download') // <-- perform the action that directly or indirectly initiates it.
]); ]);
const path = await download.path(); const path = await download.path();
``` ```

View file

@ -7,9 +7,9 @@ This test server is used internally by Playwright to test Playwright itself.
```js ```js
const {TestServer} = require('.'); const {TestServer} = require('.');
(async(() => { (async () => {
const httpServer = await TestServer.create(__dirname, 8000), const httpServer = await TestServer.create(__dirname, 8000);
const httpsServer = await TestServer.createHTTPS(__dirname, 8001) const httpsServer = await TestServer.createHTTPS(__dirname, 8001);
httpServer.setRoute('/hello', (req, res) => { httpServer.setRoute('/hello', (req, res) => {
res.end('Hello, world!'); res.end('Hello, world!');
}); });