Skip to content

Commit 5cb19c6

Browse files
authored
test: extract common headful tests (#785)
1 parent 9a00e1d commit 5cb19c6

File tree

3 files changed

+77
-35
lines changed

3 files changed

+77
-35
lines changed

test/chromium/headful.spec.js

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports.describe = function({testRunner, expect, playwright, defaultBrows
4444
],
4545
});
4646

47-
describe('HEADFUL', function() {
47+
describe('ChromiumHeadful', function() {
4848
it('background_page target type should be available', async() => {
4949
const browserWithExtension = await playwright.launch(extensionOptions);
5050
const page = await browserWithExtension.defaultContext().newPage();
@@ -61,31 +61,6 @@ module.exports.describe = function({testRunner, expect, playwright, defaultBrows
6161
expect(await page.evaluate(() => window.MAGIC)).toBe(42);
6262
await browserWithExtension.close();
6363
});
64-
it('should have default url when launching browser', async function() {
65-
const browser = await playwright.launch(extensionOptions);
66-
const pages = (await browser.defaultContext().pages()).map(page => page.url());
67-
expect(pages).toEqual(['about:blank']);
68-
await browser.close();
69-
});
70-
// see https://github.com/microsoft/playwright/issues/717
71-
it.skip(WIN && CHROMIUM)('headless should be able to read cookies written by headful', async({server}) => {
72-
const userDataDir = await mkdtempAsync(TMP_FOLDER);
73-
// Write a cookie in headful chrome
74-
const headfulBrowser = await playwright.launch(Object.assign({userDataDir}, headfulOptions));
75-
const headfulPage = await headfulBrowser.defaultContext().newPage();
76-
await headfulPage.goto(server.EMPTY_PAGE);
77-
await headfulPage.evaluate(() => document.cookie = 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
78-
await headfulBrowser.close();
79-
// Read the cookie from headless chrome
80-
const headlessBrowser = await playwright.launch(Object.assign({userDataDir}, headlessOptions));
81-
const headlessPage = await headlessBrowser.defaultContext().newPage();
82-
await headlessPage.goto(server.EMPTY_PAGE);
83-
const cookie = await headlessPage.evaluate(() => document.cookie);
84-
await headlessBrowser.close();
85-
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
86-
await rmAsync(userDataDir).catch(e => {});
87-
expect(cookie).toBe('foo=true');
88-
});
8964
// TODO: Support OOOPIF. @see https://github.com/GoogleChrome/puppeteer/issues/2548
9065
xit('OOPIF: should report google.com frame', async({server}) => {
9166
// https://google.com is isolated by default in Chromium embedder.
@@ -108,15 +83,6 @@ module.exports.describe = function({testRunner, expect, playwright, defaultBrows
10883
]);
10984
await browser.close();
11085
});
111-
it('should close browser with beforeunload page', async({server}) => {
112-
const browser = await playwright.launch(headfulOptions);
113-
const page = await browser.defaultContext().newPage();
114-
await page.goto(server.PREFIX + '/beforeunload.html');
115-
// We have to interact with a page so that 'beforeunload' handlers
116-
// fire.
117-
await page.click('body');
118-
await browser.close();
119-
});
12086
it('should open devtools when "devtools: true" option is given', async({server}) => {
12187
const browser = await playwright.launch(Object.assign({devtools: true}, headfulOptions));
12288
const context = await browser.newContext();

test/headful.spec.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright 2018 Google Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const path = require('path');
18+
const os = require('os');
19+
const fs = require('fs');
20+
const util = require('util');
21+
22+
const rmAsync = util.promisify(require('rimraf'));
23+
const mkdtempAsync = util.promisify(fs.mkdtemp);
24+
25+
const TMP_FOLDER = path.join(os.tmpdir(), 'pw_tmp_folder-');
26+
27+
module.exports.describe = function({testRunner, expect, playwright, defaultBrowserOptions, FFOX, CHROMIUM, WEBKIT, WIN}) {
28+
const {describe, xdescribe, fdescribe} = testRunner;
29+
const {it, fit, xit, dit} = testRunner;
30+
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
31+
32+
const headfulOptions = Object.assign({}, defaultBrowserOptions, {
33+
headless: false
34+
});
35+
const headlessOptions = Object.assign({}, defaultBrowserOptions, {
36+
headless: true
37+
});
38+
39+
describe('Headful', function() {
40+
it('should have default url when launching browser', async function() {
41+
const browser = await playwright.launch(headfulOptions);
42+
const pages = (await browser.defaultContext().pages()).map(page => page.url());
43+
expect(pages).toEqual(['about:blank']);
44+
await browser.close();
45+
});
46+
// see https://github.com/microsoft/playwright/issues/717
47+
it.skip((WIN && CHROMIUM) || FFOX)('headless should be able to read cookies written by headful', async({server}) => {
48+
const userDataDir = await mkdtempAsync(TMP_FOLDER);
49+
// Write a cookie in headful chrome
50+
const headfulBrowser = await playwright.launch(Object.assign({userDataDir}, headfulOptions));
51+
const headfulPage = await headfulBrowser.defaultContext().newPage();
52+
await headfulPage.goto(server.EMPTY_PAGE);
53+
await headfulPage.evaluate(() => document.cookie = 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
54+
await headfulBrowser.close();
55+
// Read the cookie from headless chrome
56+
const headlessBrowser = await playwright.launch(Object.assign({userDataDir}, headlessOptions));
57+
const headlessPage = await headlessBrowser.defaultContext().newPage();
58+
await headlessPage.goto(server.EMPTY_PAGE);
59+
const cookie = await headlessPage.evaluate(() => document.cookie);
60+
await headlessBrowser.close();
61+
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
62+
await rmAsync(userDataDir).catch(e => {});
63+
expect(cookie).toBe('foo=true');
64+
});
65+
it.skip(FFOX)('should close browser with beforeunload page', async({server}) => {
66+
const browser = await playwright.launch(headfulOptions);
67+
const page = await browser.defaultContext().newPage();
68+
await page.goto(server.PREFIX + '/beforeunload.html');
69+
// We have to interact with a page so that 'beforeunload' handlers
70+
// fire.
71+
await page.click('body');
72+
await browser.close();
73+
});
74+
});
75+
};

test/playwright.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => {
197197
testRunner.loadTests(require('./defaultbrowsercontext.spec.js'), testOptions);
198198
testRunner.loadTests(require('./fixtures.spec.js'), testOptions);
199199
testRunner.loadTests(require('./launcher.spec.js'), testOptions);
200+
testRunner.loadTests(require('./headful.spec.js'), testOptions);
200201

201202
if (CHROMIUM) {
202203
testRunner.loadTests(require('./chromium/launcher.spec.js'), testOptions);

0 commit comments

Comments
 (0)