fix: tests failing in headful (#8273)

* fix: test failing in headful

* fix: install Firefox for headful tests

* fix: skip favicon.ico requests in test

* fix: auth test in headful

* fix: disable NetworkTimeServiceQuerying

* fix: filter more favicon requests

* fix: network test with favicon

* fix: improve fixes
This commit is contained in:
Alex Rudenko 2022-05-02 11:37:21 +02:00 committed by GitHub
parent e09287f4e9
commit e841d7f9f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 49 additions and 14 deletions

View File

@ -204,8 +204,11 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: | run: |
sudo apt-get install xvfb sudo apt-get install xvfb
# Ensure both a Chromium and a Firefox binary are available.
PUPPETEER_PRODUCT=firefox npm install
npm install npm install
ls .local-chromium ls .local-chromium .local-firefox
- name: Build - name: Build
run: | run: |
npm run build npm run build

View File

@ -203,6 +203,7 @@ class ChromeLauncher implements ProductLauncher {
defaultArgs(options: BrowserLaunchArgumentOptions = {}): string[] { defaultArgs(options: BrowserLaunchArgumentOptions = {}): string[] {
const chromeArguments = [ const chromeArguments = [
'--allow-pre-commit-input', // TODO(crbug.com/1320996): neither headful nor headless should rely on this flag.
'--disable-background-networking', '--disable-background-networking',
'--enable-features=NetworkService,NetworkServiceInProcess', '--enable-features=NetworkService,NetworkServiceInProcess',
'--disable-background-timer-throttling', '--disable-background-timer-throttling',

View File

@ -548,12 +548,12 @@ describe('Launcher specs', function () {
async () => { async () => {
const { defaultBrowserOptions, puppeteer } = getTestState(); const { defaultBrowserOptions, puppeteer } = getTestState();
const options = { const options = {
args: ['--no-startup-window'],
waitForInitialPage: false, waitForInitialPage: false,
// This is needed to prevent Puppeteer from adding an initial blank page. // This is needed to prevent Puppeteer from adding an initial blank page.
// See also https://github.com/puppeteer/puppeteer/blob/ad6b736039436fcc5c0a262e5b575aa041427be3/src/node/Launcher.ts#L200 // See also https://github.com/puppeteer/puppeteer/blob/ad6b736039436fcc5c0a262e5b575aa041427be3/src/node/Launcher.ts#L200
ignoreDefaultArgs: true, ignoreDefaultArgs: true,
...defaultBrowserOptions, ...defaultBrowserOptions,
args: ['--no-startup-window'],
}; };
const browser = await puppeteer.launch(options); const browser = await puppeteer.launch(options);
const pages = await browser.pages(); const pages = await browser.pages();

View File

@ -227,7 +227,10 @@ describe('network', function () {
const { page, server } = getTestState(); const { page, server } = getTestState();
const responses = new Map(); const responses = new Map();
page.on('response', (r) => responses.set(r.url().split('/').pop(), r)); page.on(
'response',
(r) => !utils.isFavicon(r) && responses.set(r.url().split('/').pop(), r)
);
// Load and re-load to make sure serviceworker is installed and running. // Load and re-load to make sure serviceworker is installed and running.
await page.goto(server.PREFIX + '/serviceworkers/fetch/sw.html', { await page.goto(server.PREFIX + '/serviceworkers/fetch/sw.html', {
@ -251,7 +254,9 @@ describe('network', function () {
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
server.setRoute('/post', (req, res) => res.end()); server.setRoute('/post', (req, res) => res.end());
let request = null; let request = null;
page.on('request', (r) => (request = r)); page.on('request', (r) => {
if (!utils.isFavicon(r)) request = r;
});
await page.evaluate(() => await page.evaluate(() =>
fetch('./post', { fetch('./post', {
method: 'POST', method: 'POST',
@ -652,8 +657,16 @@ describe('network', function () {
const { page, server } = getTestState(); const { page, server } = getTestState();
server.setAuth('/empty.html', 'user', 'pass'); server.setAuth('/empty.html', 'user', 'pass');
let response = await page.goto(server.EMPTY_PAGE); let response;
expect(response.status()).toBe(401); try {
response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
} catch (error) {
// In headful, an error is thrown instead of 401.
if (!error.message.startsWith('net::ERR_INVALID_AUTH_CREDENTIALS')) {
throw error;
}
}
await page.authenticate({ await page.authenticate({
username: 'user', username: 'user',
password: 'pass', password: 'pass',
@ -686,8 +699,15 @@ describe('network', function () {
expect(response.status()).toBe(200); expect(response.status()).toBe(200);
await page.authenticate(null); await page.authenticate(null);
// Navigate to a different origin to bust Chrome's credential caching. // Navigate to a different origin to bust Chrome's credential caching.
response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html'); try {
expect(response.status()).toBe(401); response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
expect(response.status()).toBe(401);
} catch (error) {
// In headful, an error is thrown instead of 401.
if (!error.message.startsWith('net::ERR_INVALID_AUTH_CREDENTIALS')) {
throw error;
}
}
}); });
it('should not disable caching', async () => { it('should not disable caching', async () => {
const { page, server } = getTestState(); const { page, server } = getTestState();

View File

@ -43,6 +43,9 @@ describeFailsFirefox('request proxy', () => {
let proxiedRequestUrls: string[]; let proxiedRequestUrls: string[];
let proxyServer: Server; let proxyServer: Server;
let proxyServerUrl: string; let proxyServerUrl: string;
const defaultArgs = [
'--disable-features=NetworkTimeServiceQuerying', // We disable this in tests so that proxy-related tests don't intercept queries from this service in headful.
];
beforeEach(() => { beforeEach(() => {
proxiedRequestUrls = []; proxiedRequestUrls = [];
@ -100,7 +103,7 @@ describeFailsFirefox('request proxy', () => {
browser = await puppeteer.launch({ browser = await puppeteer.launch({
...defaultBrowserOptions, ...defaultBrowserOptions,
args: [`--proxy-server=${proxyServerUrl}`], args: [...defaultArgs, `--proxy-server=${proxyServerUrl}`],
}); });
const page = await browser.newPage(); const page = await browser.newPage();
@ -118,6 +121,7 @@ describeFailsFirefox('request proxy', () => {
browser = await puppeteer.launch({ browser = await puppeteer.launch({
...defaultBrowserOptions, ...defaultBrowserOptions,
args: [ args: [
...defaultArgs,
`--proxy-server=${proxyServerUrl}`, `--proxy-server=${proxyServerUrl}`,
`--proxy-bypass-list=${new URL(emptyPageUrl).host}`, `--proxy-bypass-list=${new URL(emptyPageUrl).host}`,
], ],
@ -138,7 +142,7 @@ describeFailsFirefox('request proxy', () => {
browser = await puppeteer.launch({ browser = await puppeteer.launch({
...defaultBrowserOptions, ...defaultBrowserOptions,
args: [`--proxy-server=${proxyServerUrl}`], args: [...defaultArgs, `--proxy-server=${proxyServerUrl}`],
}); });
const context = await browser.createIncognitoBrowserContext(); const context = await browser.createIncognitoBrowserContext();
@ -157,6 +161,7 @@ describeFailsFirefox('request proxy', () => {
browser = await puppeteer.launch({ browser = await puppeteer.launch({
...defaultBrowserOptions, ...defaultBrowserOptions,
args: [ args: [
...defaultArgs,
`--proxy-server=${proxyServerUrl}`, `--proxy-server=${proxyServerUrl}`,
`--proxy-bypass-list=${new URL(emptyPageUrl).host}`, `--proxy-bypass-list=${new URL(emptyPageUrl).host}`,
], ],
@ -180,7 +185,10 @@ describeFailsFirefox('request proxy', () => {
const { puppeteer, defaultBrowserOptions, server } = getTestState(); const { puppeteer, defaultBrowserOptions, server } = getTestState();
const emptyPageUrl = getEmptyPageUrl(server); const emptyPageUrl = getEmptyPageUrl(server);
browser = await puppeteer.launch(defaultBrowserOptions); browser = await puppeteer.launch({
...defaultBrowserOptions,
args: defaultArgs,
});
const context = await browser.createIncognitoBrowserContext({ const context = await browser.createIncognitoBrowserContext({
proxyServer: proxyServerUrl, proxyServer: proxyServerUrl,
@ -198,7 +206,10 @@ describeFailsFirefox('request proxy', () => {
const { puppeteer, defaultBrowserOptions, server } = getTestState(); const { puppeteer, defaultBrowserOptions, server } = getTestState();
const emptyPageUrl = getEmptyPageUrl(server); const emptyPageUrl = getEmptyPageUrl(server);
browser = await puppeteer.launch(defaultBrowserOptions); browser = await puppeteer.launch({
...defaultBrowserOptions,
args: defaultArgs,
});
const context = await browser.createIncognitoBrowserContext({ const context = await browser.createIncognitoBrowserContext({
proxyServer: proxyServerUrl, proxyServer: proxyServerUrl,

View File

@ -458,7 +458,7 @@ describe('request interception', function () {
await page.setRequestInterception(true); await page.setRequestInterception(true);
const requests = []; const requests = [];
page.on('request', (request) => { page.on('request', (request) => {
requests.push(request); !utils.isFavicon(request) && requests.push(request);
request.continue({}, 0); request.continue({}, 0);
}); });
const dataURL = 'data:text/html,<div>yo</div>'; const dataURL = 'data:text/html,<div>yo</div>';

View File

@ -381,7 +381,7 @@ describe('request interception', function () {
await page.setRequestInterception(true); await page.setRequestInterception(true);
const requests = []; const requests = [];
page.on('request', (request) => { page.on('request', (request) => {
requests.push(request); !utils.isFavicon(request) && requests.push(request);
request.continue(); request.continue();
}); });
const dataURL = 'data:text/html,<div>yo</div>'; const dataURL = 'data:text/html,<div>yo</div>';