|
21 | 21 | - [class: Selectors](#class-selectors)
|
22 | 22 | - [class: TimeoutError](#class-timeouterror)
|
23 | 23 | - [class: Accessibility](#class-accessibility)
|
24 |
| -- [class: Coverage](#class-coverage) |
25 | 24 | - [class: Worker](#class-worker)
|
26 | 25 | - [class: BrowserServer](#class-browserserver)
|
27 | 26 | - [class: BrowserType](#class-browsertype)
|
28 | 27 | - [class: ChromiumBrowser](#class-chromiumbrowser)
|
| 28 | +- [class: ChromiumCoverage](#class-chromiumcoverage) |
29 | 29 | - [class: ChromiumSession](#class-chromiumsession)
|
30 | 30 | - [class: ChromiumTarget](#class-chromiumtarget)
|
31 | 31 | - [class: FirefoxBrowser](#class-firefoxbrowser)
|
@@ -821,9 +821,9 @@ Get the browser context that the page belongs to.
|
821 | 821 |
|
822 | 822 | #### page.coverage
|
823 | 823 |
|
824 |
| -- returns: <[Coverage]> |
| 824 | +- returns: <?[any]> |
825 | 825 |
|
826 |
| -> **NOTE** Code coverage is currently only supported in Chromium. |
| 826 | +Browser-specific Coverage implementation, only available for Chromium atm. See [ChromiumCoverage](#class-chromiumcoverage) for more details. |
827 | 827 |
|
828 | 828 | #### page.dblclick(selector[, options])
|
829 | 829 | - `selector` <[string]> A selector to search for element to double click. If there are multiple elements satisfying the selector, the first will be double clicked.
|
@@ -3261,78 +3261,6 @@ function findFocusedNode(node) {
|
3261 | 3261 | }
|
3262 | 3262 | ```
|
3263 | 3263 |
|
3264 |
| -### class: Coverage |
3265 |
| - |
3266 |
| -Coverage gathers information about parts of JavaScript and CSS that were used by the page. |
3267 |
| - |
3268 |
| -An example of using JavaScript and CSS coverage to get percentage of initially |
3269 |
| -executed code: |
3270 |
| - |
3271 |
| -```js |
3272 |
| -// Enable both JavaScript and CSS coverage |
3273 |
| -await Promise.all([ |
3274 |
| - page.coverage.startJSCoverage(), |
3275 |
| - page.coverage.startCSSCoverage() |
3276 |
| -]); |
3277 |
| -// Navigate to page |
3278 |
| -await page.goto('https://example.com'); |
3279 |
| -// Disable both JavaScript and CSS coverage |
3280 |
| -const [jsCoverage, cssCoverage] = await Promise.all([ |
3281 |
| - page.coverage.stopJSCoverage(), |
3282 |
| - page.coverage.stopCSSCoverage(), |
3283 |
| -]); |
3284 |
| -let totalBytes = 0; |
3285 |
| -let usedBytes = 0; |
3286 |
| -const coverage = [...jsCoverage, ...cssCoverage]; |
3287 |
| -for (const entry of coverage) { |
3288 |
| - totalBytes += entry.text.length; |
3289 |
| - for (const range of entry.ranges) |
3290 |
| - usedBytes += range.end - range.start - 1; |
3291 |
| -} |
3292 |
| -console.log(`Bytes used: ${usedBytes / totalBytes * 100}%`); |
3293 |
| -``` |
3294 |
| - |
3295 |
| -<!-- GEN:toc --> |
3296 |
| -- [coverage.startCSSCoverage([options])](#coveragestartcsscoverageoptions) |
3297 |
| -- [coverage.startJSCoverage([options])](#coveragestartjscoverageoptions) |
3298 |
| -- [coverage.stopCSSCoverage()](#coveragestopcsscoverage) |
3299 |
| -- [coverage.stopJSCoverage()](#coveragestopjscoverage) |
3300 |
| -<!-- GEN:stop --> |
3301 |
| - |
3302 |
| -#### coverage.startCSSCoverage([options]) |
3303 |
| -- `options` <[Object]> Set of configurable options for coverage |
3304 |
| - - `resetOnNavigation` <[boolean]> Whether to reset coverage on every navigation. Defaults to `true`. |
3305 |
| -- returns: <[Promise]> Promise that resolves when coverage is started |
3306 |
| - |
3307 |
| -#### coverage.startJSCoverage([options]) |
3308 |
| -- `options` <[Object]> Set of configurable options for coverage |
3309 |
| - - `resetOnNavigation` <[boolean]> Whether to reset coverage on every navigation. Defaults to `true`. |
3310 |
| - - `reportAnonymousScripts` <[boolean]> Whether anonymous scripts generated by the page should be reported. Defaults to `false`. |
3311 |
| -- returns: <[Promise]> Promise that resolves when coverage is started |
3312 |
| - |
3313 |
| -> **NOTE** Anonymous scripts are ones that don't have an associated url. These are scripts that are dynamically created on the page using `eval` or `new Function`. If `reportAnonymousScripts` is set to `true`, anonymous scripts will have `__playwright_evaluation_script__` as their URL. |
3314 |
| -
|
3315 |
| -#### coverage.stopCSSCoverage() |
3316 |
| -- returns: <[Promise]<[Array]<[Object]>>> Promise that resolves to the array of coverage reports for all stylesheets |
3317 |
| - - `url` <[string]> StyleSheet URL |
3318 |
| - - `text` <[string]> StyleSheet content |
3319 |
| - - `ranges` <[Array]<[Object]>> StyleSheet ranges that were used. Ranges are sorted and non-overlapping. |
3320 |
| - - `start` <[number]> A start offset in text, inclusive |
3321 |
| - - `end` <[number]> An end offset in text, exclusive |
3322 |
| - |
3323 |
| -> **NOTE** CSS Coverage doesn't include dynamically injected style tags without sourceURLs. |
3324 |
| -
|
3325 |
| -#### coverage.stopJSCoverage() |
3326 |
| -- returns: <[Promise]<[Array]<[Object]>>> Promise that resolves to the array of coverage reports for all scripts |
3327 |
| - - `url` <[string]> Script URL |
3328 |
| - - `text` <[string]> Script content |
3329 |
| - - `ranges` <[Array]<[Object]>> Script ranges that were executed. Ranges are sorted and non-overlapping. |
3330 |
| - - `start` <[number]> A start offset in text, inclusive |
3331 |
| - - `end` <[number]> An end offset in text, exclusive |
3332 |
| - |
3333 |
| -> **NOTE** JavaScript Coverage doesn't include anonymous scripts by default. However, scripts with sourceURLs are |
3334 |
| -reported. |
3335 |
| - |
3336 | 3264 | ### class: Worker
|
3337 | 3265 |
|
3338 | 3266 | The Worker class represents a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API).
|
@@ -3687,6 +3615,71 @@ await page.evaluate(() => window.open('https://www.example.com/'));
|
3687 | 3615 | const newWindowTarget = await browser.chromium.waitForTarget(target => target.url() === 'https://www.example.com/');
|
3688 | 3616 | ```
|
3689 | 3617 |
|
| 3618 | +### class: ChromiumCoverage |
| 3619 | + |
| 3620 | +Coverage gathers information about parts of JavaScript and CSS that were used by the page. |
| 3621 | + |
| 3622 | +An example of using JavaScript coverage to produce Istambul report for page load: |
| 3623 | + |
| 3624 | +```js |
| 3625 | +const { chromium } = require('.'); |
| 3626 | +const v8toIstanbul = require('v8-to-istanbul'); |
| 3627 | + |
| 3628 | +(async() => { |
| 3629 | + const browser = await chromium.launch(); |
| 3630 | + const page = await browser.newPage(); |
| 3631 | + await page.coverage.startJSCoverage(); |
| 3632 | + await page.goto('https://chromium.org'); |
| 3633 | + const coverage = await page.coverage.stopJSCoverage(); |
| 3634 | + for (const entry of coverage) { |
| 3635 | + const converter = new v8toIstanbul('', 0, { source: entry.source }); |
| 3636 | + await converter.load(); |
| 3637 | + converter.applyCoverage(entry.functions); |
| 3638 | + console.log(JSON.stringify(converter.toIstanbul())); |
| 3639 | + } |
| 3640 | + await browser.close(); |
| 3641 | +})(); |
| 3642 | +``` |
| 3643 | + |
| 3644 | +<!-- GEN:toc --> |
| 3645 | +- [chromiumCoverage.startCSSCoverage([options])](#chromiumcoveragestartcsscoverageoptions) |
| 3646 | +- [chromiumCoverage.startJSCoverage([options])](#chromiumcoveragestartjscoverageoptions) |
| 3647 | +- [chromiumCoverage.stopCSSCoverage()](#chromiumcoveragestopcsscoverage) |
| 3648 | +- [chromiumCoverage.stopJSCoverage()](#chromiumcoveragestopjscoverage) |
| 3649 | +<!-- GEN:stop --> |
| 3650 | + |
| 3651 | +#### chromiumCoverage.startCSSCoverage([options]) |
| 3652 | +- `options` <[Object]> Set of configurable options for coverage |
| 3653 | + - `resetOnNavigation` <[boolean]> Whether to reset coverage on every navigation. Defaults to `true`. |
| 3654 | +- returns: <[Promise]> Promise that resolves when coverage is started |
| 3655 | + |
| 3656 | +#### chromiumCoverage.startJSCoverage([options]) |
| 3657 | +- `options` <[Object]> Set of configurable options for coverage |
| 3658 | + - `resetOnNavigation` <[boolean]> Whether to reset coverage on every navigation. Defaults to `true`. |
| 3659 | + - `reportAnonymousScripts` <[boolean]> Whether anonymous scripts generated by the page should be reported. Defaults to `false`. |
| 3660 | +- returns: <[Promise]> Promise that resolves when coverage is started |
| 3661 | + |
| 3662 | +> **NOTE** Anonymous scripts are ones that don't have an associated url. These are scripts that are dynamically created on the page using `eval` or `new Function`. If `reportAnonymousScripts` is set to `true`, anonymous scripts will have `__playwright_evaluation_script__` as their URL. |
| 3663 | +
|
| 3664 | +#### chromiumCoverage.stopCSSCoverage() |
| 3665 | +- returns: <[Promise]<[Array]<[Object]>>> Promise that resolves to the array of coverage reports for all stylesheets |
| 3666 | + - `url` <[string]> StyleSheet URL |
| 3667 | + - `text` <[string]> StyleSheet content |
| 3668 | + - `ranges` <[Array]<[Object]>> StyleSheet ranges that were used. Ranges are sorted and non-overlapping. |
| 3669 | + - `start` <[number]> A start offset in text, inclusive |
| 3670 | + - `end` <[number]> An end offset in text, exclusive |
| 3671 | + |
| 3672 | +> **NOTE** CSS Coverage doesn't include dynamically injected style tags without sourceURLs. |
| 3673 | +
|
| 3674 | +#### chromiumCoverage.stopJSCoverage() |
| 3675 | +- returns: <[Promise]<[Array]<[Object]>>> Promise that resolves to the array of coverage reports for all scripts |
| 3676 | + - `url` <[string]> Script URL |
| 3677 | + - `source` <[string]> Script content |
| 3678 | + - `functions` <[Array]<[Object]>> V8-specific coverage format. |
| 3679 | + |
| 3680 | +> **NOTE** JavaScript Coverage doesn't include anonymous scripts by default. However, scripts with sourceURLs are |
| 3681 | +reported. |
| 3682 | + |
3690 | 3683 | ### class: ChromiumSession
|
3691 | 3684 |
|
3692 | 3685 | * extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
|
0 commit comments