@@ -518,10 +518,11 @@ class Playwright extends Helper {
518
518
browserContext = browser . context ( ) ;
519
519
page = await browser . firstWindow ( ) ;
520
520
} else {
521
- browserContext = await this . browser . newContext ( config ) ;
521
+ browserContext = await this . browser . newContext ( Object . assign ( this . options , config ) ) ;
522
522
page = await browserContext . newPage ( ) ;
523
523
}
524
524
525
+ if ( this . options . trace ) await browserContext . tracing . start ( { screenshots : true , snapshots : true } ) ;
525
526
await targetCreatedHandler . call ( this , page ) ;
526
527
await this . _setPage ( page ) ;
527
528
// Create a new page inside context.
@@ -2071,37 +2072,42 @@ class Playwright extends Helper {
2071
2072
}
2072
2073
2073
2074
if ( this . options . recordVideo && this . page && this . page . video ( ) ) {
2074
- test . artifacts . video = `${ global . output_dir } ${ pathSeparator } videos ${ pathSeparator } ${ clearString ( test . title ) } _ ${ Date . now ( ) } . failed.webm` ;
2075
- this . page . video ( ) . saveAs ( test . artifacts . video ) . then ( ( ) => {
2076
- this . page . video ( ) . delete ( ) . catch ( e => { } ) ;
2077
- } ) ;
2075
+ test . artifacts . video = await saveVideoForPage ( this . page , `${ test . title } . failed` ) ;
2076
+ for ( const sessionName in this . sessionPages ) {
2077
+ test . artifacts [ `video_ ${ sessionName } ` ] = await saveVideoForPage ( this . sessionPages [ sessionName ] , ` ${ test . title } _ ${ sessionName } .failed` ) ;
2078
+ }
2078
2079
}
2079
2080
2080
2081
if ( this . options . trace ) {
2081
- const path = `${ `${ global . output_dir } ${ pathSeparator } trace${ pathSeparator } ${ clearString ( test . title ) } ` . slice ( 0 , 251 ) } .zip` ;
2082
- await this . browserContext . tracing . stop ( { path } ) ;
2083
- test . artifacts . trace = path ;
2082
+ test . artifacts . trace = await saveTraceForContext ( this . browserContext , `${ test . title } .failed` ) ;
2083
+ for ( const sessionName in this . sessionPages ) {
2084
+ if ( ! this . sessionPages [ sessionName ] . context ) continue ;
2085
+ test . artifacts [ `trace_${ sessionName } ` ] = await saveTraceForContext ( this . sessionPages [ sessionName ] . context ( ) , `${ test . title } _${ sessionName } .failed` ) ;
2086
+ }
2084
2087
}
2085
2088
}
2086
2089
2087
2090
async _passed ( test ) {
2088
2091
if ( this . options . recordVideo && this . page && this . page . video ( ) ) {
2089
- test . artifacts . video = `${ global . output_dir } ${ pathSeparator } videos${ pathSeparator } ${ clearString ( test . title ) } _${ Date . now ( ) } .passed.webm` ;
2090
-
2091
2092
if ( this . options . keepVideoForPassedTests ) {
2092
- this . page . video ( ) . saveAs ( test . artifacts . video ) . then ( ( ) => {
2093
- this . page . video ( ) . delete ( ) . catch ( e => { } ) ;
2094
- } ) ;
2093
+ test . artifacts . video = await saveVideoForPage ( this . page , `${ test . title } .passed` ) ;
2094
+ for ( const sessionName of Object . keys ( this . sessionPages ) ) {
2095
+ test . artifacts [ `video_${ sessionName } ` ] = await saveVideoForPage ( this . sessionPages [ sessionName ] , `${ test . title } _${ sessionName } .passed` ) ;
2096
+ }
2095
2097
} else {
2096
2098
this . page . video ( ) . delete ( ) . catch ( e => { } ) ;
2097
2099
}
2098
2100
}
2099
2101
2100
2102
if ( this . options . trace ) {
2101
2103
if ( this . options . keepTraceForPassedTests ) {
2102
- const path = `${ global . output_dir } ${ pathSeparator } trace${ pathSeparator } ${ clearString ( test . title ) } .zip` ;
2103
- await this . browserContext . tracing . stop ( { path } ) ;
2104
- test . artifacts . trace = path ;
2104
+ if ( this . options . trace ) {
2105
+ test . artifacts . trace = await saveTraceForContext ( this . browserContext , `${ test . title } .passed` ) ;
2106
+ for ( const sessionName in this . sessionPages ) {
2107
+ if ( ! this . sessionPages [ sessionName ] . context ) continue ;
2108
+ test . artifacts [ `trace_${ sessionName } ` ] = await saveTraceForContext ( this . sessionPages [ sessionName ] . context ( ) , `${ test . title } _${ sessionName } .passed` ) ;
2109
+ }
2110
+ }
2105
2111
} else {
2106
2112
await this . browserContext . tracing . stop ( ) ;
2107
2113
}
@@ -2972,3 +2978,21 @@ async function refreshContextSession() {
2972
2978
} ) ;
2973
2979
}
2974
2980
}
2981
+
2982
+ async function saveVideoForPage ( page , name ) {
2983
+ if ( ! page . video ( ) ) return null ;
2984
+ const fileName = `${ global . output_dir } ${ pathSeparator } videos${ pathSeparator } ${ Date . now ( ) } _${ clearString ( name ) . slice ( 0 , 245 ) } .webm` ;
2985
+ page . video ( ) . saveAs ( fileName ) . then ( ( ) => {
2986
+ if ( ! page ) return ;
2987
+ page . video ( ) . delete ( ) . catch ( e => { } ) ;
2988
+ } ) ;
2989
+ return fileName ;
2990
+ }
2991
+
2992
+ async function saveTraceForContext ( context , name ) {
2993
+ if ( ! context ) return ;
2994
+ if ( ! context . tracing ) return ;
2995
+ const fileName = `${ `${ global . output_dir } ${ pathSeparator } trace${ pathSeparator } ${ Date . now ( ) } _${ clearString ( name ) } ` . slice ( 0 , 245 ) } .zip` ;
2996
+ await context . tracing . stop ( { path : fileName } ) ;
2997
+ return fileName ;
2998
+ }
0 commit comments