Functions
Static Public Summary | ||
public |
actorCalled(name: string): Actor Instantiates or retrieves an actor Actor
called |
|
public |
Retrieves an actor who was last instantiated or retrieved using actorCalled. |
|
public |
append(values: ...Array<Answerable<string>>): AnswerMappingFunction<string, string> Appends the values to the end of the original string and returns a new string. |
|
public |
commaSeparated(list: Array<string>, map: function(item: string): string, acc: string): string Produces a comma-separated list based on the list provided. |
|
public |
configure(config: SerenityConfig): void Configures Serenity/JS. |
|
public |
Re-configures Serenity/JS with a new Cast of Actors you'd like to use in any subsequent call to actorCalled. This function is an alias for Serenity#engage, which provides an alternative to calling Actor#whoCan directly in your tests and is typically invoked in a "before all" or "before each" hook of your test runner of choice. If your implementation of the Cast interface is stateless, you can invoke this function once before your entire test suite is executed, see
|
|
public |
formatted(templates: TemplateStringsArray, placeholders: Array<Answerable<any>>): string A tag function returning a human-readable description of a template containing one or more Answerables. |
|
public |
Checks if the |
|
public |
inspected(value: Answerable<any>): string Provides a human-readable description of the {@link Answerable<T>}. |
|
public |
isMappable(maybeCollection: Mappable<Item> | any): boolean Checks if the value is a Mappable collection of items. |
|
public |
normalize(form: Answerable<string>): AnswerMappingFunction<string, string> Returns the String value result of normalizing the string into the normalization form named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms. |
|
public |
parse(text: *, reviver: *): * Converts a JavaScript Object Notation (JSON) string into an object. |
|
public |
q(templates: TemplateStringsArray, parameters: Array<Answerable<string|number>>): Question<Promise<string>> A Screenplay-flavour of a tagged template literal,
|
|
public |
replace(pattern: Answerable<string|RegExp>, replacement: Answerable<string|function>): MappingFunction<string, string> Returns a new string with some or all matches of a pattern replaced by a replacement. |
|
public |
slice(startIndex: Answerable<number>, endIndex: Answerable<number>): AnswerMappingFunction<string, string> Extracts the part of the string between the |
|
public |
split(separator: Answerable<string|RegExp>, limit: Answerable<number>): AnswerMappingFunction<string, string> Divides a string into an ordered list of substrings, puts these substrings into an array, and returns the array. |
|
public |
stringify(value: UNKNOWN, replacer: Function, space: undefined | undefined): string |
|
public |
toLocaleLowerCase(locales: Answerable<string|string[]>): AnswerMappingFunction<string, string> Returns the calling string value converted to upper case, according to any locale-specific case mappings. |
|
public |
toLocaleUpperCase(locales: Answerable<string|string[]>): AnswerMappingFunction<string, string> Returns a string where all alphabetic characters have been converted to uppercase, taking into account the host environment's current locale. |
|
public |
toLowerCase(): AnswerMappingFunction<string, string> Converts all the alphabetic characters in a string to lowercase. |
|
public |
toNumber(): AnswerMappingFunction<string, string> Converts a |
|
public |
toUpperCase(): AnswerMappingFunction<string, string> Converts all the alphabetic characters in a string to uppercase. |
|
public |
trim(): AnswerMappingFunction<string, string> Removes whitespace from both ends of a string. |
|
public |
trimmed(templates: TemplateStringsArray, placeholders: Array<string>): string A tag function trimming the leading and trailing whitespace from multi-line strings. |
Static Public
public actorCalled(name: string): Actor source
import {actorCalled} from '@serenity-js/core'
Instantiates or retrieves an actor Actor
called name
if one has already been instantiated.
This method is an alias for Serenity#theActorCalled.
Params:
Name | Type | Attribute | Description |
name | string | The name of the actor to instantiate or retrieve |
Examples:
import 'jasmine';
import { actorCalled } from '@serenity-js/core';
describe('Feature', () => {
it('should have some behaviour', () =>
actorCalled('James').attemptsTo(
// ... activities
));
});
import { actorCalled } from '@serenity-js/core';
import { Given } from 'cucumber';
Given(/(.*?) is a registered user/, (name: string) =>
actorCalled(name).attemptsTo(
// ... activities
));
public actorInTheSpotlight(): Actor source
import {actorInTheSpotlight} from '@serenity-js/core'
Retrieves an actor who was last instantiated or retrieved using actorCalled.
This function is particularly useful when automating Cucumber scenarios.
This function is an alias for Serenity#theActorInTheSpotlight.
Examples:
import { actorCalled } from '@serenity-js/core';
import { Given, When } from 'cucumber';
Given(/(.*?) is a registered user/, (name: string) =>
actorCalled(name).attemptsTo(
// ... activities
));
When(/(?:he|she|they) browse their recent orders/, () =>
actorInTheSpotlight().attemptsTo(
// ... activities
));
See:
public append(values: ...Array<Answerable<string>>): AnswerMappingFunction<string, string> source
import {append} from '@serenity-js/core/lib/screenplay/questions/mappings/string'
Appends the values to the end of the original string and returns a new string.
Params:
Name | Type | Attribute | Description |
values | ...Array<Answerable<string>> | The values to append to the end of the string. |
Returns:
AnswerMappingFunction<string, string> |
Tests:
public commaSeparated(list: Array<string>, map: function(item: string): string, acc: string): string source
import {commaSeparated} from '@serenity-js/core/lib/io'
Produces a comma-separated list based on the list provided.
Params:
Name | Type | Attribute | Description |
list | Array<string> | ||
map | function(item: string): string | ||
acc | string |
|
acc |
Returns:
string |
public configure(config: SerenityConfig): void source
import {configure} from '@serenity-js/core'
Configures Serenity/JS. Every call to this function replaces the previous configuration provided, so this function should called be exactly once in your test suite.
This function is an alias for Serenity#configure.
Params:
Name | Type | Attribute | Description |
config | SerenityConfig |
Returns:
void |
public engage(actors: Cast): void source
import {engage} from '@serenity-js/core'
Re-configures Serenity/JS with a new Cast of Actors you'd like to use in any subsequent call to actorCalled.
This function is an alias for Serenity#engage, which provides an alternative to calling Actor#whoCan directly in your tests and is typically invoked in a "before all" or "before each" hook of your test runner of choice.
If your implementation of the Cast interface is stateless, you can invoke this function once before your entire test suite is executed, see
beforeAll
in Jasmine,before
in Mocha,BeforeAll
in Cucumber.jsHowever, if your Cast holds state that you want reset before each scenario, it's better to invoke
engage
before each test using:beforeEach
in JasminebeforeEach
in Mocha,Before
in Cucumber.js
Params:
Name | Type | Attribute | Description |
actors | Cast |
Returns:
void |
Examples:
import { Actor, Cast } from '@serenity-js/core';
class Actors implements Cast {
prepare(actor: Actor) {
return actor.whoCan(
// ... abilities you'd like the Actor to have
);
}
}
engage(new Actors();
import 'jasmine';
beforeEach(() => engage(new Actors()));
import { Before } from 'cucumber';
Before(() => engage(new Actors());
See:
public formatted(templates: TemplateStringsArray, placeholders: Array<Answerable<any>>): string source
import {formatted} from '@serenity-js/core/lib/io'
A tag function returning a human-readable description of a template containing one or more Answerables.
Params:
Name | Type | Attribute | Description |
templates | TemplateStringsArray | ||
placeholders | Array<Answerable<any>> |
Returns:
string |
public has(api: object): boolean source
import {has} from '@serenity-js/core/lib/io/reflection'
Checks if the candidate
value "quacks like a duck".
In particular, it checks if the candidate
:
- is not
null
- is not
undefined
- has expected methods or fields (evaluated via
typeof
)
Params:
Name | Type | Attribute | Description |
api | object | An object where the keys are names of member fields and methods expected on the |
Returns:
boolean |
Examples:
const looksLikeADuck = has({
name: 'string',
quack: 'function',
})
const daisy = {
name: 'Daisy',
quack: () => 'quack',
}
looksLikeADuck(daisy) // true
public inspected(value: Answerable<any>): string source
import {inspected} from '@serenity-js/core/lib/io'
Provides a human-readable description of the {@link Answerable<T>}. Similar to util~inspect.
Params:
Name | Type | Attribute | Description |
value | Answerable<any> |
Returns:
string |
public isMappable(maybeCollection: Mappable<Item> | any): boolean source
import {isMappable} from '@serenity-js/core/lib/io/collections'
Checks if the value is a Mappable collection of items.
Params:
Name | Type | Attribute | Description |
maybeCollection | Mappable<Item> | any |
Returns:
boolean |
Examples:
import { Mappable } from '@serenity-js/core/lib/io';
Mappable.isMappable([ 1, 2, 3 ]) === true
import { Mappable } from '@serenity-js/core/lib/io';
import { element } from 'protractor';
Mappable.isMappable(element.all(by.tagName('li')) === true
public normalize(form: Answerable<string>): AnswerMappingFunction<string, string> source
import {normalize} from '@serenity-js/core/lib/screenplay/questions/mappings/string'
Returns the String value result of normalizing the string into the normalization form named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms.
Params:
Name | Type | Attribute | Description |
form | Answerable<string> |
|
One of "NFC", "NFD", "NFKC", or "NFKD", specifying the Unicode Normalization Form. If omitted or undefined, "NFC" is used. These values have the following meanings: "NFC" - Canonical Decomposition, followed by Canonical Composition. "NFD" - Canonical Decomposition. "NFKC" - Compatibility Decomposition, followed by Canonical Composition. "NFKD" - Compatibility Decomposition. |
Returns:
AnswerMappingFunction<string, string> |
public parse(text: *, reviver: *): * source
import {parse} from '@serenity-js/core/lib/io/json'
Converts a JavaScript Object Notation (JSON) string into an object. Supports objects with cyclic references.
Params:
Name | Type | Attribute | Description |
text | * | A valid JSON string. |
|
reviver | * | A function that transforms the results. This function is called for each member of the object. If a member contains nested objects, the nested objects are transformed before the parent object is. |
Returns:
* |
public q(templates: TemplateStringsArray, parameters: Array<Answerable<string|number>>): Question<Promise<string>> source
import {q} from '@serenity-js/core/lib/screenplay/questions'
A Screenplay-flavour of a tagged template literal,
q
is a tag function capable of resolving any Answerable<string | number>
you parametrise it with (i.e. a Question).
Params:
Name | Type | Attribute | Description |
templates | TemplateStringsArray | ||
parameters | Array<Answerable<string|number>> |
Examples:
import { q, actorCalled } from '@serenity-js/core';
import { Send, DeleteRequest } from '@serenity-js/rest';
actorCalled('Alice').attemptsTo(
Send.a(DeleteRequest.to(
q `/articles/${ Text.of(Article.id()) }`
))
)
import { q, actorCalled } from '@serenity-js/core';
import { Send, DeleteRequest } from '@serenity-js/rest';
actorCalled('Alice').attemptsTo(
Send.a(DeleteRequest.to(
q `/articles/${ Text.of(Article.id()) }`.describedAs('/articles/:id')
))
)
Tests:
See:
public replace(pattern: Answerable<string|RegExp>, replacement: Answerable<string|function>): MappingFunction<string, string> source
import {replace} from '@serenity-js/core/lib/screenplay/questions/mappings/string'
Returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match. If pattern is a string, only the first occurrence will be replaced.
Params:
Name | Type | Attribute | Description |
pattern | Answerable<string|RegExp> | ||
replacement | Answerable<string|function> |
Returns:
MappingFunction<string, string> |
public slice(startIndex: Answerable<number>, endIndex: Answerable<number>): AnswerMappingFunction<string, string> source
import {slice} from '@serenity-js/core/lib/screenplay/questions/mappings/string'
Extracts the part of the string between the startIndex
and endIndex
indexes, or to the end of the string if endIndex
is undefined
.
Params:
Name | Type | Attribute | Description |
startIndex | Answerable<number> | The zero-based index at which to begin extraction. If negative, it is treated as If |
|
endIndex | Answerable<number> |
|
The zero-based index before which to endIndex extraction. The character at this index will not be included. If If negative, it is treated as |
Returns:
AnswerMappingFunction<string, string> |
public split(separator: Answerable<string|RegExp>, limit: Answerable<number>): AnswerMappingFunction<string, string> source
import {split} from '@serenity-js/core/lib/screenplay/questions/mappings/string'
Divides a string into an ordered list of substrings, puts these substrings into an array, and returns the array. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method's call.
Params:
Name | Type | Attribute | Description |
separator | Answerable<string|RegExp> | The pattern describing where each split should occur. The separator can be a simple string or it can be a regular expression. |
|
limit | Answerable<number> |
|
A non-negative integer specifying a limit on the number of substrings to be included in the array. If provided, splits the string at each occurrence of the specified separator, but stops when limit entries have been placed in the array. Any leftover text is not included in the array at all. |
Returns:
AnswerMappingFunction<string, string> |
public stringify(value: UNKNOWN, replacer: Function, space: undefined | undefined): string source
import {stringify} from '@serenity-js/core/lib/io/json'
Params:
Name | Type | Attribute | Description |
value | UNKNOWN | ||
replacer | Function | ||
space | undefined | undefined |
Returns:
string |
public toLocaleLowerCase(locales: Answerable<string|string[]>): AnswerMappingFunction<string, string> source
import {toLocaleLowerCase} from '@serenity-js/core/lib/screenplay/questions/mappings/string'
Returns the calling string value converted to upper case, according to any locale-specific case mappings.
Params:
Name | Type | Attribute | Description |
locales | Answerable<string|string[]> |
|
The |
Returns:
AnswerMappingFunction<string, string> |
public toLocaleUpperCase(locales: Answerable<string|string[]>): AnswerMappingFunction<string, string> source
import {toLocaleUpperCase} from '@serenity-js/core/lib/screenplay/questions/mappings/string'
Returns a string where all alphabetic characters have been converted to uppercase, taking into account the host environment's current locale.
Params:
Name | Type | Attribute | Description |
locales | Answerable<string|string[]> |
|
The |
Returns:
AnswerMappingFunction<string, string> |
public toLowerCase(): AnswerMappingFunction<string, string> source
import {toLowerCase} from '@serenity-js/core/lib/screenplay/questions/mappings/string'
Converts all the alphabetic characters in a string to lowercase.
Returns:
AnswerMappingFunction<string, string> |
public toNumber(): AnswerMappingFunction<string, string> source
import {toNumber} from '@serenity-js/core/lib/screenplay/questions/mappings/string'
Converts a string
to a number
.
Returns:
AnswerMappingFunction<string, string> |
public toUpperCase(): AnswerMappingFunction<string, string> source
import {toUpperCase} from '@serenity-js/core/lib/screenplay/questions/mappings/string'
Converts all the alphabetic characters in a string to uppercase.
Returns:
AnswerMappingFunction<string, string> |
public trim(): AnswerMappingFunction<string, string> source
import {trim} from '@serenity-js/core/lib/screenplay/questions/mappings/string'
Removes whitespace from both ends of a string. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).
Returns:
AnswerMappingFunction<string, string> |
public trimmed(templates: TemplateStringsArray, placeholders: Array<string>): string source
import {trimmed} from '@serenity-js/core/lib/io'
A tag function trimming the leading and trailing whitespace from multi-line strings.
Params:
Name | Type | Attribute | Description |
templates | TemplateStringsArray | ||
placeholders | Array<string> |
Returns:
string |