CollectsArtifacts
Implemented by
Index
Methods
Methods
collect
Makes the Actor collect an Artifact so that it can be included in the test report.
Implementing a custom interaction to attach artifacts
import * as fs from 'node:fs'
import { Answerable, Interaction } from '@serenity-js/core'
import { Path } from '@serenity-js/core/lib/io'
import { Name, TextData } from '@serenity-js/core/lib/model'
export class Attach {
static contentsOf = (pathToFile: Path): Interaction =>
Interaction.where(`#actor attaches contents of ${ pathToFile.basename() }`, async actor => {
const data = fs.readFileSync(pathToFile.value).toString('utf-8');
actor.collect(
TextData.fromJSON({ contentType: 'text/plain', data }),
new Name(pathToFile.basename()),
)
})
static textData = (contents: Answerable<string>, name?: string): Interaction =>
Interaction.where(`#actor attaches text data`, async actor => {
const data = await actor.answer(contents);
actor.collect(
TextData.fromJSON({ contentType: 'text/plain', data }),
name && new Name(name),
)
})
}Attaching plain text
import { actorCalled } from '@serenity-js/core'
import { Path } from '@serenity-js/core/lib/io'
actorCalled('Alice').attemptsTo(
Attach.textData('some text', 'some name'),
)Attaching contents of a text file
import { actorCalled } from '@serenity-js/core'
import { Log } from '@serenity-js/core'
actorCalled('Alice').attemptsTo(
Attach.contentsOf(Path.from(__dirname, 'output/server.log')),
)Parameters
artifact: Artifact
The artifact to be collected, such as JSONData
optionalname: Name
The name of the artifact to make it easy to recognise in the test report
Returns void
Describes an Actor who can collect Artifacts, such as Photos or JSONData, while the scenario is being executed
Learn more