@@ -127,7 +127,7 @@ export default function (config) {
127127 firstFailedStepSaved = false
128128 } )
129129
130- event . dispatcher . on ( event . step . after , async step => {
130+ event . dispatcher . on ( event . step . after , step => {
131131 if ( ! currentTest ) return
132132 if ( step . status === 'failed' ) {
133133 testFailed = true
@@ -140,11 +140,10 @@ export default function (config) {
140140 output . debug ( `aiTrace: Skipping failed step "${ step . toString ( ) } " - already handled by step.failed event` )
141141 return
142142 }
143- try {
144- await persistStep ( step )
145- } catch ( err ) {
143+ const stepPersistPromise = persistStep ( step ) . catch ( err => {
146144 output . debug ( `aiTrace: Error saving step: ${ err . message } ` )
147- }
145+ } )
146+ recorder . add ( `wait aiTrace step persistence: ${ step . toString ( ) } ` , ( ) => stepPersistPromise , true )
148147 } )
149148
150149 event . dispatcher . on ( event . step . failed , async step => {
@@ -282,7 +281,22 @@ export default function (config) {
282281 output . debug ( `aiTrace: Browser unavailable, partial artifact capture: ${ err . message } ` )
283282 }
284283
285- if ( ! step . artifacts ?. screenshot ) {
284+ if ( step . artifacts ?. screenshot ) {
285+ const screenshotPath = path . isAbsolute ( step . artifacts . screenshot )
286+ ? step . artifacts . screenshot
287+ : path . resolve ( dir , step . artifacts . screenshot )
288+ const screenshotFile = path . basename ( screenshotPath )
289+ stepData . artifacts . screenshot = screenshotFile
290+ step . artifacts . screenshot = screenshotPath
291+
292+ if ( ! fs . existsSync ( screenshotPath ) ) {
293+ try {
294+ await helper . saveScreenshot ( screenshotPath , config . fullPageScreenshots )
295+ } catch ( err ) {
296+ output . debug ( `aiTrace: Could not save screenshot: ${ err . message } ` )
297+ }
298+ }
299+ } else {
286300 try {
287301 const screenshotFile = `${ stepPrefix } _screenshot.png`
288302 const screenshotPath = path . join ( dir , screenshotFile )
0 commit comments