chore: move tests around after targets extraction (#153)

This commit is contained in:
Pavel Feldman 2019-12-05 13:15:17 -08:00 committed by GitHub
parent 79d3b5dffd
commit 2d77760f01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 62 deletions

View File

@ -210,5 +210,21 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
}).catch(e => error = e);
expect(error).toBeInstanceOf(playwright.errors.TimeoutError);
});
it('should fire target events', async function({browser, server}) {
const context = await browser.createIncognitoBrowserContext();
const events = [];
browser.chromium.on('targetcreated', target => events.push('CREATED: ' + target.url()));
browser.chromium.on('targetchanged', target => events.push('CHANGED: ' + target.url()));
browser.chromium.on('targetdestroyed', target => events.push('DESTROYED: ' + target.url()));
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
await page.close();
expect(events).toEqual([
'CREATED: about:blank',
`CHANGED: ${server.EMPTY_PAGE}`,
`DESTROYED: ${server.EMPTY_PAGE}`
]);
await context.close();
});
});
};

View File

@ -16,7 +16,7 @@
const utils = require('./utils');
module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME, WEBKIT}) {
module.exports.addTests = function({testRunner, expect}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
@ -40,7 +40,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
await context.close();
expect(browser.browserContexts().length).toBe(1);
});
it.skip(WEBKIT)('should close all belonging targets once closing context', async function({browser, server}) {
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();
@ -62,28 +62,12 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
expect(popupTarget.browserContext()).toBe(context);
await context.close();
});
it.skip(WEBKIT)('should fire target events', async function({browser, server}) {
const context = await browser.createIncognitoBrowserContext();
const events = [];
browser.chromium.on('targetcreated', target => events.push('CREATED: ' + target.url()));
browser.chromium.on('targetchanged', target => events.push('CHANGED: ' + target.url()));
browser.chromium.on('targetdestroyed', target => events.push('DESTROYED: ' + target.url()));
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
await page.close();
expect(events).toEqual([
'CREATED: about:blank',
`CHANGED: ${server.EMPTY_PAGE}`,
`DESTROYED: ${server.EMPTY_PAGE}`
]);
await context.close();
});
it('should isolate localStorage and cookies', async function({browser, server}) {
// Create two incognito contexts.
const context1 = await browser.createIncognitoBrowserContext();
const context2 = await browser.createIncognitoBrowserContext();
expect(browser.chromium.targets(context1).length).toBe(0);
expect(browser.chromium.targets(context2).length).toBe(0);
expect((await context1.pages()).length).toBe(0);
expect((await context2.pages()).length).toBe(0);
// Create a page in first incognito context.
const page1 = await context1.newPage();
@ -93,8 +77,8 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
document.cookie = 'name=page1';
});
expect(browser.chromium.targets(context1).length).toBe(1);
expect(browser.chromium.targets(context2).length).toBe(0);
expect((await context1.pages()).length).toBe(1);
expect((await context2.pages()).length).toBe(0);
// Create a page in second incognito context.
const page2 = await context2.newPage();
@ -104,10 +88,10 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
document.cookie = 'name=page2';
});
expect(browser.chromium.targets(context1).length).toBe(1);
expect(browser.chromium.targets(context1)[0]).toBe(browser.chromium.pageTarget(page1));
expect(browser.chromium.targets(context2).length).toBe(1);
expect(browser.chromium.targets(context2)[0]).toBe(browser.chromium.pageTarget(page2));
expect((await context1.pages()).length).toBe(1);
expect((await context2.pages()).length).toBe(1);
expect((await context1.pages())[0]).toBe(page1);
expect((await context2.pages())[0]).toBe(page2);
// Make sure pages don't share localstorage or cookies.
expect(await page1.evaluate(() => localStorage.getItem('name'))).toBe('page1');

View File

@ -63,6 +63,41 @@ module.exports.addLauncherTests = function({testRunner, expect, defaultBrowserOp
expect(error.message).toContain('Failed to fetch browser webSocket url from');
originalBrowser.close();
});
it('userDataDir option should restore state', async({server}) => {
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({userDataDir}, defaultBrowserOptions);
const browser = await playwright.launch(options);
const page = await browser.newPage();
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => localStorage.hey = 'hello');
await browser.close();
const browser2 = await playwright.launch(options);
const page2 = await browser2.newPage();
await page2.goto(server.EMPTY_PAGE);
expect(await page2.evaluate(() => localStorage.hey)).toBe('hello');
await browser2.close();
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
await rmAsync(userDataDir).catch(e => {});
});
// This mysteriously fails on Windows on AppVeyor. See https://github.com/GoogleChrome/puppeteer/issues/4111
it('userDataDir option should restore cookies', async({server}) => {
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({userDataDir}, defaultBrowserOptions);
const browser = await playwright.launch(options);
const page = await browser.newPage();
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => document.cookie = 'doSomethingOnlyOnce=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
await browser.close();
const browser2 = await playwright.launch(options);
const page2 = await browser2.newPage();
await page2.goto(server.EMPTY_PAGE);
expect(await page2.evaluate(() => document.cookie)).toBe('doSomethingOnlyOnce=true');
await browser2.close();
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
await rmAsync(userDataDir).catch(e => {});
});
});
describe('Playwright.launch |pipe| option', function() {

View File

@ -151,41 +151,6 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
await rmAsync(userDataDir).catch(e => {});
});
it.skip(WEBKIT)('userDataDir option should restore state', async({server}) => {
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({userDataDir}, defaultBrowserOptions);
const browser = await playwright.launch(options);
const page = await browser.newPage();
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => localStorage.hey = 'hello');
await browser.close();
const browser2 = await playwright.launch(options);
const page2 = await browser2.newPage();
await page2.goto(server.EMPTY_PAGE);
expect(await page2.evaluate(() => localStorage.hey)).toBe('hello');
await browser2.close();
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
await rmAsync(userDataDir).catch(e => {});
});
// This mysteriously fails on Windows on AppVeyor. See https://github.com/GoogleChrome/puppeteer/issues/4111
xit('userDataDir option should restore cookies', async({server}) => {
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({userDataDir}, defaultBrowserOptions);
const browser = await playwright.launch(options);
const page = await browser.newPage();
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => document.cookie = 'doSomethingOnlyOnce=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
await browser.close();
const browser2 = await playwright.launch(options);
const page2 = await browser2.newPage();
await page2.goto(server.EMPTY_PAGE);
expect(await page2.evaluate(() => document.cookie)).toBe('doSomethingOnlyOnce=true');
await browser2.close();
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
await rmAsync(userDataDir).catch(e => {});
});
it('should return the default arguments', async() => {
if (CHROME) {
expect(playwright.defaultArgs()).toContain('--no-first-run');

View File

@ -1145,7 +1145,7 @@ module.exports.addTests = function({testRunner, expect, headless, playwright, FF
// convert target destroy events into close.
describe('Page.Events.Close', function() {
it.skip(WEBKIT)('should work with window.close', async function({ browser, page, context, server }) {
const newPagePromise = new Promise(fulfill => browser.chromium.once('targetcreated', target => fulfill(target.page())));
const newPagePromise = new Promise(f => page.once('popup', f));
await page.evaluate(() => window['newPage'] = window.open('about:blank'));
const newPage = await newPagePromise;
const closedPromise = new Promise(x => newPage.on('close', x));