1717import { spawnSync } from 'child_process' ;
1818import fs from 'fs' ;
1919import path from 'path' ;
20- import type { Page } from 'playwright-core' ;
2120import { PNG , jpegjs } from 'playwright-core/lib/utilsBundle' ;
2221import { registry } from '../../packages/playwright-core/lib/server' ;
2322import { expect , browserTest as it } from '../config/browserTest' ;
24- import { parseTraceRaw } from '../config/utils' ;
23+ import { parseTraceRaw , rafraf } from '../config/utils' ;
2524
2625export class VideoPlayer {
2726 fileName : string ;
@@ -171,7 +170,7 @@ it.describe('screencast', () => {
171170 const page = await context . newPage ( ) ;
172171
173172 await page . evaluate ( ( ) => document . body . style . backgroundColor = 'red' ) ;
174- await waitForRafs ( page , 100 ) ;
173+ await rafraf ( page , 100 ) ;
175174 await context . close ( ) ;
176175
177176 const videoFile = await page . video ( ) . path ( ) ;
@@ -196,7 +195,7 @@ it.describe('screencast', () => {
196195 const page = await context . newPage ( ) ;
197196
198197 await page . evaluate ( ( ) => document . body . style . backgroundColor = 'red' ) ;
199- await waitForRafs ( page , 100 ) ;
198+ await rafraf ( page , 100 ) ;
200199 await context . close ( ) ;
201200
202201 const videoFile = await page . video ( ) . path ( ) ;
@@ -226,7 +225,7 @@ it.describe('screencast', () => {
226225 document . body . textContent = '' ; // remove link
227226 document . body . style . backgroundColor = 'red' ;
228227 } ) ;
229- await waitForRafs ( page , 100 ) ;
228+ await rafraf ( page , 100 ) ;
230229 await context . close ( ) ;
231230
232231 const videoFile = await page . video ( ) . path ( ) ;
@@ -294,7 +293,7 @@ it.describe('screencast', () => {
294293 const page = await context . newPage ( ) ;
295294 const deletePromise = page . video ( ) . delete ( ) ;
296295 await page . evaluate ( ( ) => document . body . style . backgroundColor = 'red' ) ;
297- await waitForRafs ( page , 100 ) ;
296+ await rafraf ( page , 100 ) ;
298297 await context . close ( ) ;
299298
300299 const videoPath = await page . video ( ) . path ( ) ;
@@ -385,9 +384,9 @@ it.describe('screencast', () => {
385384 const page = await context . newPage ( ) ;
386385
387386 await page . goto ( server . PREFIX + '/background-color.html#rgb(0,0,0)' ) ;
388- await waitForRafs ( page , 100 ) ;
387+ await rafraf ( page , 100 ) ;
389388 await page . goto ( server . CROSS_PROCESS_PREFIX + '/background-color.html#rgb(100,100,100)' ) ;
390- await waitForRafs ( page , 100 ) ;
389+ await rafraf ( page , 100 ) ;
391390 await context . close ( ) ;
392391
393392 const videoFile = await page . video ( ) . path ( ) ;
@@ -423,7 +422,7 @@ it.describe('screencast', () => {
423422 const page = await context . newPage ( ) ;
424423
425424 await page . goto ( server . PREFIX + '/rotate-z.html' ) ;
426- await waitForRafs ( page , 100 ) ;
425+ await rafraf ( page , 100 ) ;
427426 await context . close ( ) ;
428427
429428 const videoFile = await page . video ( ) . path ( ) ;
@@ -457,8 +456,8 @@ it.describe('screencast', () => {
457456 ] ) ;
458457 await popup . evaluate ( ( ) => document . body . style . backgroundColor = 'red' ) ;
459458 await Promise . all ( [
460- waitForRafs ( page , 100 ) ,
461- waitForRafs ( popup , 100 ) ,
459+ rafraf ( page , 100 ) ,
460+ rafraf ( popup , 100 ) ,
462461 ] ) ;
463462 await context . close ( ) ;
464463
@@ -490,11 +489,11 @@ it.describe('screencast', () => {
490489 await page . $eval ( '.container' , container => {
491490 container . firstElementChild . classList . remove ( 'red' ) ;
492491 } ) ;
493- await waitForRafs ( page , 100 ) ;
492+ await rafraf ( page , 100 ) ;
494493 await page . $eval ( '.container' , container => {
495494 container . firstElementChild . classList . add ( 'red' ) ;
496495 } ) ;
497- await waitForRafs ( page , 100 ) ;
496+ await rafraf ( page , 100 ) ;
498497 await context . close ( ) ;
499498
500499 const videoFile = await page . video ( ) . path ( ) ;
@@ -530,7 +529,7 @@ it.describe('screencast', () => {
530529 } ) ;
531530
532531 const page = await context . newPage ( ) ;
533- await waitForRafs ( page , 100 ) ;
532+ await rafraf ( page , 100 ) ;
534533 await context . close ( ) ;
535534
536535 const videoFile = await page . video ( ) . path ( ) ;
@@ -547,7 +546,7 @@ it.describe('screencast', () => {
547546 } ) ;
548547
549548 const page = await context . newPage ( ) ;
550- await waitForRafs ( page , 100 ) ;
549+ await rafraf ( page , 100 ) ;
551550 await context . close ( ) ;
552551
553552 const videoFile = await page . video ( ) . path ( ) ;
@@ -567,7 +566,7 @@ it.describe('screencast', () => {
567566 } ) ;
568567
569568 const page = await context . newPage ( ) ;
570- await waitForRafs ( page , 100 ) ;
569+ await rafraf ( page , 100 ) ;
571570 await context . close ( ) ;
572571
573572 const videoFile = await page . video ( ) . path ( ) ;
@@ -588,7 +587,7 @@ it.describe('screencast', () => {
588587 } ) ;
589588
590589 await page . evaluate ( ( ) => document . body . style . backgroundColor = 'red' ) ;
591- await waitForRafs ( page , 100 ) ;
590+ await rafraf ( page , 100 ) ;
592591 await context . close ( ) ;
593592
594593 const videoFile = await page . video ( ) . path ( ) ;
@@ -617,7 +616,7 @@ it.describe('screencast', () => {
617616 } ) ;
618617
619618 const page = await context . newPage ( ) ;
620- await waitForRafs ( page , 100 ) ;
619+ await rafraf ( page , 100 ) ;
621620 await context . close ( ) ;
622621
623622 const videoFile = await page . video ( ) . path ( ) ;
@@ -638,7 +637,7 @@ it.describe('screencast', () => {
638637 } ) ;
639638
640639 const page = await context . newPage ( ) ;
641- await waitForRafs ( page , 100 ) ;
640+ await rafraf ( page , 100 ) ;
642641 await browser . close ( ) ;
643642
644643 const file = testInfo . outputPath ( 'saved-video-' ) ;
@@ -659,7 +658,7 @@ it.describe('screencast', () => {
659658 } ) ;
660659
661660 const page = await context . newPage ( ) ;
662- await waitForRafs ( page , 100 ) ;
661+ await rafraf ( page , 100 ) ;
663662 await ( browser as any ) . _channel . killForTests ( ) ;
664663
665664 const file = testInfo . outputPath ( 'saved-video-' ) ;
@@ -681,7 +680,7 @@ it.describe('screencast', () => {
681680 } ) ;
682681
683682 const page = await context . newPage ( ) ;
684- await waitForRafs ( page , 100 ) ;
683+ await rafraf ( page , 100 ) ;
685684 await page . close ( ) ;
686685 await context . close ( ) ;
687686 await browser . close ( ) ;
@@ -709,7 +708,7 @@ it.describe('screencast', () => {
709708
710709 const page = await context . newPage ( ) ;
711710 await page . goto ( server . EMPTY_PAGE ) ;
712- await waitForRafs ( page , 100 ) ;
711+ await rafraf ( page , 100 ) ;
713712
714713 const cookies = await context . cookies ( ) ;
715714 expect ( cookies . length ) . toBe ( 1 ) ;
@@ -738,7 +737,7 @@ it.describe('screencast', () => {
738737
739738 const page = await context . newPage ( ) ;
740739 await page . setContent ( `<div style='margin: 0; background: red; position: fixed; right:0; bottom:0; width: 30; height: 30;'></div>` ) ;
741- await waitForRafs ( page , 100 ) ;
740+ await rafraf ( page , 100 ) ;
742741 await page . close ( ) ;
743742 await context . close ( ) ;
744743 await browser . close ( ) ;
@@ -775,7 +774,7 @@ it.describe('screencast', () => {
775774
776775 const page = await context . newPage ( ) ;
777776 await page . setContent ( `<div style='margin: 0; background: red; position: fixed; right:0; bottom:0; width: 30; height: 30;'></div>` ) ;
778- await waitForRafs ( page , 100 ) ;
777+ await rafraf ( page , 100 ) ;
779778 await page . close ( ) ;
780779 await context . close ( ) ;
781780 await browser . close ( ) ;
@@ -811,7 +810,7 @@ it.describe('screencast', () => {
811810 const page = await context . newPage ( ) ;
812811
813812 await page . evaluate ( ( ) => document . body . style . backgroundColor = 'red' ) ;
814- await waitForRafs ( page , 100 ) ;
813+ await rafraf ( page , 100 ) ;
815814 await context . tracing . stop ( { path : traceFile } ) ;
816815 await context . close ( ) ;
817816
@@ -849,23 +848,10 @@ it('should saveAs video', async ({ browser }, testInfo) => {
849848 } ) ;
850849 const page = await context . newPage ( ) ;
851850 await page . evaluate ( ( ) => document . body . style . backgroundColor = 'red' ) ;
852- await waitForRafs ( page , 100 ) ;
851+ await rafraf ( page , 100 ) ;
853852 await context . close ( ) ;
854853
855854 const saveAsPath = testInfo . outputPath ( 'my-video.webm' ) ;
856855 await page . video ( ) . saveAs ( saveAsPath ) ;
857856 expect ( fs . existsSync ( saveAsPath ) ) . toBeTruthy ( ) ;
858857} ) ;
859-
860- async function waitForRafs ( page : Page , count : number ) : Promise < void > {
861- await page . evaluate ( count => new Promise < void > ( resolve => {
862- const onRaf = ( ) => {
863- -- count ;
864- if ( ! count )
865- resolve ( ) ;
866- else
867- window . builtins . requestAnimationFrame ( onRaf ) ;
868- } ;
869- window . builtins . requestAnimationFrame ( onRaf ) ;
870- } ) , count ) ;
871- }
0 commit comments