Skip to content

Commit

Permalink
feat(web): announce artifcat generation on TestRunFinishes
Browse files Browse the repository at this point in the history
Related tickets: serenity-js#1996
  • Loading branch information
viper3400 committed Nov 11, 2023
1 parent c94c01a commit f9bad89
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions packages/web/src/stage/crew/photographer/Photographer.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -153,6 +154,7 @@ import * as strategies from './strategies';
* @group Stage
*/
export class Photographer implements StageCrewMember {
private artifacts : Array<ActivityRelatedArtifactGenerated>;

/**
* Instantiates a new {@apilink Photographer} configured to take photos (screenshots)
Expand Down Expand Up @@ -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(),
));
}
}
}
}

0 comments on commit f9bad89

Please sign in to comment.