@serenity-js/core
Serenity/JS is an innovative open-source framework designed to make acceptance and regression testing of complex software systems faster, more collaborative and easier to scale.
βοΈ Get started with Serenity/JS!
π Join the Serenity/JS Community!
- Meet other Serenity/JS developers and maintainers on the Serenity/JS Community chat channel,
- Find answers to your Serenity/JS questions on the Serenity/JS Forum,
- Learn how to contribute to Serenity/JS,
- Support the project and gain access to Serenity/JS Playbooks by becoming a Serenity/JS GitHub Sponsor!
Serenity/JS Coreβ
@serenity-js/core
is the heart of the Serenity/JS framework.
It enables you to configure the framework, manage actors, and provides basic building blocks
to help you design high-quality acceptance tests.
Installationβ
To install this module, run the following command in your computer terminal:
npm install --save-dev @serenity-js/core
π£ Stay up to dateβ
New features, tutorials, and demos are coming soon! Follow Serenity/JS on LinkedIn, subscribe to Serenity/JS channel on YouTube and join the Serenity/JS Community Chat to stay up to date! Please also make sure to star βοΈ Serenity/JS on GitHub to help others discover the framework!
π Support Serenity/JSβ
If you appreciate all the effort that goes into making sophisticated tools easy to work with, please support our work and become a Serenity/JS GitHub Sponsor today!
Index
Abilities
Activities
Actors
Errors
Expectations
Notes
Questions
Screenplay Pattern
Serenity
Stage
Time
Abilities
AbilityType
Type parameters
- A: Ability
Type declaration
Parameters
rest...args: any[]
Returns A
Expectations
Predicate
Type parameters
- Actual
Type declaration
Parameters
actor: AnswersQuestions
actual: Answerable<Actual>
Returns Promise<ExpectationOutcome> | ExpectationOutcome
Questions
Answerable
A union type that provides a convenient way to represent any value that can be resolved by Actor.answer.
Type parameters
- T
Answered
Describes the type of answer a given Answerable would resolve to when given to Actor.answer.
Answered<Answerable<T>> === T
Type parameters
- T
QuestionAdapterFieldDecorator
Describes an object recursively wrapped in QuestionAdapter proxies, so that:
- both methods and fields of the wrapped object can be used as questions or interactions
- method parameters of the wrapped object will accept Answerable<T>
Type parameters
- Original_Type
QuestionAdapter
A union type representing a proxy object returned by Question.about.
QuestionAdapter proxies the methods and fields of the wrapped object recursively, allowing them to be used as either a Question or an Interaction.
Type parameters
- T
RecursivelyAnswered
Describes a recursively resolved plain JavaScript WithAnswerableProperties.
Typically, used in conjunction with Question.fromObject.
Using RecursivelyAnswered
import {
actorCalled, notes, q, Question, QuestionAdapter, WithAnswerableProperties
} from '@serenity-js/core';
interface RequestConfiguration {
headers: Record<string, string>;
}
const requestConfiguration: WithAnswerableProperties<RequestConfiguration> = {
headers: {
Authorization: q`Bearer ${ notes().get('authDetails').token }`
}
}
const question: QuestionAdapter<RequestConfiguration> =
Question.fromObject<RequestConfiguration>(requestConfiguration)
const answer = await actorCalled('Annie').answer(question);
const a1: RequestConfiguration = answer;
const a2: RecursivelyAnswered<WithAnswerableProperties<RequestConfiguration>> = answer;
// RequestConfiguration === RecursivelyAnswered<WithAnswerableProperties<RequestConfiguration>>
Type parameters
- T
WithAnswerableProperties
Describes a plain JavaScript object with Answerable properties. Typically, used in conjunction with RecursivelyAnswered and Question.fromObject.
import {
actorCalled, notes, q, Question, QuestionAdapter, WithAnswerableProperties
} from '@serenity-js/core';
interface RequestConfiguration {
headers: Record<string, string>;
}
const requestConfiguration: WithAnswerableProperties<RequestConfiguration> = {
headers: {
Authorization: q`Bearer ${ notes().get('authDetails').token }`
}
}
const question: QuestionAdapter<RequestConfiguration> =
Question.fromObject<RequestConfiguration>(requestConfiguration)
const answer: RequestConfiguration = await actorCalled('Annie').answer(question);
Type parameters
- T
Serenity
ClassDescription
ClassDescription
describes the Node module ID and optionally:
- a named export that you want to import
- a parameter that should be passed to the static
fromJSON
method if the imported type provides it.
ClassDescription
is used to describe the StageCrewMembers passed to SerenityConfig.
The most basic class description is the name of a Node module that must provide a default
export.
For example, below definition would be interpreted as a request to import the default
export from the @serenity-js/serenity-bdd
module and instantiate it using its no-arg constructor:
import { configure } from '@serenity-js/core'
configure({
crew: [
`@serenity-js/serenity-bdd`
]
})
Class description can also include a named export to be imported. For example, below definition would be interpreted as a request
to import the SerenityBDDReporter
type from @serenity-js/serenity-bdd
and instantiate it using its no-arg constructor:
import { configure } from '@serenity-js/core'
configure({
crew: [
`@serenity-js/serenity-bdd:SerenityBDDReporter`
]
})
However, not all types have no-arg constructors. In those cases, a type offering a static fromJSON(configParam)
method can be described using a tuple
where the first item describes the Node module and optionally the class name, and the second item describes the configParam
.
import { configure } from '@serenity-js/core'
configure({
crew: [
[ `@serenity-js/core:ArtifactArchiver`, { outputDirectory: './target/site/serenity' } ]
]
})
Note that the class description could also describe a local Node module. This can be useful when youβre writing a custom StageCrewMember implementation.
For example, ./my-reporter:MyReporter
would be interpreted as a request to load the MyReporter
type from ./my-reporter
file, located
relative to the working directory of the current Node.js process.
constserenity
Serenity object is the root object of the Serenity/JS framework.
An interface describing the static access method that every Ability class needs to provide in order to be accessible from within the interactions.
Retrieving an ability from an interaction
Learn more