api: s/createIncognitoBrowserContext/newContext/

This commit is contained in:
Pavel Feldman 2019-12-12 20:14:00 -08:00
parent 90f0b8c2b0
commit c7cf4886ea
13 changed files with 26 additions and 26 deletions

View File

@ -32,7 +32,7 @@
* [browser.browserContexts()](#browserbrowsercontexts)
* [browser.chromium](#browserchromium)
* [browser.close()](#browserclose)
* [browser.createIncognitoBrowserContext()](#browsercreateincognitobrowsercontext)
* [browser.newContext()](#browsernewcontext)
* [browser.defaultBrowserContext()](#browserdefaultbrowsercontext)
* [browser.disconnect()](#browserdisconnect)
* [browser.isConnected()](#browserisconnected)
@ -625,7 +625,7 @@ a single instance of [BrowserContext].
Closes Chromium and all of its pages (if any were opened). The [Browser] object itself is considered to be disposed and cannot be used anymore.
#### browser.createIncognitoBrowserContext()
#### browser.newContext()
- returns: <[Promise]<[BrowserContext]>>
Creates a new incognito browser context. This won't share cookies/cache with other browser contexts.
@ -634,7 +634,7 @@ Creates a new incognito browser context. This won't share cookies/cache with oth
(async () => {
const browser = await playwright.launch();
// Create a new incognito browser context.
const context = await browser.createIncognitoBrowserContext();
const context = await browser.newContext();
// Create a new page in a pristine context.
const page = await context.newPage();
// Do stuff
@ -691,12 +691,12 @@ a single BrowserContext used by default. The method `browser.newPage()` creates
If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser
context.
Playwright allows creation of "incognito" browser contexts with `browser.createIncognitoBrowserContext()` method.
Playwright allows creation of "incognito" browser contexts with `browser.newContext()` method.
"Incognito" browser contexts don't write any browsing data to disk.
```js
// Create a new incognito browser context
const context = await browser.createIncognitoBrowserContext();
const context = await browser.newContext();
// Create a new page inside context.
const page = await context.newPage();
// ... do stuff with page ...

View File

@ -23,7 +23,7 @@ import * as childProcess from 'child_process';
export interface BrowserInterface {
browserContexts(): BrowserContext[];
close(): Promise<void>;
createIncognitoBrowserContext(): Promise<BrowserContext>;
newContext(): Promise<BrowserContext>;
defaultBrowserContext(): BrowserContext;
newPage(): Promise<Page>;
pages(): Promise<Page[]>;

View File

@ -127,7 +127,7 @@ export class Browser extends EventEmitter implements BrowserInterface {
return this._process;
}
async createIncognitoBrowserContext(): Promise<BrowserContext> {
async newContext(): Promise<BrowserContext> {
const {browserContextId} = await this._client.send('Target.createBrowserContext');
const context = this._createBrowserContext(browserContextId);
this._contexts.set(browserContextId, context);

View File

@ -78,7 +78,7 @@ export class Browser extends EventEmitter implements BrowserInterface {
return !this._connection._closed;
}
async createIncognitoBrowserContext(): Promise<BrowserContext> {
async newContext(): Promise<BrowserContext> {
const {browserContextId} = await this._connection.send('Target.createBrowserContext');
const context = this._createBrowserContext(browserContextId);
this._contexts.set(browserContextId, context);

View File

@ -70,7 +70,7 @@ export class Browser extends EventEmitter implements BrowserInterface {
}
async userAgent(): Promise<string> {
const context = await this.createIncognitoBrowserContext();
const context = await this.newContext();
const page = await context.newPage();
const userAgent = await page.evaluate(() => navigator.userAgent);
context.close();
@ -86,7 +86,7 @@ export class Browser extends EventEmitter implements BrowserInterface {
return this._process;
}
async createIncognitoBrowserContext(): Promise<BrowserContext> {
async newContext(): Promise<BrowserContext> {
const {browserContextId} = await this._connection.send('Browser.createContext');
const context = this._createBrowserContext(browserContextId);
this._contexts.set(browserContextId, context);

View File

@ -34,7 +34,7 @@ module.exports.addTests = function({testRunner, expect}) {
});
it('should create new incognito context', async function({browser, server}) {
expect(browser.browserContexts().length).toBe(1);
const context = await browser.createIncognitoBrowserContext();
const context = await browser.newContext();
expect(context.isIncognito()).toBe(true);
expect(browser.browserContexts().length).toBe(2);
expect(browser.browserContexts().indexOf(context) !== -1).toBe(true);
@ -44,7 +44,7 @@ module.exports.addTests = function({testRunner, expect}) {
it('should close all belonging targets once closing context', async function({browser, server}) {
expect((await browser.pages()).length).toBe(1);
const context = await browser.createIncognitoBrowserContext();
const context = await browser.newContext();
await context.newPage();
expect((await browser.pages()).length).toBe(2);
expect((await context.pages()).length).toBe(1);
@ -53,7 +53,7 @@ module.exports.addTests = function({testRunner, expect}) {
expect((await browser.pages()).length).toBe(1);
});
it('window.open should use parent tab context', async function({browser, server}) {
const context = await browser.createIncognitoBrowserContext();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
const [popupTarget] = await Promise.all([
@ -65,8 +65,8 @@ module.exports.addTests = function({testRunner, expect}) {
});
it('should isolate localStorage and cookies', async function({browser, server}) {
// Create two incognito contexts.
const context1 = await browser.createIncognitoBrowserContext();
const context2 = await browser.createIncognitoBrowserContext();
const context1 = await browser.newContext();
const context2 = await browser.newContext();
expect((await context1.pages()).length).toBe(0);
expect((await context2.pages()).length).toBe(0);

View File

@ -24,7 +24,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
describe('Chromium', function() {
it('should work across sessions', async function({browser, server}) {
expect(browser.browserContexts().length).toBe(2);
const context = await browser.createIncognitoBrowserContext();
const context = await browser.newContext();
expect(browser.browserContexts().length).toBe(3);
const remoteBrowser = await playwright.connect({
browserWSEndpoint: browser.chromium.wsEndpoint()
@ -175,7 +175,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
describe('Chromium.waitForTarget', () => {
it('should wait for a target', async function({browser, server}) {
const context = await browser.createIncognitoBrowserContext();
const context = await browser.newContext();
let resolved = false;
const targetPromise = browser.chromium.waitForTarget(target => target.browserContext() === context && target.url() === server.EMPTY_PAGE);
targetPromise.then(() => resolved = true);
@ -187,7 +187,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
await context.close();
});
it('should timeout waiting for a non-existent target', async function({browser, server}) {
const context = await browser.createIncognitoBrowserContext();
const context = await browser.newContext();
const error = await browser.chromium.waitForTarget(target => target.browserContext() === context && target.url() === server.EMPTY_PAGE, {timeout: 1}).catch(e => e);
expect(error).toBeInstanceOf(playwright.errors.TimeoutError);
await context.close();
@ -211,7 +211,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
expect(error).toBeInstanceOf(playwright.errors.TimeoutError);
});
it('should fire target events', async function({browser, server}) {
const context = await browser.createIncognitoBrowserContext();
const context = await browser.newContext();
const events = [];
browser.chromium.on('targetcreated', target => events.push('CREATED: ' + target.url()));
browser.chromium.on('targetchanged', target => events.push('CHANGED: ' + target.url()));

View File

@ -118,7 +118,7 @@ module.exports.addTests = function({testRunner, expect, playwright, defaultBrows
});
it('should open devtools when "devtools: true" option is given', async({server}) => {
const browser = await playwright.launch(Object.assign({devtools: true}, headfulOptions));
const context = await browser.createIncognitoBrowserContext();
const context = await browser.newContext();
await Promise.all([
context.newPage(),
browser.chromium.waitForTarget(target => target.browserContext() === context && target.url().includes('devtools://')),

View File

@ -26,7 +26,7 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
}));
});
beforeEach(async function(state) {
state.context = await state.browser.createIncognitoBrowserContext();
state.context = await state.browser.newContext();
state.page = await state.context.newPage();
});
afterEach(async function(state) {

View File

@ -155,7 +155,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
expect(await page.evaluate(() => document.cookie)).toEqual('password=123456');
});
it('should isolate cookies in browser contexts', async({context, server, browser}) => {
const anotherContext = await browser.createIncognitoBrowserContext();
const anotherContext = await browser.newContext();
await context.setCookies([{url: server.EMPTY_PAGE, name: 'page1cookie', value: 'page1value'}]);
await anotherContext.setCookies([{url: server.EMPTY_PAGE, name: 'page2cookie', value: 'page2value'}]);
@ -365,7 +365,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
expect(await page.evaluate('document.cookie')).toBe('');
});
it('should isolate cookies when clearing', async({context, server, browser}) => {
const anotherContext = await browser.createIncognitoBrowserContext();
const anotherContext = await browser.newContext();
await context.setCookies([{url: server.EMPTY_PAGE, name: 'page1cookie', value: 'page1value'}]);
await anotherContext.setCookies([{url: server.EMPTY_PAGE, name: 'page2cookie', value: 'page2value'}]);

View File

@ -77,7 +77,7 @@ module.exports.addTests = function({testRunner, expect, WEBKIT}) {
});
it.skip(WEBKIT)('should isolate permissions between browser contexs', async({page, server, context, browser}) => {
await page.goto(server.EMPTY_PAGE);
const otherContext = await browser.createIncognitoBrowserContext();
const otherContext = await browser.newContext();
const otherPage = await otherContext.newPage();
await otherPage.goto(server.EMPTY_PAGE);
expect(await getPermission(page, 'geolocation')).toBe('prompt');

View File

@ -28,7 +28,7 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
delete state.browser;
});
beforeEach(async state => {
state.context = await state.browser.createIncognitoBrowserContext();
state.context = await state.browser.newContext();
state.page = await state.context.newPage();
});
afterEach(async state => {

View File

@ -126,7 +126,7 @@ module.exports.addTests = ({testRunner, product, playwrightPath}) => {
describe('Page', function() {
beforeEach(async state => {
state.context = await state.browser.createIncognitoBrowserContext();
state.context = await state.browser.newContext();
state.page = await state.context.newPage();
});