mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: use launch
helper (#10344)
This commit is contained in:
parent
d89072a368
commit
e3e68a99d2
@ -15,7 +15,7 @@ module.exports = {
|
|||||||
files: ['*.spec.ts'],
|
files: ['*.spec.ts'],
|
||||||
rules: {
|
rules: {
|
||||||
'no-restricted-syntax': [
|
'no-restricted-syntax': [
|
||||||
'warn',
|
'error',
|
||||||
{
|
{
|
||||||
message:
|
message:
|
||||||
'Use helper command `launch` to make sure the browsers get cleaned',
|
'Use helper command `launch` to make sure the browsers get cleaned',
|
||||||
|
@ -401,6 +401,12 @@
|
|||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["webDriverBiDi"],
|
||||||
"expectations": ["PASS"]
|
"expectations": ["PASS"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.launch should be able to launch Firefox",
|
||||||
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
"parameters": ["chrome"],
|
||||||
|
"expectations": ["SKIP"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.launch should work with no default arguments",
|
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.launch should work with no default arguments",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
@ -1145,12 +1151,6 @@
|
|||||||
"parameters": ["cdp", "firefox"],
|
"parameters": ["cdp", "firefox"],
|
||||||
"expectations": ["SKIP"]
|
"expectations": ["SKIP"]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.launch should be able to launch Firefox",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["cdp", "chrome"],
|
|
||||||
"expectations": ["FAIL"]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.launch should be able to launch Firefox",
|
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Puppeteer.launch should be able to launch Firefox",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
@ -15,46 +15,39 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
import {
|
import {CDPBrowser} from 'puppeteer-core/internal/common/Browser.js';
|
||||||
CDPBrowser,
|
|
||||||
CDPBrowserContext,
|
|
||||||
} from 'puppeteer-core/internal/common/Browser.js';
|
|
||||||
|
|
||||||
import {getTestState} from './mocha-utils'; // eslint-disable-line import/extensions
|
import {getTestState, launch} from './mocha-utils.js';
|
||||||
import {attachFrame} from './utils.js';
|
import {attachFrame} from './utils.js';
|
||||||
|
|
||||||
describe('TargetManager', () => {
|
describe('TargetManager', () => {
|
||||||
/* We use a special browser for this test as we need the --site-per-process flag */
|
/* We use a special browser for this test as we need the --site-per-process flag */
|
||||||
let browser: CDPBrowser;
|
let testState: Awaited<ReturnType<typeof launch>> & {
|
||||||
let context: CDPBrowserContext;
|
browser: CDPBrowser;
|
||||||
|
};
|
||||||
|
|
||||||
before(async () => {
|
beforeEach(async () => {
|
||||||
const {puppeteer, defaultBrowserOptions} = getTestState();
|
const {defaultBrowserOptions} = getTestState();
|
||||||
browser = (await puppeteer.launch(
|
testState = (await launch(
|
||||||
Object.assign({}, defaultBrowserOptions, {
|
Object.assign({}, defaultBrowserOptions, {
|
||||||
args: (defaultBrowserOptions.args || []).concat([
|
args: (defaultBrowserOptions.args || []).concat([
|
||||||
'--site-per-process',
|
'--site-per-process',
|
||||||
'--remote-debugging-port=21222',
|
'--remote-debugging-port=21222',
|
||||||
'--host-rules=MAP * 127.0.0.1',
|
'--host-rules=MAP * 127.0.0.1',
|
||||||
]),
|
]),
|
||||||
})
|
}),
|
||||||
)) as CDPBrowser;
|
{createPage: false}
|
||||||
});
|
)) as Awaited<ReturnType<typeof launch>> & {
|
||||||
|
browser: CDPBrowser;
|
||||||
beforeEach(async () => {
|
};
|
||||||
context = await browser.createIncognitoBrowserContext();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await context.close();
|
await testState.close();
|
||||||
});
|
|
||||||
|
|
||||||
after(async () => {
|
|
||||||
await browser.close();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle targets', async () => {
|
it('should handle targets', async () => {
|
||||||
const {server} = getTestState();
|
const {server, context, browser} = testState;
|
||||||
|
|
||||||
const targetManager = browser._targetManager();
|
const targetManager = browser._targetManager();
|
||||||
expect(targetManager.getAvailableTargets().size).toBe(2);
|
expect(targetManager.getAvailableTargets().size).toBe(2);
|
||||||
|
@ -19,6 +19,7 @@ import expect from 'expect';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
getTestState,
|
getTestState,
|
||||||
|
launch,
|
||||||
setupTestBrowserHooks,
|
setupTestBrowserHooks,
|
||||||
setupTestPageAndContextHooks,
|
setupTestPageAndContextHooks,
|
||||||
} from './mocha-utils.js';
|
} from './mocha-utils.js';
|
||||||
@ -29,111 +30,129 @@ describe('Chromium-Specific Launcher tests', function () {
|
|||||||
it('should be able to connect using browserUrl, with and without trailing slash', async () => {
|
it('should be able to connect using browserUrl, with and without trailing slash', async () => {
|
||||||
const {defaultBrowserOptions, puppeteer} = getTestState();
|
const {defaultBrowserOptions, puppeteer} = getTestState();
|
||||||
|
|
||||||
const originalBrowser = await puppeteer.launch(
|
const {close} = await launch(
|
||||||
Object.assign({}, defaultBrowserOptions, {
|
Object.assign({}, defaultBrowserOptions, {
|
||||||
args: ['--remote-debugging-port=21222'],
|
args: ['--remote-debugging-port=21222'],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const browserURL = 'http://127.0.0.1:21222';
|
try {
|
||||||
|
const browserURL = 'http://127.0.0.1:21222';
|
||||||
|
|
||||||
const browser1 = await puppeteer.connect({browserURL});
|
const browser1 = await puppeteer.connect({browserURL});
|
||||||
const page1 = await browser1.newPage();
|
const page1 = await browser1.newPage();
|
||||||
expect(
|
expect(
|
||||||
await page1.evaluate(() => {
|
await page1.evaluate(() => {
|
||||||
return 7 * 8;
|
return 7 * 8;
|
||||||
})
|
})
|
||||||
).toBe(56);
|
).toBe(56);
|
||||||
browser1.disconnect();
|
browser1.disconnect();
|
||||||
|
|
||||||
const browser2 = await puppeteer.connect({
|
const browser2 = await puppeteer.connect({
|
||||||
browserURL: browserURL + '/',
|
browserURL: browserURL + '/',
|
||||||
});
|
});
|
||||||
const page2 = await browser2.newPage();
|
const page2 = await browser2.newPage();
|
||||||
expect(
|
expect(
|
||||||
await page2.evaluate(() => {
|
await page2.evaluate(() => {
|
||||||
return 8 * 7;
|
return 8 * 7;
|
||||||
})
|
})
|
||||||
).toBe(56);
|
).toBe(56);
|
||||||
browser2.disconnect();
|
browser2.disconnect();
|
||||||
await originalBrowser.close();
|
} finally {
|
||||||
|
await close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
it('should throw when using both browserWSEndpoint and browserURL', async () => {
|
it('should throw when using both browserWSEndpoint and browserURL', async () => {
|
||||||
const {defaultBrowserOptions, puppeteer} = getTestState();
|
const {defaultBrowserOptions, puppeteer} = getTestState();
|
||||||
|
|
||||||
const originalBrowser = await puppeteer.launch(
|
const {browser, close} = await launch(
|
||||||
Object.assign({}, defaultBrowserOptions, {
|
Object.assign({}, defaultBrowserOptions, {
|
||||||
args: ['--remote-debugging-port=21222'],
|
args: ['--remote-debugging-port=21222'],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const browserURL = 'http://127.0.0.1:21222';
|
try {
|
||||||
|
const browserURL = 'http://127.0.0.1:21222';
|
||||||
|
|
||||||
let error!: Error;
|
let error!: Error;
|
||||||
await puppeteer
|
await puppeteer
|
||||||
.connect({
|
.connect({
|
||||||
browserURL,
|
browserURL,
|
||||||
browserWSEndpoint: originalBrowser.wsEndpoint(),
|
browserWSEndpoint: browser.wsEndpoint(),
|
||||||
})
|
})
|
||||||
.catch(error_ => {
|
.catch(error_ => {
|
||||||
return (error = error_);
|
return (error = error_);
|
||||||
});
|
});
|
||||||
expect(error.message).toContain(
|
expect(error.message).toContain(
|
||||||
'Exactly one of browserWSEndpoint, browserURL or transport'
|
'Exactly one of browserWSEndpoint, browserURL or transport'
|
||||||
);
|
);
|
||||||
|
} finally {
|
||||||
await originalBrowser.close();
|
await close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
it('should throw when trying to connect to non-existing browser', async () => {
|
it('should throw when trying to connect to non-existing browser', async () => {
|
||||||
const {defaultBrowserOptions, puppeteer} = getTestState();
|
const {defaultBrowserOptions, puppeteer} = getTestState();
|
||||||
|
|
||||||
const originalBrowser = await puppeteer.launch(
|
const {close} = await launch(
|
||||||
Object.assign({}, defaultBrowserOptions, {
|
Object.assign({}, defaultBrowserOptions, {
|
||||||
args: ['--remote-debugging-port=21222'],
|
args: ['--remote-debugging-port=21222'],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const browserURL = 'http://127.0.0.1:32333';
|
try {
|
||||||
|
const browserURL = 'http://127.0.0.1:32333';
|
||||||
|
|
||||||
let error!: Error;
|
let error!: Error;
|
||||||
await puppeteer.connect({browserURL}).catch(error_ => {
|
await puppeteer.connect({browserURL}).catch(error_ => {
|
||||||
return (error = error_);
|
return (error = error_);
|
||||||
});
|
});
|
||||||
expect(error.message).toContain(
|
expect(error.message).toContain(
|
||||||
'Failed to fetch browser webSocket URL from'
|
'Failed to fetch browser webSocket URL from'
|
||||||
);
|
);
|
||||||
await originalBrowser.close();
|
} finally {
|
||||||
|
await close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Puppeteer.launch |pipe| option', function () {
|
describe('Puppeteer.launch |pipe| option', function () {
|
||||||
it('should support the pipe option', async () => {
|
it('should support the pipe option', async () => {
|
||||||
const {defaultBrowserOptions, puppeteer} = getTestState();
|
const {defaultBrowserOptions} = getTestState();
|
||||||
const options = Object.assign({pipe: true}, defaultBrowserOptions);
|
const options = Object.assign({pipe: true}, defaultBrowserOptions);
|
||||||
const browser = await puppeteer.launch(options);
|
const {browser, close} = await launch(options, {createPage: false});
|
||||||
expect(await browser.pages()).toHaveLength(1);
|
try {
|
||||||
expect(browser.wsEndpoint()).toBe('');
|
expect(await browser.pages()).toHaveLength(1);
|
||||||
const page = await browser.newPage();
|
expect(browser.wsEndpoint()).toBe('');
|
||||||
expect(await page.evaluate('11 * 11')).toBe(121);
|
const page = await browser.newPage();
|
||||||
await page.close();
|
expect(await page.evaluate('11 * 11')).toBe(121);
|
||||||
await browser.close();
|
await page.close();
|
||||||
|
} finally {
|
||||||
|
await close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
it('should support the pipe argument', async () => {
|
it('should support the pipe argument', async () => {
|
||||||
const {defaultBrowserOptions, puppeteer} = getTestState();
|
const {defaultBrowserOptions} = getTestState();
|
||||||
const options = Object.assign({}, defaultBrowserOptions);
|
const options = Object.assign({}, defaultBrowserOptions);
|
||||||
options.args = ['--remote-debugging-pipe'].concat(options.args || []);
|
options.args = ['--remote-debugging-pipe'].concat(options.args || []);
|
||||||
const browser = await puppeteer.launch(options);
|
const {browser, close} = await launch(options);
|
||||||
expect(browser.wsEndpoint()).toBe('');
|
try {
|
||||||
const page = await browser.newPage();
|
expect(browser.wsEndpoint()).toBe('');
|
||||||
expect(await page.evaluate('11 * 11')).toBe(121);
|
const page = await browser.newPage();
|
||||||
await page.close();
|
expect(await page.evaluate('11 * 11')).toBe(121);
|
||||||
await browser.close();
|
await page.close();
|
||||||
|
} finally {
|
||||||
|
await close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
it('should fire "disconnected" when closing with pipe', async () => {
|
it('should fire "disconnected" when closing with pipe', async () => {
|
||||||
const {defaultBrowserOptions, puppeteer} = getTestState();
|
const {defaultBrowserOptions} = getTestState();
|
||||||
const options = Object.assign({pipe: true}, defaultBrowserOptions);
|
const options = Object.assign({pipe: true}, defaultBrowserOptions);
|
||||||
const browser = await puppeteer.launch(options);
|
const {browser, close} = await launch(options);
|
||||||
const disconnectedEventPromise = waitEvent(browser, 'disconnected');
|
try {
|
||||||
// Emulate user exiting browser.
|
const disconnectedEventPromise = waitEvent(browser, 'disconnected');
|
||||||
browser.process()!.kill();
|
// Emulate user exiting browser.
|
||||||
await disconnectedEventPromise;
|
browser.process()!.kill();
|
||||||
|
await disconnectedEventPromise;
|
||||||
|
} finally {
|
||||||
|
await close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -20,6 +20,7 @@ import {
|
|||||||
getTestState,
|
getTestState,
|
||||||
setupTestBrowserHooks,
|
setupTestBrowserHooks,
|
||||||
setupTestPageAndContextHooks,
|
setupTestPageAndContextHooks,
|
||||||
|
launch,
|
||||||
} from './mocha-utils.js';
|
} from './mocha-utils.js';
|
||||||
|
|
||||||
describe('Cookie specs', () => {
|
describe('Cookie specs', () => {
|
||||||
@ -480,16 +481,15 @@ describe('Cookie specs', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
it('should set secure same-site cookies from a frame', async () => {
|
it('should set secure same-site cookies from a frame', async () => {
|
||||||
const {httpsServer, puppeteer, defaultBrowserOptions} = getTestState();
|
const {httpsServer, defaultBrowserOptions} = getTestState();
|
||||||
|
|
||||||
const browser = await puppeteer.launch({
|
const {browser, close} = await launch({
|
||||||
...defaultBrowserOptions,
|
...defaultBrowserOptions,
|
||||||
ignoreHTTPSErrors: true,
|
ignoreHTTPSErrors: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const page = await browser.newPage();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const page = await browser.newPage();
|
||||||
await page.goto(httpsServer.PREFIX + '/grid.html');
|
await page.goto(httpsServer.PREFIX + '/grid.html');
|
||||||
await page.evaluate(src => {
|
await page.evaluate(src => {
|
||||||
let fulfill!: () => void;
|
let fulfill!: () => void;
|
||||||
@ -533,8 +533,7 @@ describe('Cookie specs', () => {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
await page.close();
|
await close();
|
||||||
await browser.close();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -19,13 +19,10 @@ import os from 'os';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
import {
|
import {PuppeteerLaunchOptions} from 'puppeteer-core/internal/node/PuppeteerNode.js';
|
||||||
PuppeteerLaunchOptions,
|
|
||||||
PuppeteerNode,
|
|
||||||
} from 'puppeteer-core/internal/node/PuppeteerNode.js';
|
|
||||||
import {rmSync} from 'puppeteer-core/internal/node/util/fs.js';
|
import {rmSync} from 'puppeteer-core/internal/node/util/fs.js';
|
||||||
|
|
||||||
import {getTestState} from './mocha-utils.js';
|
import {getTestState, launch} from './mocha-utils.js';
|
||||||
|
|
||||||
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
||||||
|
|
||||||
@ -59,7 +56,7 @@ describe('headful tests', function () {
|
|||||||
headless: boolean;
|
headless: boolean;
|
||||||
devtools: boolean;
|
devtools: boolean;
|
||||||
};
|
};
|
||||||
const browsers: any[] = [];
|
const browsers: Array<() => Promise<void>> = [];
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const {server, defaultBrowserOptions} = getTestState();
|
const {server, defaultBrowserOptions} = getTestState();
|
||||||
@ -96,29 +93,24 @@ describe('headful tests', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
async function launchBrowser(puppeteer: PuppeteerNode, options: any) {
|
async function launchBrowser(options: any) {
|
||||||
const browser = await puppeteer.launch(options);
|
const {browser, close} = await launch(options, {createContext: false});
|
||||||
browsers.push(browser);
|
browsers.push(close);
|
||||||
return browser;
|
return browser;
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(async () => {
|
||||||
for (const i in browsers) {
|
await Promise.all(
|
||||||
const browser = browsers[i];
|
browsers.map((close, index) => {
|
||||||
if (browser.isConnected()) {
|
delete browsers[index];
|
||||||
browser.close();
|
return close();
|
||||||
}
|
})
|
||||||
delete browsers[i];
|
);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('HEADFUL', function () {
|
describe('HEADFUL', function () {
|
||||||
it('background_page target type should be available', async () => {
|
it('background_page target type should be available', async () => {
|
||||||
const {puppeteer} = getTestState();
|
const browserWithExtension = await launchBrowser(extensionOptions);
|
||||||
const browserWithExtension = await launchBrowser(
|
|
||||||
puppeteer,
|
|
||||||
extensionOptions
|
|
||||||
);
|
|
||||||
const page = await browserWithExtension.newPage();
|
const page = await browserWithExtension.newPage();
|
||||||
const backgroundPageTarget = await browserWithExtension.waitForTarget(
|
const backgroundPageTarget = await browserWithExtension.waitForTarget(
|
||||||
target => {
|
target => {
|
||||||
@ -130,8 +122,8 @@ describe('headful tests', function () {
|
|||||||
expect(backgroundPageTarget).toBeTruthy();
|
expect(backgroundPageTarget).toBeTruthy();
|
||||||
});
|
});
|
||||||
it('service_worker target type should be available', async () => {
|
it('service_worker target type should be available', async () => {
|
||||||
const {puppeteer, defaultBrowserOptions} = getTestState();
|
const {defaultBrowserOptions} = getTestState();
|
||||||
const browserWithExtension = await launchBrowser(puppeteer, {
|
const browserWithExtension = await launchBrowser({
|
||||||
...defaultBrowserOptions,
|
...defaultBrowserOptions,
|
||||||
headless: false,
|
headless: false,
|
||||||
args: [
|
args: [
|
||||||
@ -150,11 +142,7 @@ describe('headful tests', function () {
|
|||||||
expect(serviceWorkerTarget).toBeTruthy();
|
expect(serviceWorkerTarget).toBeTruthy();
|
||||||
});
|
});
|
||||||
it('target.page() should return a background_page', async function () {
|
it('target.page() should return a background_page', async function () {
|
||||||
const {puppeteer} = getTestState();
|
const browserWithExtension = await launchBrowser(extensionOptions);
|
||||||
const browserWithExtension = await launchBrowser(
|
|
||||||
puppeteer,
|
|
||||||
extensionOptions
|
|
||||||
);
|
|
||||||
const backgroundPageTarget = await browserWithExtension.waitForTarget(
|
const backgroundPageTarget = await browserWithExtension.waitForTarget(
|
||||||
target => {
|
target => {
|
||||||
return target.type() === 'background_page';
|
return target.type() === 'background_page';
|
||||||
@ -175,7 +163,7 @@ describe('headful tests', function () {
|
|||||||
});
|
});
|
||||||
it('target.page() should return a DevTools page if custom isPageTarget is provided', async function () {
|
it('target.page() should return a DevTools page if custom isPageTarget is provided', async function () {
|
||||||
const {puppeteer} = getTestState();
|
const {puppeteer} = getTestState();
|
||||||
const originalBrowser = await launchBrowser(puppeteer, devtoolsOptions);
|
const originalBrowser = await launchBrowser(devtoolsOptions);
|
||||||
|
|
||||||
const browserWSEndpoint = originalBrowser.wsEndpoint();
|
const browserWSEndpoint = originalBrowser.wsEndpoint();
|
||||||
|
|
||||||
@ -197,25 +185,21 @@ describe('headful tests', function () {
|
|||||||
})
|
})
|
||||||
).toBe(6);
|
).toBe(6);
|
||||||
expect(await browser.pages()).toContainEqual(page);
|
expect(await browser.pages()).toContainEqual(page);
|
||||||
await browser.close();
|
|
||||||
});
|
});
|
||||||
it('should have default url when launching browser', async function () {
|
it('should have default url when launching browser', async function () {
|
||||||
const {puppeteer} = getTestState();
|
const browser = await launchBrowser(extensionOptions);
|
||||||
const browser = await launchBrowser(puppeteer, extensionOptions);
|
|
||||||
const pages = (await browser.pages()).map((page: {url: () => any}) => {
|
const pages = (await browser.pages()).map((page: {url: () => any}) => {
|
||||||
return page.url();
|
return page.url();
|
||||||
});
|
});
|
||||||
expect(pages).toEqual(['about:blank']);
|
expect(pages).toEqual(['about:blank']);
|
||||||
await browser.close();
|
|
||||||
});
|
});
|
||||||
it('headless should be able to read cookies written by headful', async () => {
|
it('headless should be able to read cookies written by headful', async () => {
|
||||||
/* Needs investigation into why but this fails consistently on Windows CI. */
|
/* Needs investigation into why but this fails consistently on Windows CI. */
|
||||||
const {server, puppeteer} = getTestState();
|
const {server} = getTestState();
|
||||||
|
|
||||||
const userDataDir = await mkdtemp(TMP_FOLDER);
|
const userDataDir = await mkdtemp(TMP_FOLDER);
|
||||||
// Write a cookie in headful chrome
|
// Write a cookie in headful chrome
|
||||||
const headfulBrowser = await launchBrowser(
|
const headfulBrowser = await launchBrowser(
|
||||||
puppeteer,
|
|
||||||
Object.assign({userDataDir}, headfulOptions)
|
Object.assign({userDataDir}, headfulOptions)
|
||||||
);
|
);
|
||||||
const headfulPage = await headfulBrowser.newPage();
|
const headfulPage = await headfulBrowser.newPage();
|
||||||
@ -227,7 +211,6 @@ describe('headful tests', function () {
|
|||||||
await headfulBrowser.close();
|
await headfulBrowser.close();
|
||||||
// Read the cookie from headless chrome
|
// Read the cookie from headless chrome
|
||||||
const headlessBrowser = await launchBrowser(
|
const headlessBrowser = await launchBrowser(
|
||||||
puppeteer,
|
|
||||||
Object.assign({userDataDir}, headlessOptions)
|
Object.assign({userDataDir}, headlessOptions)
|
||||||
);
|
);
|
||||||
const headlessPage = await headlessBrowser.newPage();
|
const headlessPage = await headlessBrowser.newPage();
|
||||||
@ -244,10 +227,10 @@ describe('headful tests', function () {
|
|||||||
});
|
});
|
||||||
// TODO: Support OOOPIF. @see https://github.com/puppeteer/puppeteer/issues/2548
|
// TODO: Support OOOPIF. @see https://github.com/puppeteer/puppeteer/issues/2548
|
||||||
it.skip('OOPIF: should report google.com frame', async () => {
|
it.skip('OOPIF: should report google.com frame', async () => {
|
||||||
const {server, puppeteer} = getTestState();
|
const {server} = getTestState();
|
||||||
|
|
||||||
// https://google.com is isolated by default in Chromium embedder.
|
// https://google.com is isolated by default in Chromium embedder.
|
||||||
const browser = await launchBrowser(puppeteer, headfulOptions);
|
const browser = await launchBrowser(headfulOptions);
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
await page.setRequestInterception(true);
|
await page.setRequestInterception(true);
|
||||||
@ -270,12 +253,11 @@ describe('headful tests', function () {
|
|||||||
})
|
})
|
||||||
.sort();
|
.sort();
|
||||||
expect(urls).toEqual([server.EMPTY_PAGE, 'https://google.com/']);
|
expect(urls).toEqual([server.EMPTY_PAGE, 'https://google.com/']);
|
||||||
await browser.close();
|
|
||||||
});
|
});
|
||||||
it('OOPIF: should expose events within OOPIFs', async () => {
|
it('OOPIF: should expose events within OOPIFs', async () => {
|
||||||
const {server, puppeteer} = getTestState();
|
const {server} = getTestState();
|
||||||
|
|
||||||
const browser = await launchBrowser(puppeteer, forcedOopifOptions);
|
const browser = await launchBrowser(forcedOopifOptions);
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
|
|
||||||
// Setup our session listeners to observe OOPIF activity.
|
// Setup our session listeners to observe OOPIF activity.
|
||||||
@ -333,9 +315,9 @@ describe('headful tests', function () {
|
|||||||
expect(requests).toContain(`http://oopifdomain:${server.PORT}/fetch`);
|
expect(requests).toContain(`http://oopifdomain:${server.PORT}/fetch`);
|
||||||
});
|
});
|
||||||
it('should close browser with beforeunload page', async () => {
|
it('should close browser with beforeunload page', async () => {
|
||||||
const {server, puppeteer} = getTestState();
|
const {server} = getTestState();
|
||||||
|
|
||||||
const browser = await launchBrowser(puppeteer, headfulOptions);
|
const browser = await launchBrowser(headfulOptions);
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto(server.PREFIX + '/beforeunload.html');
|
await page.goto(server.PREFIX + '/beforeunload.html');
|
||||||
// We have to interact with a page so that 'beforeunload' handlers
|
// We have to interact with a page so that 'beforeunload' handlers
|
||||||
@ -344,10 +326,7 @@ describe('headful tests', function () {
|
|||||||
await browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
it('should open devtools when "devtools: true" option is given', async () => {
|
it('should open devtools when "devtools: true" option is given', async () => {
|
||||||
const {puppeteer} = getTestState();
|
|
||||||
|
|
||||||
const browser = await launchBrowser(
|
const browser = await launchBrowser(
|
||||||
puppeteer,
|
|
||||||
Object.assign({devtools: true}, headfulOptions)
|
Object.assign({devtools: true}, headfulOptions)
|
||||||
);
|
);
|
||||||
const context = await browser.createIncognitoBrowserContext();
|
const context = await browser.createIncognitoBrowserContext();
|
||||||
@ -363,8 +342,7 @@ describe('headful tests', function () {
|
|||||||
|
|
||||||
describe('Page.bringToFront', function () {
|
describe('Page.bringToFront', function () {
|
||||||
it('should work', async () => {
|
it('should work', async () => {
|
||||||
const {puppeteer} = getTestState();
|
const browser = await launchBrowser(headfulOptions);
|
||||||
const browser = await launchBrowser(puppeteer, headfulOptions);
|
|
||||||
const page1 = await browser.newPage();
|
const page1 = await browser.newPage();
|
||||||
const page2 = await browser.newPage();
|
const page2 = await browser.newPage();
|
||||||
|
|
||||||
@ -400,8 +378,8 @@ describe('headful tests', function () {
|
|||||||
|
|
||||||
describe('Page.screenshot', function () {
|
describe('Page.screenshot', function () {
|
||||||
it('should run in parallel in multiple pages', async () => {
|
it('should run in parallel in multiple pages', async () => {
|
||||||
const {server, puppeteer} = getTestState();
|
const {server} = getTestState();
|
||||||
const browser = await puppeteer.launch(headfulOptions);
|
const browser = await launchBrowser(headfulOptions);
|
||||||
const context = await browser.createIncognitoBrowserContext();
|
const context = await browser.createIncognitoBrowserContext();
|
||||||
|
|
||||||
const N = 2;
|
const N = 2;
|
||||||
|
@ -39,6 +39,7 @@ describe('ignoreHTTPSErrors', function () {
|
|||||||
{ignoreHTTPSErrors: true},
|
{ignoreHTTPSErrors: true},
|
||||||
defaultBrowserOptions
|
defaultBrowserOptions
|
||||||
);
|
);
|
||||||
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
browser = await puppeteer.launch(options);
|
browser = await puppeteer.launch(options);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -364,47 +364,69 @@ export const createTimeout = <T>(
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const browserCleanups: Array<() => Promise<void>> = [];
|
let browserCleanups: Array<() => Promise<void>> = [];
|
||||||
|
|
||||||
export const launch = async (
|
export const launch = async (
|
||||||
options: PuppeteerLaunchOptions
|
launchOptions: PuppeteerLaunchOptions,
|
||||||
|
options: {
|
||||||
|
createContext?: boolean;
|
||||||
|
createPage?: boolean;
|
||||||
|
} = {}
|
||||||
): Promise<
|
): Promise<
|
||||||
PuppeteerTestState & {
|
PuppeteerTestState & {
|
||||||
close: () => Promise<void>;
|
close: () => Promise<void>;
|
||||||
}
|
}
|
||||||
> => {
|
> => {
|
||||||
|
const {createContext = true, createPage = true} = options;
|
||||||
const close = async () => {
|
const close = async () => {
|
||||||
let cleanup = browserCleanups.pop();
|
let cleanup = browserCleanups.pop();
|
||||||
while (cleanup) {
|
try {
|
||||||
await cleanup();
|
while (cleanup) {
|
||||||
cleanup = browserCleanups.pop();
|
await cleanup();
|
||||||
|
cleanup = browserCleanups.pop();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// If the browser was closed by other mean swallow the error
|
||||||
|
// and mark he browser as closed
|
||||||
|
if ((error as any)?.message.includes('Connection closed')) {
|
||||||
|
browserCleanups = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const browser = await puppeteer.launch({
|
const browser = await puppeteer.launch({
|
||||||
...defaultBrowserOptions,
|
...defaultBrowserOptions,
|
||||||
...options,
|
...launchOptions,
|
||||||
});
|
});
|
||||||
browserCleanups.push(() => {
|
browserCleanups.push(() => {
|
||||||
return browser.close();
|
return browser.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
const context = await browser.createIncognitoBrowserContext();
|
let context: BrowserContext;
|
||||||
browserCleanups.push(() => {
|
let page: Page;
|
||||||
return context.close();
|
if (createContext) {
|
||||||
});
|
context = await browser.createIncognitoBrowserContext();
|
||||||
|
browserCleanups.push(() => {
|
||||||
|
return context.close();
|
||||||
|
});
|
||||||
|
|
||||||
const page = await context.newPage();
|
if (createPage) {
|
||||||
browserCleanups.push(() => {
|
page = await context.newPage();
|
||||||
return page.close();
|
browserCleanups.push(() => {
|
||||||
});
|
return page.close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...getTestState(),
|
...getTestState(),
|
||||||
browser,
|
browser,
|
||||||
context,
|
context: context!,
|
||||||
page,
|
page: page!,
|
||||||
close,
|
close,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -30,6 +30,7 @@ describeWithDebugLogs('OOPIF', function () {
|
|||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const {puppeteer, defaultBrowserOptions} = getTestState();
|
const {puppeteer, defaultBrowserOptions} = getTestState();
|
||||||
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
browser = await puppeteer.launch(
|
browser = await puppeteer.launch(
|
||||||
Object.assign({}, defaultBrowserOptions, {
|
Object.assign({}, defaultBrowserOptions, {
|
||||||
args: (defaultBrowserOptions.args || []).concat([
|
args: (defaultBrowserOptions.args || []).concat([
|
||||||
|
@ -21,9 +21,8 @@ import os from 'os';
|
|||||||
|
|
||||||
import {TestServer} from '@pptr/testserver';
|
import {TestServer} from '@pptr/testserver';
|
||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
import type {Browser} from 'puppeteer-core/internal/api/Browser.js';
|
|
||||||
|
|
||||||
import {getTestState} from './mocha-utils.js';
|
import {getTestState, launch} from './mocha-utils.js';
|
||||||
|
|
||||||
let HOSTNAME = os.hostname();
|
let HOSTNAME = os.hostname();
|
||||||
|
|
||||||
@ -52,12 +51,13 @@ function getEmptyPageUrl(server: TestServer): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('request proxy', () => {
|
describe('request proxy', () => {
|
||||||
let browser: Browser;
|
|
||||||
let proxiedRequestUrls: string[];
|
let proxiedRequestUrls: string[];
|
||||||
let proxyServer: Server;
|
let proxyServer: Server;
|
||||||
let proxyServerUrl: string;
|
let proxyServerUrl: string;
|
||||||
const defaultArgs = [
|
const defaultArgs = [
|
||||||
'--disable-features=NetworkTimeServiceQuerying', // We disable this in tests so that proxy-related tests don't intercept queries from this service in headful.
|
// We disable this in tests so that proxy-related tests
|
||||||
|
// don't intercept queries from this service in headful.
|
||||||
|
'--disable-features=NetworkTimeServiceQuerying',
|
||||||
];
|
];
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -97,8 +97,6 @@ describe('request proxy', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await browser.close();
|
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
proxyServer.close(error => {
|
proxyServer.close(error => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -111,27 +109,29 @@ describe('request proxy', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should proxy requests when configured', async () => {
|
it('should proxy requests when configured', async () => {
|
||||||
const {puppeteer, defaultBrowserOptions, server} = getTestState();
|
const {defaultBrowserOptions, server} = getTestState();
|
||||||
const emptyPageUrl = getEmptyPageUrl(server);
|
const emptyPageUrl = getEmptyPageUrl(server);
|
||||||
|
|
||||||
browser = await puppeteer.launch({
|
const {browser, close} = await launch({
|
||||||
...defaultBrowserOptions,
|
...defaultBrowserOptions,
|
||||||
args: [...defaultArgs, `--proxy-server=${proxyServerUrl}`],
|
args: [...defaultArgs, `--proxy-server=${proxyServerUrl}`],
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
|
const page = await browser.newPage();
|
||||||
|
const response = (await page.goto(emptyPageUrl))!;
|
||||||
|
|
||||||
const page = await browser.newPage();
|
expect(response.ok()).toBe(true);
|
||||||
const response = (await page.goto(emptyPageUrl))!;
|
expect(proxiedRequestUrls).toEqual([emptyPageUrl]);
|
||||||
|
} finally {
|
||||||
expect(response.ok()).toBe(true);
|
await close();
|
||||||
|
}
|
||||||
expect(proxiedRequestUrls).toEqual([emptyPageUrl]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should respect proxy bypass list', async () => {
|
it('should respect proxy bypass list', async () => {
|
||||||
const {puppeteer, defaultBrowserOptions, server} = getTestState();
|
const {defaultBrowserOptions, server} = getTestState();
|
||||||
const emptyPageUrl = getEmptyPageUrl(server);
|
const emptyPageUrl = getEmptyPageUrl(server);
|
||||||
|
|
||||||
browser = await puppeteer.launch({
|
const {browser, close} = await launch({
|
||||||
...defaultBrowserOptions,
|
...defaultBrowserOptions,
|
||||||
args: [
|
args: [
|
||||||
...defaultArgs,
|
...defaultArgs,
|
||||||
@ -139,39 +139,43 @@ describe('request proxy', () => {
|
|||||||
`--proxy-bypass-list=${new URL(emptyPageUrl).host}`,
|
`--proxy-bypass-list=${new URL(emptyPageUrl).host}`,
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
|
const page = await browser.newPage();
|
||||||
|
const response = (await page.goto(emptyPageUrl))!;
|
||||||
|
|
||||||
const page = await browser.newPage();
|
expect(response.ok()).toBe(true);
|
||||||
const response = (await page.goto(emptyPageUrl))!;
|
expect(proxiedRequestUrls).toEqual([]);
|
||||||
|
} finally {
|
||||||
expect(response.ok()).toBe(true);
|
await close();
|
||||||
|
}
|
||||||
expect(proxiedRequestUrls).toEqual([]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('in incognito browser context', () => {
|
describe('in incognito browser context', () => {
|
||||||
it('should proxy requests when configured at browser level', async () => {
|
it('should proxy requests when configured at browser level', async () => {
|
||||||
const {puppeteer, defaultBrowserOptions, server} = getTestState();
|
const {defaultBrowserOptions, server} = getTestState();
|
||||||
const emptyPageUrl = getEmptyPageUrl(server);
|
const emptyPageUrl = getEmptyPageUrl(server);
|
||||||
|
|
||||||
browser = await puppeteer.launch({
|
const {browser, close} = await launch({
|
||||||
...defaultBrowserOptions,
|
...defaultBrowserOptions,
|
||||||
args: [...defaultArgs, `--proxy-server=${proxyServerUrl}`],
|
args: [...defaultArgs, `--proxy-server=${proxyServerUrl}`],
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
|
const context = await browser.createIncognitoBrowserContext();
|
||||||
|
const page = await context.newPage();
|
||||||
|
const response = (await page.goto(emptyPageUrl))!;
|
||||||
|
|
||||||
const context = await browser.createIncognitoBrowserContext();
|
expect(response.ok()).toBe(true);
|
||||||
const page = await context.newPage();
|
expect(proxiedRequestUrls).toEqual([emptyPageUrl]);
|
||||||
const response = (await page.goto(emptyPageUrl))!;
|
} finally {
|
||||||
|
await close();
|
||||||
expect(response.ok()).toBe(true);
|
}
|
||||||
|
|
||||||
expect(proxiedRequestUrls).toEqual([emptyPageUrl]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should respect proxy bypass list when configured at browser level', async () => {
|
it('should respect proxy bypass list when configured at browser level', async () => {
|
||||||
const {puppeteer, defaultBrowserOptions, server} = getTestState();
|
const {defaultBrowserOptions, server} = getTestState();
|
||||||
const emptyPageUrl = getEmptyPageUrl(server);
|
const emptyPageUrl = getEmptyPageUrl(server);
|
||||||
|
|
||||||
browser = await puppeteer.launch({
|
const {browser, close} = await launch({
|
||||||
...defaultBrowserOptions,
|
...defaultBrowserOptions,
|
||||||
args: [
|
args: [
|
||||||
...defaultArgs,
|
...defaultArgs,
|
||||||
@ -179,58 +183,64 @@ describe('request proxy', () => {
|
|||||||
`--proxy-bypass-list=${new URL(emptyPageUrl).host}`,
|
`--proxy-bypass-list=${new URL(emptyPageUrl).host}`,
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
|
const context = await browser.createIncognitoBrowserContext();
|
||||||
|
const page = await context.newPage();
|
||||||
|
const response = (await page.goto(emptyPageUrl))!;
|
||||||
|
|
||||||
const context = await browser.createIncognitoBrowserContext();
|
expect(response.ok()).toBe(true);
|
||||||
const page = await context.newPage();
|
expect(proxiedRequestUrls).toEqual([]);
|
||||||
const response = (await page.goto(emptyPageUrl))!;
|
} finally {
|
||||||
|
await close();
|
||||||
expect(response.ok()).toBe(true);
|
}
|
||||||
|
|
||||||
expect(proxiedRequestUrls).toEqual([]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See issues #7873, #7719, and #7698.
|
* See issues #7873, #7719, and #7698.
|
||||||
*/
|
*/
|
||||||
it('should proxy requests when configured at context level', async () => {
|
it('should proxy requests when configured at context level', async () => {
|
||||||
const {puppeteer, defaultBrowserOptions, server} = getTestState();
|
const {defaultBrowserOptions, server} = getTestState();
|
||||||
const emptyPageUrl = getEmptyPageUrl(server);
|
const emptyPageUrl = getEmptyPageUrl(server);
|
||||||
|
|
||||||
browser = await puppeteer.launch({
|
const {browser, close} = await launch({
|
||||||
...defaultBrowserOptions,
|
...defaultBrowserOptions,
|
||||||
args: defaultArgs,
|
args: defaultArgs,
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
|
const context = await browser.createIncognitoBrowserContext({
|
||||||
|
proxyServer: proxyServerUrl,
|
||||||
|
});
|
||||||
|
const page = await context.newPage();
|
||||||
|
const response = (await page.goto(emptyPageUrl))!;
|
||||||
|
|
||||||
const context = await browser.createIncognitoBrowserContext({
|
expect(response.ok()).toBe(true);
|
||||||
proxyServer: proxyServerUrl,
|
expect(proxiedRequestUrls).toEqual([emptyPageUrl]);
|
||||||
});
|
} finally {
|
||||||
const page = await context.newPage();
|
await close();
|
||||||
const response = (await page.goto(emptyPageUrl))!;
|
}
|
||||||
|
|
||||||
expect(response.ok()).toBe(true);
|
|
||||||
|
|
||||||
expect(proxiedRequestUrls).toEqual([emptyPageUrl]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should respect proxy bypass list when configured at context level', async () => {
|
it('should respect proxy bypass list when configured at context level', async () => {
|
||||||
const {puppeteer, defaultBrowserOptions, server} = getTestState();
|
const {defaultBrowserOptions, server} = getTestState();
|
||||||
const emptyPageUrl = getEmptyPageUrl(server);
|
const emptyPageUrl = getEmptyPageUrl(server);
|
||||||
|
|
||||||
browser = await puppeteer.launch({
|
const {browser, close} = await launch({
|
||||||
...defaultBrowserOptions,
|
...defaultBrowserOptions,
|
||||||
args: defaultArgs,
|
args: defaultArgs,
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
|
const context = await browser.createIncognitoBrowserContext({
|
||||||
|
proxyServer: proxyServerUrl,
|
||||||
|
proxyBypassList: [new URL(emptyPageUrl).host],
|
||||||
|
});
|
||||||
|
const page = await context.newPage();
|
||||||
|
const response = (await page.goto(emptyPageUrl))!;
|
||||||
|
|
||||||
const context = await browser.createIncognitoBrowserContext({
|
expect(response.ok()).toBe(true);
|
||||||
proxyServer: proxyServerUrl,
|
expect(proxiedRequestUrls).toEqual([]);
|
||||||
proxyBypassList: [new URL(emptyPageUrl).host],
|
} finally {
|
||||||
});
|
await close();
|
||||||
const page = await context.newPage();
|
}
|
||||||
const response = (await page.goto(emptyPageUrl))!;
|
|
||||||
|
|
||||||
expect(response.ok()).toBe(true);
|
|
||||||
|
|
||||||
expect(proxiedRequestUrls).toEqual([]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -20,6 +20,7 @@ import {
|
|||||||
getTestState,
|
getTestState,
|
||||||
setupTestBrowserHooks,
|
setupTestBrowserHooks,
|
||||||
setupTestPageAndContextHooks,
|
setupTestPageAndContextHooks,
|
||||||
|
launch,
|
||||||
} from './mocha-utils.js';
|
} from './mocha-utils.js';
|
||||||
|
|
||||||
describe('Screenshots', function () {
|
describe('Screenshots', function () {
|
||||||
@ -223,9 +224,9 @@ describe('Screenshots', function () {
|
|||||||
expect(screenshot).toBeGolden('screenshot-element-bounding-box.png');
|
expect(screenshot).toBeGolden('screenshot-element-bounding-box.png');
|
||||||
});
|
});
|
||||||
it('should work with a null viewport', async () => {
|
it('should work with a null viewport', async () => {
|
||||||
const {defaultBrowserOptions, puppeteer, server} = getTestState();
|
const {defaultBrowserOptions, server} = getTestState();
|
||||||
|
|
||||||
const browser = await puppeteer.launch({
|
const {browser, close} = await launch({
|
||||||
...defaultBrowserOptions,
|
...defaultBrowserOptions,
|
||||||
defaultViewport: null,
|
defaultViewport: null,
|
||||||
});
|
});
|
||||||
@ -240,7 +241,7 @@ describe('Screenshots', function () {
|
|||||||
const screenshot = await elementHandle.screenshot();
|
const screenshot = await elementHandle.screenshot();
|
||||||
expect(screenshot).toBeTruthy();
|
expect(screenshot).toBeTruthy();
|
||||||
} finally {
|
} finally {
|
||||||
await browser.close();
|
await close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
it('should take into account padding and border', async () => {
|
it('should take into account padding and border', async () => {
|
||||||
|
@ -18,35 +18,30 @@ import fs from 'fs';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
import {Browser} from 'puppeteer-core/internal/api/Browser.js';
|
|
||||||
import {Page} from 'puppeteer-core/internal/api/Page.js';
|
|
||||||
|
|
||||||
import {getTestState} from './mocha-utils.js';
|
import {getTestState, launch} from './mocha-utils.js';
|
||||||
|
|
||||||
describe('Tracing', function () {
|
describe('Tracing', function () {
|
||||||
let outputFile!: string;
|
let outputFile!: string;
|
||||||
let browser!: Browser;
|
let testState: Awaited<ReturnType<typeof launch>>;
|
||||||
let page!: Page;
|
|
||||||
|
|
||||||
/* we manually manage the browser here as we want a new browser for each
|
/* we manually manage the browser here as we want a new browser for each
|
||||||
* individual test, which isn't the default behaviour of getTestState()
|
* individual test, which isn't the default behaviour of getTestState()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const {defaultBrowserOptions, puppeteer} = getTestState();
|
const {defaultBrowserOptions} = getTestState();
|
||||||
browser = await puppeteer.launch(defaultBrowserOptions);
|
testState = await launch(defaultBrowserOptions);
|
||||||
page = await browser.newPage();
|
|
||||||
outputFile = path.join(__dirname, 'trace.json');
|
outputFile = path.join(__dirname, 'trace.json');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await browser.close();
|
await testState.close();
|
||||||
if (fs.existsSync(outputFile)) {
|
if (fs.existsSync(outputFile)) {
|
||||||
fs.unlinkSync(outputFile);
|
fs.unlinkSync(outputFile);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
it('should output a trace', async () => {
|
it('should output a trace', async () => {
|
||||||
const {server} = getTestState();
|
const {server, page} = testState;
|
||||||
|
|
||||||
await page.tracing.start({screenshots: true, path: outputFile});
|
await page.tracing.start({screenshots: true, path: outputFile});
|
||||||
await page.goto(server.PREFIX + '/grid.html');
|
await page.goto(server.PREFIX + '/grid.html');
|
||||||
@ -55,6 +50,7 @@ describe('Tracing', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should run with custom categories if provided', async () => {
|
it('should run with custom categories if provided', async () => {
|
||||||
|
const {page} = testState;
|
||||||
await page.tracing.start({
|
await page.tracing.start({
|
||||||
path: outputFile,
|
path: outputFile,
|
||||||
categories: ['-*', 'disabled-by-default-devtools.timeline.frame'],
|
categories: ['-*', 'disabled-by-default-devtools.timeline.frame'],
|
||||||
@ -77,6 +73,7 @@ describe('Tracing', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should run with default categories', async () => {
|
it('should run with default categories', async () => {
|
||||||
|
const {page} = testState;
|
||||||
await page.tracing.start({
|
await page.tracing.start({
|
||||||
path: outputFile,
|
path: outputFile,
|
||||||
});
|
});
|
||||||
@ -92,6 +89,7 @@ describe('Tracing', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('should throw if tracing on two pages', async () => {
|
it('should throw if tracing on two pages', async () => {
|
||||||
|
const {page, browser} = testState;
|
||||||
await page.tracing.start({path: outputFile});
|
await page.tracing.start({path: outputFile});
|
||||||
const newPage = await browser.newPage();
|
const newPage = await browser.newPage();
|
||||||
let error!: Error;
|
let error!: Error;
|
||||||
@ -103,7 +101,7 @@ describe('Tracing', function () {
|
|||||||
await page.tracing.stop();
|
await page.tracing.stop();
|
||||||
});
|
});
|
||||||
it('should return a buffer', async () => {
|
it('should return a buffer', async () => {
|
||||||
const {server} = getTestState();
|
const {page, server} = testState;
|
||||||
|
|
||||||
await page.tracing.start({screenshots: true, path: outputFile});
|
await page.tracing.start({screenshots: true, path: outputFile});
|
||||||
await page.goto(server.PREFIX + '/grid.html');
|
await page.goto(server.PREFIX + '/grid.html');
|
||||||
@ -112,7 +110,7 @@ describe('Tracing', function () {
|
|||||||
expect(trace.toString()).toEqual(buf.toString());
|
expect(trace.toString()).toEqual(buf.toString());
|
||||||
});
|
});
|
||||||
it('should work without options', async () => {
|
it('should work without options', async () => {
|
||||||
const {server} = getTestState();
|
const {page, server} = testState;
|
||||||
|
|
||||||
await page.tracing.start();
|
await page.tracing.start();
|
||||||
await page.goto(server.PREFIX + '/grid.html');
|
await page.goto(server.PREFIX + '/grid.html');
|
||||||
@ -121,7 +119,7 @@ describe('Tracing', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return undefined in case of Buffer error', async () => {
|
it('should return undefined in case of Buffer error', async () => {
|
||||||
const {server} = getTestState();
|
const {page, server} = testState;
|
||||||
|
|
||||||
await page.tracing.start({screenshots: true});
|
await page.tracing.start({screenshots: true});
|
||||||
await page.goto(server.PREFIX + '/grid.html');
|
await page.goto(server.PREFIX + '/grid.html');
|
||||||
@ -139,7 +137,7 @@ describe('Tracing', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should support a buffer without a path', async () => {
|
it('should support a buffer without a path', async () => {
|
||||||
const {server} = getTestState();
|
const {page, server} = testState;
|
||||||
|
|
||||||
await page.tracing.start({screenshots: true});
|
await page.tracing.start({screenshots: true});
|
||||||
await page.goto(server.PREFIX + '/grid.html');
|
await page.goto(server.PREFIX + '/grid.html');
|
||||||
@ -148,6 +146,7 @@ describe('Tracing', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should properly fail if readProtocolStream errors out', async () => {
|
it('should properly fail if readProtocolStream errors out', async () => {
|
||||||
|
const {page} = testState;
|
||||||
await page.tracing.start({path: __dirname});
|
await page.tracing.start({path: __dirname});
|
||||||
|
|
||||||
let error!: Error;
|
let error!: Error;
|
||||||
|
Loading…
Reference in New Issue
Block a user