external@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!
- Serenity/JS web testing tutorial
- Serenity/JS Handbook and Getting Started guides
- API documentation
- Serenity/JS Project Templates
👋 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
To learn more about Serenity/JS and how to use it on your project, follow the Serenity/JS Getting Started guide.
📣 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
externalAbilityType
Type parameters
- A: Ability
Expectations
externalPredicate
Type parameters
- Actual
Type declaration
Parameters
externalactor: AnswersQuestions
externalactual: Answerable<Actual>
Returns Promise<ExpectationOutcome> | ExpectationOutcome
Questions
externalAnswerable
A union type that provides a convenient way to represent any value
that can be resolved by Actor.answer
.
Type parameters
- T
externalAnswered
Describes the type of answer a given Answerable
would
resolve to when given to Actor.answer
.
Answered<Answerable<T>> === T
Type parameters
- T
externalQuestionAdapterFieldDecorator
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
externalQuestionAdapter
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
- Answer_Type
externalMetaQuestionAdapter
An extension of QuestionAdapter
, that in addition to proxying methods and fields
of the wrapped object can also act as a MetaQuestion
.
Type parameters
- Context_Type
- Answer_Type
externalRecursivelyAnswered
Describes a recursively resolved plain JavaScript object with answerable properties.
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
externalWithAnswerableProperties
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
externalClassDescription
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 stage crew members 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.
externalconstserenity
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
Ability
Actor
Interaction