Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions lib/plugin/aiTrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default function (config) {
firstFailedStepSaved = false
})

event.dispatcher.on(event.step.after, async step => {
event.dispatcher.on(event.step.after, step => {
if (!currentTest) return
if (step.status === 'failed') {
testFailed = true
Expand All @@ -140,13 +140,10 @@ export default function (config) {
output.debug(`aiTrace: Skipping failed step "${step.toString()}" - already handled by step.failed event`)
return
}
recorder.add(`save artifacts for step ${step.toString()}`, async () => {
try {
await persistStep(step)
} catch (err) {
output.debug(`aiTrace: Error saving step: ${err.message}`)
}
}, true)
const stepPersistPromise = persistStep(step).catch(err => {
output.debug(`aiTrace: Error saving step: ${err.message}`)
})
recorder.add(`wait aiTrace step persistence: ${step.toString()}`, () => stepPersistPromise, true)
})

event.dispatcher.on(event.step.failed, async step => {
Expand Down Expand Up @@ -284,7 +281,22 @@ export default function (config) {
output.debug(`aiTrace: Browser unavailable, partial artifact capture: ${err.message}`)
}

if (!step.artifacts?.screenshot) {
if (step.artifacts?.screenshot) {
const screenshotPath = path.isAbsolute(step.artifacts.screenshot)
? step.artifacts.screenshot
: path.resolve(dir, step.artifacts.screenshot)
const screenshotFile = path.basename(screenshotPath)
stepData.artifacts.screenshot = screenshotFile
step.artifacts.screenshot = screenshotPath

if (!fs.existsSync(screenshotPath)) {
try {
await helper.saveScreenshot(screenshotPath, config.fullPageScreenshots)
} catch (err) {
output.debug(`aiTrace: Could not save screenshot: ${err.message}`)
}
}
} else {
try {
const screenshotFile = `${stepPrefix}_screenshot.png`
const screenshotPath = path.join(dir, screenshotFile)
Expand Down