From f9bad89681c395c020fbcaa100c9949480ffc6bf Mon Sep 17 00:00:00 2001 From: viper3400 Date: Sun, 5 Nov 2023 20:01:15 +0100 Subject: [PATCH] feat(web): announce artifcat generation on TestRunFinishes Related tickets: #1996 --- .../stage/crew/photographer/Photographer.ts | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/packages/web/src/stage/crew/photographer/Photographer.ts b/packages/web/src/stage/crew/photographer/Photographer.ts index 2df7704baa..ea566ecfce 100644 --- a/packages/web/src/stage/crew/photographer/Photographer.ts +++ b/packages/web/src/stage/crew/photographer/Photographer.ts @@ -1,6 +1,7 @@ import { ConfigurationError, LogicError } from '@serenity-js/core'; -import type { DomainEvent } from '@serenity-js/core/lib/events'; -import { ActivityFinished, ActivityStarts } from '@serenity-js/core/lib/events'; +import type { ActivityRelatedArtifactGenerated, DomainEvent} from '@serenity-js/core/lib/events'; +import { ActivityFinished, ActivityStarts, ArtifactGenerated, AsyncOperationAttempted, AsyncOperationCompleted, AsyncOperationFailed, TestRunFinishes} from '@serenity-js/core/lib/events'; +import { CorrelationId, Description,Name } from '@serenity-js/core/lib/model'; import type { Stage, StageCrewMember } from '@serenity-js/core/lib/stage'; import * as strategies from './strategies'; @@ -153,6 +154,7 @@ import * as strategies from './strategies'; * @group Stage */ export class Photographer implements StageCrewMember { + private artifacts : Array; /** * Instantiates a new {@apilink Photographer} configured to take photos (screenshots) @@ -222,8 +224,41 @@ export class Photographer implements StageCrewMember { if (event instanceof ActivityStarts || event instanceof ActivityFinished) { this.photoTakingStrategy.considerTakingPhoto(event, this.stage).then( (artifact) => { - if (artifact) this.stage.announce(artifact); + if (artifact) this.artifacts.push(artifact) }) } + + if (event instanceof TestRunFinishes) { + const id = CorrelationId.create(); + + this.stage.announce(new AsyncOperationAttempted( + new Name(this.constructor.name), + new Description(`Generating Serenity images ...`), + id, + this.stage.currentTime(), + )); + try { + this.artifacts.forEach( (artifact) => this.stage.announce(new ArtifactGenerated( + artifact.sceneId, + artifact.name, + artifact.artifact, + artifact.timestamp + )) + ); + this.stage.announce(new AsyncOperationCompleted( + id, + this.stage.currentTime(), + )); + this.artifacts = [] + + } + catch (error) { + this.stage.announce(new AsyncOperationFailed( + error, + id, + this.stage.currentTime(), + )); + } + } } }