Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test: make debugp collect IO (#1485)
Pavel Feldmanb1bebdad2e22
diff --git a/src/chromium/crConnection.ts b/src/chromium/crConnection.tsindex 4100e0f256..43d1843031 100644--- a/src/chromium/crConnection.ts+++ b/src/chromium/crConnection.ts@@ -44,6 +44,7 @@ export class CRConnection extends platform.EventEmitter {this.rootSession = new CRSession(this, '', 'browser', '');this._sessions.set('', this.rootSession);this._debugProtocol = platform.debug('pw:protocol');+ (this._debugProtocol as any).color = '34';}static fromSession(session: CRSession): CRConnection {diff --git a/src/firefox/ffConnection.ts b/src/firefox/ffConnection.tsindex 120ab8efb4..006d33155c 100644--- a/src/firefox/ffConnection.ts+++ b/src/firefox/ffConnection.ts@@ -58,6 +58,7 @@ export class FFConnection extends platform.EventEmitter {this.off = super.removeListener;this.removeListener = super.removeListener;this.once = super.once;+ (this._debugProtocol as any).color = '34';}async send<T extends keyof Protocol.CommandParameters>(diff --git a/src/server/processLauncher.ts b/src/server/processLauncher.tsindex 3b0be1b920..4d639a3491 100644--- a/src/server/processLauncher.ts+++ b/src/server/processLauncher.ts@@ -24,6 +24,10 @@ import { TimeoutError } from '../errors';import * as platform from '../platform';const debugLauncher = platform.debug('pw:launcher');+const debugStdout = platform.debug('pw:stdio:out');+const debugStderr = platform.debug('pw:stdio:err');+(debugStdout as any).color = '178';+(debugStderr as any).color = '160';const removeFolderAsync = platform.promisify(removeFolder);export type LaunchProcessOptions = {@@ -73,13 +77,19 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Launreturn result;}- if (options.dumpio) {- spawnedProcess.stdout.pipe(process.stdout);- spawnedProcess.stderr.pipe(process.stderr);- } else {- spawnedProcess.stderr.on('data', () => {});- spawnedProcess.stdout.on('data', () => {});- }+ const stdout = readline.createInterface({ input: spawnedProcess.stdout });+ stdout.on('line', (data: string) => {+ debugStdout(data);+ if (options.dumpio)+ console.log(`\x1b[33m[out]\x1b[0m ${data}`); // eslint-disable-line no-console+ });++ const stderr = readline.createInterface({ input: spawnedProcess.stderr });+ stderr.on('line', (data: string) => {+ debugStderr(data);+ if (options.dumpio)+ console.log(`\x1b[31m[err]\x1b[0m ${data}`); // eslint-disable-line no-console+ });let processClosed = false;const waitForProcessToClose = new Promise((fulfill, reject) => {diff --git a/src/webkit/wkConnection.ts b/src/webkit/wkConnection.tsindex 8182a354f6..d127ccf9fd 100644--- a/src/webkit/wkConnection.ts+++ b/src/webkit/wkConnection.ts@@ -46,6 +46,7 @@ export class WKConnection {this.browserSession = new WKSession(this, '', 'Browser has been closed.', (message: any) => {this.rawSend(message);});+ (this._debugFunction as any).color = '34';}nextMessageId(): number {diff --git a/test/fixtures.spec.js b/test/fixtures.spec.jsindex d547c44624..242f81bfca 100644--- a/test/fixtures.spec.js+++ b/test/fixtures.spec.js@@ -72,14 +72,14 @@ module.exports.describe = function({testRunner, expect, product, browserType, plit.slow()('should dump browser process stderr', async({server}) => {let dumpioData = '';const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath, product, 'usewebsocket']);- res.stderr.on('data', data => dumpioData += data.toString('utf8'));+ res.stdout.on('data', data => dumpioData += data.toString('utf8'));await new Promise(resolve => res.on('close', resolve));expect(dumpioData).toContain('message from dumpio');});it.slow()('should dump browser process stderr', async({server}) => {let dumpioData = '';const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath, product]);- res.stderr.on('data', data => dumpioData += data.toString('utf8'));+ res.stdout.on('data', data => dumpioData += data.toString('utf8'));await new Promise(resolve => res.on('close', resolve));expect(dumpioData).toContain('message from dumpio');});diff --git a/test/playwright.spec.js b/test/playwright.spec.jsindex 7f5e007d3f..50e68e444b 100644--- a/test/playwright.spec.js+++ b/test/playwright.spec.js@@ -20,6 +20,7 @@ const os = require('os');const rm = require('rimraf').sync;const GoldenUtils = require('./golden-utils');const {Matchers} = require('../utils/testrunner/');+const readline = require('readline');const YELLOW_COLOR = '\x1b[33m';const RESET_COLOR = '\x1b[0m';@@ -103,6 +104,8 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => {beforeAll(async state => {state.browser = await browserType.launch(defaultBrowserOptions);state.browserServer = state.browser.__server__;+ state._stdout = readline.createInterface({ input: state.browserServer.process().stdout });+ state._stderr = readline.createInterface({ input: state.browserServer.process().stderr });});afterAll(async state => {@@ -112,22 +115,18 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => {});beforeEach(async(state, test) => {- const onLine = (line) => test.output += line + '\n';+ test.output = [];+ const dumpout = data => test.output.push(`\x1b[33m[pw:stdio:out]\x1b[0m ${data}`);+ const dumperr = data => test.output.push(`\x1b[31m[pw:stdio:err]\x1b[0m ${data}`);+ state._stdout.on('line', dumpout);+ state._stderr.on('line', dumperr);if (dumpProtocolOnFailure)- state.browser._setDebugFunction(onLine);-- let rl;- if (state.browserServer.process().stderr) {- rl = require('readline').createInterface({ input: state.browserServer.process().stderr });- test.output = '';- rl.on('line', onLine);- }-+ state.browser._setDebugFunction(data => test.output.push(`\x1b[32m[pw:protocol]\x1b[0m ${data}`));state.tearDown = async () => {- if (rl) {- rl.removeListener('line', onLine);- rl.close();- }+ state._stdout.off('line', dumpout);+ state._stderr.off('line', dumperr);+ state._stdout.close();+ state._stderr.close();if (dumpProtocolOnFailure)state.browser._setDebugFunction(() => void 0);};diff --git a/utils/testrunner/Reporter.js b/utils/testrunner/Reporter.jsindex 79f02698a8..e6b85688af 100644--- a/utils/testrunner/Reporter.js+++ b/utils/testrunner/Reporter.js@@ -207,7 +207,8 @@ class Reporter {console.log(`${prefix} ${colors.red(`[TIMEOUT ${test.timeout}ms]`)} ${test.fullName} (${formatLocation(test.location)})`);if (test.output) {console.log(' Output:');- console.log(padLines(test.output, 4));+ for (const line of test.output)+ console.log(' ' + line);}} else if (test.result === 'failed') {console.log(`${prefix} ${colors.red('[FAIL]')} ${test.fullName} (${formatLocation(test.location)})`);@@ -253,7 +254,8 @@ class Reporter {}if (test.output) {console.log(' Output:');- console.log(padLines(test.output, 4));+ for (const line of test.output)+ console.log(' ' + line);}}}