Wait
The Wait class is an action class in the Screenplay pattern designed for use with the @testla/screenplay library. This class enables actors to wait for either a specified loading state or for a selector to become visible/active using the BrowseTheWeb ability provided by Testla.
Extends
This class extends the abstract FrameEnabledAction which extends Action class from Core.
Methods
performAs
public performAs(actor: Actor): Promise<any>;
- Description: Waits for either a specified loading state or for a selector to become visible/active.
- Parameters:
actor- The actor performing this action.
- Returns:
Promise<any>- Resolves when the required load state or selector visibility is reached.
forLoadState
public static forLoadState(state: 'load' | 'domcontentloaded' | 'networkidle'): Wait;
- Description: Creates a new instance of the
Waitclass to wait for a specific status of the page. - Parameters:
state- Either 'load', 'domcontentloaded', or 'networkidle'.
- Returns:
Wait- Returns a newWaitinstance.
forSelector
public static forSelector(selector: Selector, options?: SelectorOptions): Wait;
- Description: Creates a new instance of the
Waitclass to wait for a specific selector to exist. - Parameters:
selector- The selector.options- (optional) Advanced selector lookup options.
- Returns:
Wait- Returns a newWaitinstance.
forEvent
Introduced in: 1.5.0
public static forEvent(event: string): Wait;
- Description: Creates a new instance of the
Waitclass to wait for a specific event. - Parameters:
event- The event.
- Returns:
Wait- Returns a newWaitinstance.
forUrl
Introduced in: 1.8.0
public static forUrl(url: string | RegExp, options): Wait;
- Description: Creates a new instance of the
Waitclass to wait for a specific url. - Parameters:
url- The url.
- Returns:
Wait- Returns a newWaitinstance.
Methods inherited from FrameEnabledAction
inFrame
Introduced in: 1.3.0
A webpage may be associated with multiple Frame objects. Each webpage possesses a primary frame and interactions at the page level
such as clicking, are typically performed within this main frame. In addition to the main frame, a webpage can incorporate extra
frames using the HTML 'iframe' tag. These supplementary frames can be targeted for interactions occurring within the specific frame. To reach elements in those frames you can use the inFrame() method to find the specified frame selector using the BrowseTheWeb ability.
You can also chain frame objects to go down to the inner most iframe using the inFrame() API. Be aware the sequence starts with outer most iframe and goes down to inner most iframe.
public inFrame(frameSelector: FrameSelector): Check;
- Description: Finds the specified frame selector using the
BrowseTheWebability. - Parameters:
frameSelector- The FrameSelector.
- Returns:
Action- Returns the current action.
Usage:
// Find an element in a specific frame
await actor.attemptsTo(
Find.element('#myElement').inFrame('#myFrame'),
);
// Find an element in nested frames
await actor.attemptsTo(
Find.element('#content')
.inFrame('[name="frameTop"]')
.inFrame('[name="frameMiddle"]'),
);
Methods inherited from Core Action
orSkipOnFail
Introduced in core: 0.5.0
public get orSkipOnFail(): Action;
- Description: Allows to skip an action on fail.
- Returns:
Action- Returns the current action.
Usage:
// Would skip the step on error without breaking the execution
await actor.attemptsTo(
Do.something().orSkipOnFail,
);
withAbilityAlias
Introduced in core: 0.3.0
public withAbilityAlias(alias: string): Action;
- Description: Defines the ability alias to be used during execution.
- Parameters:
alias- The alias.
- Returns:
Action- Returns the current action.
Usage:
await actor.attemptsTo(
Do.something().withAbilityAlias('myAlias'),
);