@@ -24,6 +24,7 @@ import type { TestInfoImpl, TestStepInternal } from './worker/testInfo';
2424import { rootTestType } from './common/testType' ;
2525import type { ContextReuseMode } from './common/config' ;
2626import type { ApiCallData , ClientInstrumentation , ClientInstrumentationListener } from '../../playwright-core/src/client/clientInstrumentation' ;
27+ import type { Playwright as PlaywrightImpl } from '../../playwright-core/src/client/playwright' ;
2728import { currentTestInfo } from './common/globals' ;
2829export { expect } from './matchers/expect' ;
2930export const _baseTest : TestType < { } , { } > = rootTestType . test ;
@@ -50,6 +51,7 @@ type TestFixtures = PlaywrightTestArgs & PlaywrightTestOptions & {
5051} ;
5152
5253type WorkerFixtures = PlaywrightWorkerArgs & PlaywrightWorkerOptions & {
54+ playwright : PlaywrightImpl ;
5355 _browserOptions : LaunchOptions ;
5456 _optionContextReuseMode : ContextReuseMode ,
5557 _optionConnectOptions : PlaywrightWorkerOptions [ 'connectOptions' ] ,
@@ -78,18 +80,16 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
7880 const options : LaunchOptions = {
7981 handleSIGINT : false ,
8082 ...launchOptions ,
83+ tracesDir : tracing ( ) . tracesDir ( ) ,
8184 } ;
8285 if ( headless !== undefined )
8386 options . headless = headless ;
8487 if ( channel !== undefined )
8588 options . channel = channel ;
86- options . tracesDir = tracing ( ) . tracesDir ( ) ;
8789
88- for ( const browserType of [ playwright . chromium , playwright . firefox , playwright . webkit , playwright . _bidiChromium , playwright . _bidiFirefox ] )
89- ( browserType as any ) . _defaultLaunchOptions = options ;
90+ playwright . _defaultLaunchOptions = options ;
9091 await use ( options ) ;
91- for ( const browserType of [ playwright . chromium , playwright . firefox , playwright . webkit , playwright . _bidiChromium , playwright . _bidiFirefox ] )
92- ( browserType as any ) . _defaultLaunchOptions = undefined ;
92+ playwright . _defaultLaunchOptions = undefined ;
9393 } , { scope : 'worker' , auto : true , box : true } ] ,
9494
9595 browser : [ async ( { playwright, browserName, _browserOptions, connectOptions, _reuseContext } , use , testInfo ) => {
@@ -232,21 +232,14 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
232232 testInfo . snapshotSuffix = process . platform ;
233233 if ( debugMode ( ) )
234234 ( testInfo as TestInfoImpl ) . _setDebugMode ( ) ;
235- for ( const browserType of [ playwright . chromium , playwright . firefox , playwright . webkit ] ) {
236- ( browserType as any ) . _defaultContextOptions = _combinedContextOptions ;
237- ( browserType as any ) . _defaultContextTimeout = actionTimeout || 0 ;
238- ( browserType as any ) . _defaultContextNavigationTimeout = navigationTimeout || 0 ;
239- }
240- ( playwright . request as any ) . _defaultContextOptions = { ..._combinedContextOptions } ;
241- ( playwright . request as any ) . _defaultContextOptions . tracesDir = tracing ( ) . tracesDir ( ) ;
242- ( playwright . request as any ) . _defaultContextOptions . timeout = actionTimeout || 0 ;
235+
236+ playwright . _defaultContextOptions = _combinedContextOptions ;
237+ playwright . _defaultContextTimeout = actionTimeout || 0 ;
238+ playwright . _defaultContextNavigationTimeout = navigationTimeout || 0 ;
243239 await use ( ) ;
244- ( playwright . request as any ) . _defaultContextOptions = undefined ;
245- for ( const browserType of [ playwright . chromium , playwright . firefox , playwright . webkit ] ) {
246- ( browserType as any ) . _defaultContextOptions = undefined ;
247- ( browserType as any ) . _defaultContextTimeout = undefined ;
248- ( browserType as any ) . _defaultContextNavigationTimeout = undefined ;
249- }
240+ playwright . _defaultContextOptions = undefined ;
241+ playwright . _defaultContextTimeout = undefined ;
242+ playwright . _defaultContextNavigationTimeout = undefined ;
250243 } , { auto : 'all-hooks-included' , title : 'context configuration' , box : true } as any ] ,
251244
252245 _setupArtifacts : [ async ( { playwright, screenshot, _pageSnapshot } , use , testInfo ) => {
@@ -453,7 +446,6 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
453446} ) ;
454447
455448type ScreenshotOption = PlaywrightWorkerOptions [ 'screenshot' ] | undefined ;
456- type Playwright = PlaywrightWorkerArgs [ 'playwright' ] ;
457449type PageSnapshotOption = 'off' | 'on' | 'only-on-failure' ;
458450
459451function normalizeVideoMode ( video : VideoMode | 'retry-with-video' | { mode : VideoMode } | undefined ) : VideoMode {
@@ -556,12 +548,7 @@ class SnapshotRecorder {
556548 if ( ! this . shouldCaptureUponFinish ( ) )
557549 return ;
558550
559- const contexts : BrowserContext [ ] = [ ] ;
560- const playwright = this . _artifactsRecorder . _playwright ;
561- for ( const browserType of [ playwright . chromium , playwright . firefox , playwright . webkit ] )
562- contexts . push ( ...( browserType as any ) . _contexts ) ;
563-
564- await Promise . all ( contexts . flatMap ( context => context . pages ( ) . map ( page => this . _snapshotPage ( page , false ) ) ) ) ;
551+ await Promise . all ( this . _artifactsRecorder . _playwright . _allPages ( ) . map ( page => this . _snapshotPage ( page , false ) ) ) ;
565552 }
566553
567554 async persistTemporary ( ) {
@@ -622,15 +609,15 @@ class SnapshotRecorder {
622609
623610class ArtifactsRecorder {
624611 _testInfo ! : TestInfoImpl ;
625- _playwright : Playwright ;
612+ _playwright : PlaywrightImpl ;
626613 _artifactsDir : string ;
627614 private _reusedContexts = new Set < BrowserContext > ( ) ;
628615 private _startedCollectingArtifacts : symbol ;
629616
630617 private _pageSnapshotRecorder : SnapshotRecorder ;
631618 private _screenshotRecorder : SnapshotRecorder ;
632619
633- constructor ( playwright : Playwright , artifactsDir : string , screenshot : ScreenshotOption , pageSnapshot : PageSnapshotOption ) {
620+ constructor ( playwright : PlaywrightImpl , artifactsDir : string , screenshot : ScreenshotOption , pageSnapshot : PageSnapshotOption ) {
634621 this . _playwright = playwright ;
635622 this . _artifactsDir = artifactsDir ;
636623 const screenshotOptions = typeof screenshot === 'string' ? undefined : screenshot ;
@@ -654,17 +641,12 @@ class ArtifactsRecorder {
654641 this . _pageSnapshotRecorder . fixOrdinal ( ) ;
655642
656643 // Process existing contexts.
657- for ( const browserType of [ this . _playwright . chromium , this . _playwright . firefox , this . _playwright . webkit ] ) {
658- const promises : ( Promise < void > | undefined ) [ ] = [ ] ;
659- const existingContexts = Array . from ( ( browserType as any ) . _contexts ) as BrowserContext [ ] ;
660- for ( const context of existingContexts ) {
661- if ( ( context as any ) [ kIsReusedContext ] )
662- this . _reusedContexts . add ( context ) ;
663- else
664- promises . push ( this . didCreateBrowserContext ( context ) ) ;
665- }
666- await Promise . all ( promises ) ;
667- }
644+ await Promise . all ( this . _playwright . _allContexts ( ) . map ( async context => {
645+ if ( ( context as any ) [ kIsReusedContext ] )
646+ this . _reusedContexts . add ( context ) ;
647+ else
648+ await this . didCreateBrowserContext ( context ) ;
649+ } ) ) ;
668650 {
669651 const existingApiRequests : APIRequestContext [ ] = Array . from ( ( this . _playwright . request as any ) . _contexts as Set < APIRequestContext > ) ;
670652 await Promise . all ( existingApiRequests . map ( c => this . didCreateRequestContext ( c ) ) ) ;
@@ -704,10 +686,7 @@ class ArtifactsRecorder {
704686 async didFinishTest ( ) {
705687 await this . didFinishTestFunction ( ) ;
706688
707- let leftoverContexts : BrowserContext [ ] = [ ] ;
708- for ( const browserType of [ this . _playwright . chromium , this . _playwright . firefox , this . _playwright . webkit ] )
709- leftoverContexts . push ( ...( browserType as any ) . _contexts ) ;
710- leftoverContexts = leftoverContexts . filter ( context => ! this . _reusedContexts . has ( context ) ) ;
689+ const leftoverContexts = this . _playwright . _allContexts ( ) . filter ( context => ! this . _reusedContexts . has ( context ) ) ;
711690 const leftoverApiRequests : APIRequestContext [ ] = Array . from ( ( this . _playwright . request as any ) . _contexts as Set < APIRequestContext > ) ;
712691
713692 // Collect traces/screenshots for remaining contexts.
0 commit comments