Page
Introduced in: 1.8.0
The Page class is a question class in the Screenplay pattern designed for use with the @testla/screenplay library. This class enables actors to inquire about the state of a browser page, such as url, using the BrowseTheWeb ability provided by Testla.
Extends
This class extends the abstract Question<boolean> class from Core.
Methods
answeredBy
public async answeredBy(actor: Actor): Promise<boolean>;
- Description: Verifies if the page is in the specified state (i.e. url).
- Parameters:
actor- The actor answering this question.
- Returns:
Promise<boolean>- Resolves totruefor a positive check,falsefor a negative check.
toHave
public static get toHave(): Page;
- Description: Creates a new instance of the
Pageclass for a positive check. - Returns:
Page- Returns a newPageinstance.
notToHave
public static get notToHave(): Page;
- Description: Creates a new instance of the
Pageclass for a negative check. - Returns:
Page- Returns a newPageinstance.
url
Introduced in: 1.8.0
public url(url: string | RegExp, options?: { timeout?: number }): Page;
- Description: Verifies if an element has the given text.
- Parameters:
url- The url.options- (optional) Advanced page options.
- Returns:
Page- Returns thisPageinstance.
Methods inherited from Core Question
failAsFalse
Introduced in core: 0.5.0
In some cases you may want to ask questions to find out about the status of the system under test to make decisions on how to move on with your test. In order to not fail a test but receive information about questions being answered negative you can use failAsFalse on a question which then returns a boolean value instead.
public get failAsFalse(): Question;
- Description: Returns false instead of failing when exception occurrs.
- Returns:
Question- Returns the current question.
Usage:
// get evaluation result based on valid check
const evaluationResult = await actor.asks(
MyQuestion.is.asExpected().failAsFalse,
);
// proceed based on answer from above
if (wasLoggedIn === false) {
// some code to be executed on false case
}
withAbilityAlias
Introduced in core: 0.3.0
It happens that there is the need to make use of the same ability but with different settings.
The solution Testla Screenplay offers is Ability Aliasing. With that multiple instances of an ability can be assigned to a user at the same time.
To use an aliased ability in a question you can use the withAbilityAlias method to define the alias to be used during execution.
public withAbilityAlias(alias: string): Question;
- Description: Defines the ability alias to be used during execution.
- Parameters:
alias- The alias.
- Returns:
Question- Returns the current question.
Usage:
await actor.asks(
MyQuestion.is.asExpected().withAbilityAlias('myAlias'),
);