feat: introduce page.browserContext() (#3655)

This commit is contained in:
Andrey Lushnikov 2018-12-12 15:08:31 -08:00 committed by GitHub
parent 4346fa1978
commit c90392bdf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -96,6 +96,7 @@
* [page.authenticate(credentials)](#pageauthenticatecredentials) * [page.authenticate(credentials)](#pageauthenticatecredentials)
* [page.bringToFront()](#pagebringtofront) * [page.bringToFront()](#pagebringtofront)
* [page.browser()](#pagebrowser) * [page.browser()](#pagebrowser)
* [page.browserContext()](#pagebrowsercontext)
* [page.click(selector[, options])](#pageclickselector-options) * [page.click(selector[, options])](#pageclickselector-options)
* [page.close([options])](#pagecloseoptions) * [page.close([options])](#pagecloseoptions)
* [page.content()](#pagecontent) * [page.content()](#pagecontent)
@ -1099,6 +1100,12 @@ Brings page to front (activates tab).
Get the browser the page belongs to. Get the browser the page belongs to.
#### page.browserContext()
- returns: <[BrowserContext]>
Get the browser context that the page belongs to.
#### page.click(selector[, options]) #### page.click(selector[, options])
- `selector` <[string]> A [selector] to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked. - `selector` <[string]> A [selector] to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked.
- `options` <[Object]> - `options` <[Object]>

View File

@ -172,6 +172,13 @@ class Page extends EventEmitter {
return this._target.browser(); return this._target.browser();
} }
/**
* @return {!Puppeteer.BrowserContext}
*/
browserContext() {
return this._target.browserContext();
}
_onTargetCrashed() { _onTargetCrashed() {
this.emit('error', new Error('Page crashed!')); this.emit('error', new Error('Page crashed!'));
} }

View File

@ -918,4 +918,10 @@ module.exports.addTests = function({testRunner, expect, headless}) {
expect(page.browser()).toBe(browser); expect(page.browser()).toBe(browser);
}); });
}); });
describe('Page.browserContext', function() {
it('should return the correct browser instance', async function({page, context, browser}) {
expect(page.browserContext()).toBe(context);
});
});
}; };