Skip to content

Commit 892dbba

Browse files
authored
Puppeteer E2E test: Log console output (#25382)
* Puppeteer: Log console output * Don't error that camera is not available
1 parent 45ce26d commit 892dbba

File tree

1 file changed

+65
-8
lines changed

1 file changed

+65
-8
lines changed

test/e2e/puppeteer.js

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ async function main() {
145145

146146
/* Prepare page */
147147

148+
const errorMessagesCache = [];
149+
148150
const page = ( await browser.pages() )[ 0 ];
149-
await preparePage( page, injection, build );
151+
await preparePage( page, injection, build, errorMessagesCache );
150152

151153
/* Loop for each file */
152154

@@ -184,13 +186,64 @@ async function main() {
184186

185187
}
186188

187-
async function preparePage( page, injection, build ) {
189+
async function preparePage( page, injection, build, errorMessages ) {
188190

189-
/* let page.pageSize */
191+
/* let page.file, page.pageSize, page.error */
190192

191193
await page.evaluateOnNewDocument( injection );
192194
await page.setRequestInterception( true );
193195

196+
page.on( 'console', async msg => {
197+
198+
const type = msg.type();
199+
200+
if ( type !== 'warning' && type !== 'error' ) {
201+
202+
return;
203+
204+
}
205+
206+
const file = page.file;
207+
208+
if ( file === undefined ) {
209+
210+
return;
211+
212+
}
213+
214+
let text = ( await Promise.all( msg.args().map( arg => arg.executionContext().evaluate( arg => arg instanceof Error ? arg.message : arg, arg ) ) ) ).join( ' ' ); // https://github.com/puppeteer/puppeteer/issues/3397#issuecomment-434970058
215+
216+
text = text.trim();
217+
if ( text === '' ) return;
218+
219+
text = file + ': ' + text.replace( /\[\.WebGL-(.+?)\] /g, '' );
220+
221+
if ( errorMessages.includes( text ) ) {
222+
223+
return;
224+
225+
}
226+
227+
if ( text.includes( 'Unable to access the camera/webcam' ) ) {
228+
229+
return;
230+
231+
}
232+
233+
errorMessages.push( text );
234+
235+
if ( type === 'warning' ) {
236+
237+
console.yellow( text );
238+
239+
} else {
240+
241+
page.error = text;
242+
243+
}
244+
245+
} );
246+
194247
page.on( 'response', async ( response ) => {
195248

196249
try {
@@ -231,7 +284,9 @@ async function makeAttempt( page, failedScreenshots, cleanPage, isMakeScreenshot
231284

232285
try {
233286

287+
page.file = file;
234288
page.pageSize = 0;
289+
page.error = undefined;
235290

236291
/* Load target page */
237292

@@ -295,20 +350,22 @@ async function makeAttempt( page, failedScreenshots, cleanPage, isMakeScreenshot
295350

296351
} catch ( e ) {
297352

298-
if ( e.message.includes( 'Render timeout exceeded' ) ) { // This can mean that the example doesn't use requestAnimationFrame loop
353+
if ( ! e.message.includes( 'Render timeout exceeded' ) ) {
299354

300-
console.yellow( `Render timeout exceeded in file ${ file }` );
355+
throw new Error( `Error happened while rendering file ${ file }: ${ e }` );
301356

302-
} else {
357+
} /* else { // This can mean that the example doesn't use requestAnimationFrame loop
303358
304-
throw new Error( `Error happened while rendering file ${ file }: ${ e }` );
359+
console.yellow( `Render timeout exceeded in file ${ file }` );
305360
306-
}
361+
} */
307362

308363
}
309364

310365
const screenshot = ( await jimp.read( await page.screenshot() ) ).scale( 1 / viewScale ).quality( jpgQuality );
311366

367+
if ( page.error !== undefined ) throw new Error( page.error );
368+
312369
if ( isMakeScreenshot ) {
313370

314371
/* Make screenshots */

0 commit comments

Comments
 (0)