The Element
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 web element, such as visibility, enabled state, text, or value, using the BrowseTheWeb
ability provided by Testla.
public async answeredBy(actor: Actor): Promise<boolean>;
- Description: Verifies if an element is in the specified state (visible, enabled, has text, or has value).
- Parameters:
actor
- The actor answering this question.
- Returns:
Promise<boolean>
- Resolves totrue
for a positive check,false
for a negative check.
public static get toBe(): Element;
- Description: Creates a new instance of the
Element
class for a positive check. - Returns:
Element
- Returns a newElement
instance.
public static get notToBe(): Element;
- Description: Creates a new instance of the
Element
class for a negative check. - Returns:
Element
- Returns a newElement
instance.
public static get toHave(): Element;
- Description: Alias for
toBe
. Creates a new instance of theElement
class for a positive check. - Returns:
Element
- Returns a newElement
instance.
public static get notToHave(): Element;
- Description: Alias for
notToBe
. Creates a new instance of theElement
class for a negative check. - Returns:
Element
- Returns a newElement
instance.
public visible(selector: Selector, options?: SelectorOptions): Element;
- Description: Verifies if an element is visible.
- Parameters:
selector
- The selector.options
- (optional) Advanced selector lookup options.
- Returns:
Element
- Returns thisElement
instance.
public enabled(selector: Selector, options?: SelectorOptions): Element;
- Description: Verifies if an element is enabled.
- Parameters:
selector
- The selector.options
- (optional) Advanced selector lookup options.
- Returns:
Element
- Returns thisElement
instance.
public enabled(selector: Selector, options?: SelectorOptions): Element;
- Description: Verifies if an element is checked.
- Parameters:
selector
- The selector.options
- (optional) Advanced selector lookup options.
- Returns:
Element
- Returns thisElement
instance.
public text(selector: Selector, text: string | RegExp | (string | RegExp)[], options?: SelectorOptions): Element;
- Description: Verifies if an element has the given text.
- Parameters:
selector
- The selector.text
- The text to check.options
- (optional) Advanced selector lookup options.
- Returns:
Element
- Returns thisElement
instance.
public value(selector: Selector, value: string | RegExp, options?: SelectorOptions): Element;
- Description: Verifies if an element has the given value.
- Parameters:
selector
- The selector.value
- The value to check.options
- (optional) Advanced selector lookup options.
- Returns:
Element
- Returns thisElement
instance.
public count(selector: Selector, desiredCount: number, options?: SelectorOptions): Element;
- Description: Verifies if an element has a desired count.
- Parameters:
selector
- The selector.desiredCount
- The desired count.options
- (optional) Advanced selector lookup options.
- Returns:
Element
- Returns thisElement
instance.
public minCount(selector: Selector, minimumCount: number, options?: SelectorOptions): Element;
- Description: Verifies if an element has a minimum count.
- Parameters:
selector
- The selector.minimumCount
- The minimum count.options
- (optional) Advanced selector lookup options.
- Returns:
Element
- Returns thisElement
instance.
public inFrame(frameSelector: FrameSelector): Element;
- Description: Finds the specified frame selector using the
BrowseTheWeb
ability. - Parameters:
frameSelector
- The FrameSelector.
- Returns:
Element
- Returns the current action.
public withAbilityAlias(alias: string): Element;
- Description: Defines the ability alias to be used during execution.
- Parameters:
alias
- The alias.
- Returns:
Element
- Returns the current question.
Introduced in: 1.6.0
public get failAsFalse(): Element;
- Description: Returns false instead of failing when exception occurrs.
- Returns:
Element
- Returns the current question.