2020-12-30 18:04:51 -08:00
|
|
|
<!-- THIS FILE IS NOW GENERATED -->
|
|
|
|
|
2020-06-22 16:53:56 -07:00
|
|
|
# Verification
|
2020-04-20 16:56:46 -07:00
|
|
|
|
2020-05-11 09:54:03 -07:00
|
|
|
<!-- GEN:toc-top-level -->
|
2020-10-07 09:04:53 -07:00
|
|
|
- [Videos](#videos)
|
2020-06-22 16:53:56 -07:00
|
|
|
- [Screenshots](#screenshots)
|
|
|
|
- [Console logs](#console-logs)
|
|
|
|
- [Page errors](#page-errors)
|
2020-04-20 17:17:10 -07:00
|
|
|
- [Page events](#page-events)
|
2020-05-11 09:54:03 -07:00
|
|
|
<!-- GEN:stop -->
|
2020-04-20 16:56:46 -07:00
|
|
|
|
|
|
|
<br/>
|
|
|
|
|
2020-10-07 09:04:53 -07:00
|
|
|
## Videos
|
|
|
|
|
2020-12-30 18:04:51 -08:00
|
|
|
Playwright can record videos for all pages in a
|
|
|
|
[browser context](core-concepts.md#browser-contexts). Videos are saved upon
|
|
|
|
context closure, so make sure to await `browserContext.close()`.
|
2020-10-07 09:04:53 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
// With browser.newContext()
|
2020-11-02 19:42:05 -08:00
|
|
|
const context = await browser.newContext({ recordVideo: { dir: 'videos/' } });
|
2020-10-13 09:33:31 -07:00
|
|
|
// Make sure to await close, so that videos are saved.
|
|
|
|
await context.close();
|
2020-10-07 09:04:53 -07:00
|
|
|
|
|
|
|
// With browser.newPage()
|
2020-11-02 19:42:05 -08:00
|
|
|
const page = await browser.newPage({ recordVideo: { dir: 'videos/' } });
|
2020-10-13 09:33:31 -07:00
|
|
|
// Make sure to await close, so that videos are saved.
|
|
|
|
await page.close();
|
2020-10-07 09:04:53 -07:00
|
|
|
|
|
|
|
// [Optional] Specify video size; defaults to viewport size
|
|
|
|
const context = await browser.newContext({
|
2020-11-02 19:42:05 -08:00
|
|
|
recordVideo: {
|
|
|
|
dir: 'videos/',
|
|
|
|
size: { width: 800, height: 600 },
|
|
|
|
}
|
2020-10-07 09:04:53 -07:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
#### API reference
|
2020-12-30 18:04:51 -08:00
|
|
|
- [BrowserContext]
|
2020-10-07 09:04:53 -07:00
|
|
|
- [browser.newContext([options])](./api.md#browsernewcontextoptions)
|
|
|
|
- [browser.newPage([options])](./api.md#browsernewpageoptions)
|
2020-10-13 09:33:31 -07:00
|
|
|
- [browserContext.close()](./api.md#browsercontextclose)
|
2020-10-07 09:04:53 -07:00
|
|
|
|
2020-06-22 16:53:56 -07:00
|
|
|
## Screenshots
|
2020-04-20 16:56:46 -07:00
|
|
|
|
|
|
|
```js
|
2020-05-02 17:21:46 -07:00
|
|
|
// Save to file
|
2020-10-07 09:04:53 -07:00
|
|
|
await page.screenshot({ path: 'screenshot.png' });
|
2020-04-20 17:17:10 -07:00
|
|
|
|
2020-05-02 17:21:46 -07:00
|
|
|
// Capture full page
|
2020-10-07 09:04:53 -07:00
|
|
|
await page.screenshot({ path: 'screenshot.png', fullPage: true });
|
2020-04-20 17:17:10 -07:00
|
|
|
|
2020-05-02 17:21:46 -07:00
|
|
|
// Capture into buffer
|
2020-04-20 17:17:10 -07:00
|
|
|
const buffer = await page.screenshot();
|
|
|
|
console.log(buffer.toString('base64'));
|
2020-04-20 16:56:46 -07:00
|
|
|
|
2020-05-02 17:21:46 -07:00
|
|
|
// Capture given element
|
|
|
|
const elementHandle = await page.$('.header');
|
|
|
|
await elementHandle.screenshot({ path: 'screenshot.png' });
|
2020-05-03 16:59:41 +02:00
|
|
|
```
|
2020-04-20 16:56:46 -07:00
|
|
|
|
|
|
|
#### API reference
|
|
|
|
- [page.screenshot([options])](./api.md#pagescreenshotoptions)
|
2020-04-20 17:17:10 -07:00
|
|
|
- [elementHandle.screenshot([options])](./api.md#elementhandlescreenshotoptions)
|
2020-04-20 16:56:46 -07:00
|
|
|
|
|
|
|
<br/>
|
|
|
|
|
2020-06-22 16:53:56 -07:00
|
|
|
## Console logs
|
2020-04-20 16:56:46 -07:00
|
|
|
|
2020-06-23 19:34:18 -07:00
|
|
|
Console messages logged in the page can be brought into the Node.js context.
|
2020-04-20 16:56:46 -07:00
|
|
|
|
|
|
|
```js
|
2020-06-23 19:34:18 -07:00
|
|
|
// Listen for all console logs
|
|
|
|
page.on('console', msg => console.log(msg.text()))
|
|
|
|
|
|
|
|
// Listen for all console events and handle errors
|
2020-04-20 17:17:10 -07:00
|
|
|
page.on('console', msg => {
|
2020-06-23 19:34:18 -07:00
|
|
|
if (msg.type() === 'error')
|
|
|
|
console.log(`Error text: "${msg.text()}"`);
|
2020-04-20 17:17:10 -07:00
|
|
|
});
|
2020-06-23 19:34:18 -07:00
|
|
|
|
|
|
|
// Get the next console log
|
|
|
|
const [msg] = await Promise.all([
|
|
|
|
page.waitForEvent('console'),
|
|
|
|
// Issue console.log inside the page
|
|
|
|
page.evaluate(() => {
|
2020-10-07 09:04:53 -07:00
|
|
|
console.log('hello', 42, { foo: 'bar' });
|
2020-06-23 19:34:18 -07:00
|
|
|
}),
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Deconstruct console log arguments
|
|
|
|
await msg.args[0].jsonValue() // hello
|
|
|
|
await msg.args[1].jsonValue() // 42
|
2020-04-20 16:56:46 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
#### API reference
|
2020-12-30 18:04:51 -08:00
|
|
|
- [ConsoleMessage]
|
|
|
|
- [Page]
|
2020-12-04 11:09:20 -08:00
|
|
|
- [page.on('console')](./api.md#pageonconsole)
|
2020-04-20 16:56:46 -07:00
|
|
|
|
|
|
|
<br/>
|
|
|
|
|
2020-06-22 16:53:56 -07:00
|
|
|
## Page errors
|
2020-04-20 16:56:46 -07:00
|
|
|
|
2020-06-22 16:53:56 -07:00
|
|
|
Listen for uncaught exceptions in the page with the `pagerror` event.
|
2020-04-20 17:17:10 -07:00
|
|
|
|
2020-04-20 16:56:46 -07:00
|
|
|
```js
|
2020-04-20 17:17:10 -07:00
|
|
|
// Log all uncaught errors to the terminal
|
|
|
|
page.on('pageerror', exception => {
|
|
|
|
console.log(`Uncaught exception: "${exception}"`);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Navigate to a page with an exception.
|
|
|
|
await page.goto('data:text/html,<script>throw new Error("Test")</script>');
|
2020-04-20 16:56:46 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
#### API reference
|
2020-12-30 18:04:51 -08:00
|
|
|
- [Page]
|
2020-12-04 11:09:20 -08:00
|
|
|
- [page.on('pageerror')](./api.md#pageonpageerror)
|
2020-04-20 16:56:46 -07:00
|
|
|
|
|
|
|
<br/>
|
2020-06-22 16:53:56 -07:00
|
|
|
|
|
|
|
## Page events
|
|
|
|
|
|
|
|
#### `"requestfailed"`
|
|
|
|
|
|
|
|
```js
|
|
|
|
page.on('requestfailed', request => {
|
|
|
|
console.log(request.url() + ' ' + request.failure().errorText);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
#### `"dialog"` - handle alert, confirm, prompt
|
|
|
|
|
|
|
|
```js
|
|
|
|
page.on('dialog', dialog => {
|
|
|
|
dialog.accept();
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
#### `"popup"` - handle popup windows
|
|
|
|
|
|
|
|
```js
|
|
|
|
const [popup] = await Promise.all([
|
|
|
|
page.waitForEvent('popup'),
|
|
|
|
page.click('#open')
|
|
|
|
]);
|
|
|
|
```
|
|
|
|
|
|
|
|
#### API reference
|
2020-12-30 18:04:51 -08:00
|
|
|
- [Page]
|
2020-12-04 11:09:20 -08:00
|
|
|
- [page.on('requestfailed')](./api.md#pageonrequestfailed)
|
|
|
|
- [page.on('dialog')](./api.md#pageondialog)
|
|
|
|
- [page.on('popup')](./api.md#pageonpopup)
|
2020-12-30 18:04:51 -08:00
|
|
|
[Playwright]: api.md#class-playwright "Playwright"
|
|
|
|
[Browser]: api.md#class-browser "Browser"
|
|
|
|
[BrowserContext]: api.md#class-browsercontext "BrowserContext"
|
|
|
|
[Page]: api.md#class-page "Page"
|
|
|
|
[Frame]: api.md#class-frame "Frame"
|
|
|
|
[ElementHandle]: api.md#class-elementhandle "ElementHandle"
|
|
|
|
[JSHandle]: api.md#class-jshandle "JSHandle"
|
|
|
|
[ConsoleMessage]: api.md#class-consolemessage "ConsoleMessage"
|
|
|
|
[Dialog]: api.md#class-dialog "Dialog"
|
|
|
|
[Download]: api.md#class-download "Download"
|
|
|
|
[Video]: api.md#class-video "Video"
|
|
|
|
[FileChooser]: api.md#class-filechooser "FileChooser"
|
|
|
|
[Keyboard]: api.md#class-keyboard "Keyboard"
|
|
|
|
[Mouse]: api.md#class-mouse "Mouse"
|
|
|
|
[Touchscreen]: api.md#class-touchscreen "Touchscreen"
|
|
|
|
[Request]: api.md#class-request "Request"
|
|
|
|
[Response]: api.md#class-response "Response"
|
|
|
|
[Selectors]: api.md#class-selectors "Selectors"
|
|
|
|
[Route]: api.md#class-route "Route"
|
|
|
|
[WebSocket]: api.md#class-websocket "WebSocket"
|
|
|
|
[TimeoutError]: api.md#class-timeouterror "TimeoutError"
|
|
|
|
[Accessibility]: api.md#class-accessibility "Accessibility"
|
|
|
|
[Worker]: api.md#class-worker "Worker"
|
|
|
|
[BrowserServer]: api.md#class-browserserver "BrowserServer"
|
|
|
|
[BrowserType]: api.md#class-browsertype "BrowserType"
|
|
|
|
[Logger]: api.md#class-logger "Logger"
|
|
|
|
[ChromiumBrowser]: api.md#class-chromiumbrowser "ChromiumBrowser"
|
|
|
|
[ChromiumBrowserContext]: api.md#class-chromiumbrowsercontext "ChromiumBrowserContext"
|
|
|
|
[ChromiumCoverage]: api.md#class-chromiumcoverage "ChromiumCoverage"
|
|
|
|
[CDPSession]: api.md#class-cdpsession "CDPSession"
|
|
|
|
[FirefoxBrowser]: api.md#class-firefoxbrowser "FirefoxBrowser"
|
|
|
|
[WebKitBrowser]: api.md#class-webkitbrowser "WebKitBrowser"
|
|
|
|
[Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array"
|
|
|
|
[Buffer]: https://nodejs.org/api/buffer.html#buffer_class_buffer "Buffer"
|
|
|
|
[ChildProcess]: https://nodejs.org/api/child_process.html "ChildProcess"
|
|
|
|
[Element]: https://developer.mozilla.org/en-US/docs/Web/API/element "Element"
|
|
|
|
[Error]: https://nodejs.org/api/errors.html#errors_class_error "Error"
|
|
|
|
[EvaluationArgument]: #evaluationargument "Evaluation Argument"
|
|
|
|
[Map]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map "Map"
|
|
|
|
[Object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object"
|
|
|
|
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"
|
|
|
|
[RegExp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp"
|
|
|
|
[Serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable"
|
|
|
|
[UIEvent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"
|
|
|
|
[URL]: https://nodejs.org/api/url.html "URL"
|
|
|
|
[USKeyboardLayout]: ../src/usKeyboardLayout.ts "USKeyboardLayout"
|
|
|
|
[UnixTime]: https://en.wikipedia.org/wiki/Unix_time "Unix Time"
|
|
|
|
[boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean"
|
|
|
|
[function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function"
|
|
|
|
[iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols "Iterator"
|
|
|
|
[null]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null "null"
|
|
|
|
[number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number"
|
|
|
|
[origin]: https://developer.mozilla.org/en-US/docs/Glossary/Origin "Origin"
|
|
|
|
[selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector"
|
|
|
|
[Readable]: https://nodejs.org/api/stream.html#stream_class_stream_readable "Readable"
|
|
|
|
[string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string"
|
|
|
|
[xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath"
|