Move path option into tracing.start (#192)

This consolidates all the tracing options in the tracing.start()
This commit is contained in:
JoelEinbinder 2017-08-02 15:41:05 -07:00 committed by Andrey Lushnikov
parent 315c388f4d
commit 984e011cf0
3 changed files with 19 additions and 17 deletions

View File

@ -73,8 +73,8 @@
+ [mouse.move(x, y)](#mousemovex-y)
+ [mouse.up([options])](#mouseupoptions)
* [class: Tracing](#class-tracing)
+ [tracing.start([options])](#tracingstartoptions)
+ [tracing.stop(path)](#tracingstoppath)
+ [tracing.start(options)](#tracingstartoptions)
+ [tracing.stop()](#tracingstop)
* [class: Dialog](#class-dialog)
+ [dialog.accept([promptText])](#dialogacceptprompttext)
+ [dialog.dismiss()](#dialogdismiss)
@ -839,18 +839,18 @@ Dispatches a `mouseup` event.
You can use [`tracing.start`](#tracingstartoptions) and [`tracing.stop`](#tracingstoppath) to create a trace file which can be opened in Chrome DevTools or [timeline viewer](https://chromedevtools.github.io/timeline-viewer/).
```js
await page.tracing.start();
await page.tracing.start({path: 'trace.json'});
await page.navigate('https://www.google.com');
await page.tracing.stop('trace.json');
await page.tracing.stop();
```
#### tracing.start([options])
#### tracing.start(options)
- `options` <[Object]>
- `path` <[string]> A path to write the trace file to. **required**
- `screenshots` <[boolean]> captures screenshots in the trace.
- returns: <[Promise]>
#### tracing.stop(path)
- `path` <[string]> A path to write the trace file to.
#### tracing.stop()
- returns: <[Promise]>
### class: Dialog

View File

@ -23,14 +23,16 @@ class Tracing {
constructor(client) {
this._client = client;
this._recording = false;
this._path = '';
}
/**
* @param {Object=} options
* @param {!Object} options
* @return {!Promise}
*/
async start(options = {}) {
async start(options) {
console.assert(!this._recording, 'Cannot start recording trace while already recording trace.');
console.assert(options.path, 'Must specify a path to write trace file to.');
const categoriesArray = [
'-*', 'devtools.timeline', 'v8.execute', 'disabled-by-default-devtools.timeline',
@ -42,6 +44,7 @@ class Tracing {
if (options.screenshots)
categoriesArray.push('disabled-by-default-devtools.screenshot');
this._path = options.path;
this._recording = true;
await this._client.send('Tracing.start', {
transferMode: 'ReturnAsStream',
@ -50,14 +53,13 @@ class Tracing {
}
/**
* @param {string} path
* @return {!Promise}
*/
async stop(path) {
async stop() {
let fulfill;
let contentPromise = new Promise(x => fulfill = x);
this._client.once('Tracing.tracingComplete', event => {
this._readStream(event.stream, path).then(fulfill);
this._readStream(event.stream, this._path).then(fulfill);
});
await this._client.send('Tracing.end');
this._recording = false;

View File

@ -1503,23 +1503,23 @@ describe('Page', function() {
fs.unlinkSync(outputFile);
});
it('should output a trace', SX(async function() {
await page.tracing.start({screenshots: true});
await page.tracing.start({screenshots: true, path: outputFile});
await page.navigate(PREFIX + '/grid.html');
await page.tracing.stop(outputFile);
await page.tracing.stop();
expect(fs.existsSync(outputFile)).toBe(true);
}));
it('should throw if tracing on two pages', SX(async function() {
await page.tracing.start();
await page.tracing.start({path: outputFile});
let newPage = await browser.newPage();
let error = null;
try {
await newPage.tracing.start();
await newPage.tracing.start({path: outputFile});
} catch (e) {
error = e;
}
await newPage.close();
expect(error).toBeTruthy();
await page.tracing.stop(outputFile);
await page.tracing.stop();
}));
});
});