Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PageElement<Store>

PageElement is the main building block for all page objects.

Modern websites are usually built with reusable components (eg. in React or Angular) which provide a consistent structure of the component's HTML elements and their behavior.

The goal of PageElements is to also benefit from these advantages by recreating website components as testing components. To do so, PageElement maps the structure of a website's components and provides an api to interact with them.

A big pitfall of scripted browser testing is that a website and its building blocks need to be loaded and rendered before they can be interacted with and all of this takes time. Therefore, browser based tests constantly need to wait for elements of a page to be loaded and rendered or for certain conditions to be met.

PageElements try to overcome these hurdles be performing an "initial waiting condition" before interacting with elements on the page. The supported initial wait conditions include:

  • 'exist' to wait for an element to exist in the DOM
  • 'visible' to wait for an element to become visible (not obscured by other elements, not set to 'hidden')
  • 'text' to wait for an element to have any text

All public functions/actions defined on the PageElement class that interact with an element on the page or that retrieve or check an element's state automatically wait for this initial wait condition to become true before proceeding with any other functionality.

PageElement furthermore provides three apis to:

  • .currently: retrieve or check the current state
  • .wait: wait for a certain state
  • .eventually: check if a certain state is eventually reached within a specific timeout.
template

Store type of the PageNodeStore instance which can be used to retrieve/create PageNodes

Type parameters

Hierarchy

Implements

Index

Constructors

constructor

  • new PageElement(selector: string, __namedParameters: object): PageElement
  • PageElement serves as the main building block for all page objects.

    Modern websites are usually built with reusable components (eg. in React or Angular) which provide a consistent structure of the component's HTML elements and their behavior.

    The goal of PageElements is to also benefit from these advantages by recreating website components as testing components. To do so, PageElement maps the structure of a website's components and provides an api to interact with them.

    A big pitfall of scripted browser testing is that a website and its building blocks need to be loaded and rendered before they can be interacted with and all of this takes time. Therefore, browser based tests constantly need to wait for elements of a page to be loaded and rendered or for certain conditions to be met.

    PageElements try to overcome these hurdles be performing an "initial waiting condition" before interacting with elements on the page. The supported initial wait conditions include:

    • 'exist' to wait for an element to exist in the DOM
    • 'visible' to wait for an element to become visible(not obscured by other elements, not set to 'hidden'...)
    • 'text' to wait for an element to have any text
    • 'value' to wait for an element to have any value

    Functions/actions defined on the PageElement class that interact with an element on the page or that retrieve or check an element's state automatically wait for this initial wait condition to become true before proceeding with any other functionality.

    PageElement furthermore provides three apis to:

    • .currently: retrieve or check the current state
    • .wait: wait for a certain state
    • .eventually: check if a certain state is eventually reached within a specific timeout.

    Parameters

    • selector: string

      the XPath selector used to identify PageElement on the page

    • __namedParameters: object

    Returns PageElement

Properties

Protected _$

_$: Store

_$ provides access to the PageNode retrieval functions of PageElementBase's PageNodeStore and prefixes the selectors of all PageNodes retrieved via _$ with the selector of PageElementBase.

Protected _customScroll

_customScroll: IScrollParams

stores the default custom scrolling behaviour

Protected _interval

_interval: number

the default interval used by PageElement for all of its functions that operate with intervals (eg. wait and eventually)

Protected _lastDiff

_lastDiff: IDiff

Stores the last differences of PageNode's check state functions.

Intended for framework-internal usage only.

Protected _selector

_selector: string

the XPath selector of PageNode

Protected _store

_store: Store

an instance of PageNodeStore which can be used to retrieve/create PageNodes

Protected _timeout

_timeout: number

the default timeout used by PageElement for all of its functions that operate with timeouts (eg. wait and eventually)

Protected _waitType

_waitType: WaitType

Defines the kind of wait condition performed when initialWait is invoked.

The initial wait condition is performed every time before an interaction with the tested application takes place via a PageElement's action (eg. click).

currently

currently: PageElementCurrently<Store, this>

eventually

eventually: PageElementEventually<Store, this>

wait

wait: PageElementWait<Store, this>

Accessors

$

  • get $(): Store

Protected __element

  • get __element(): Client<RawResult<Element>> & RawResult<Element>
  • Fetches the first webdriverio element from the HTML page that is identified by PageElement's XPath selector without performing PageElement's initial waiting condition.

    Returns Client<RawResult<Element>> & RawResult<Element>

__lastDiff

  • get __lastDiff(): IDiff

element

  • get element(): Client<RawResult<Element>> & RawResult<Element>
  • Fetches the first webdriverio element from the HTML page that is identified by PageElement's XPath selector after performing PageElement's initial waiting condition.

    Returns Client<RawResult<Element>> & RawResult<Element>

Methods

__any

  • __any(actual: any): boolean
  • Returns true if actual has any value.

    By default, the comparison is only implemented for the types string, number and boolean.

    If actual is of type number or boolean, this function always returns true unless the value of actual is undefined or null.

    If the implementation is missing for the type of actual, an error will be thrown.

    Parameters

    • actual: any

      an actual value retrieved from the page's state

    Returns boolean

__contains

  • __contains(actual: any, expected: any): boolean
  • Returns true if actual contains expected. Both actual and expected are supposed to be of the same type.

    By default, the comparison is only implemented for the type string. If the implementation is missing for the type of actual and expected, an error will be thrown.

    Parameters

    • actual: any

      an actual value retrieved from the page's state

    • expected: any

      an expected value

    Returns boolean

__equals

  • __equals(actual: any, expected: any): boolean
  • Returns true if actual equals expected. Both actual and expected are supposed to be of the same type.

    By default, the comparison is only implemented for the types string, number, boolean undefined and null.

    If the implementation is missing for the type of actual and expected, an error will be thrown.

    Parameters

    • actual: any

      an actual value retrieved from the page's state

    • expected: any

      an expected value

    Returns boolean

__eventually

  • __eventually(func: function): boolean
  • Provides custom error handling of 'could not be located' and 'WaitUntilTimeoutError' errors for functions that check if a condition returns true within a specific timeout.

    Parameters

    • func: function

      the function which is supposed to return true within a specific timeout

        • (): void
        • Returns void

    Returns boolean

__execute

  • __execute<ResultType>(func: function): ResultType
  • Executes func and trows any errors that occur during its execution.

    If an error occurs because an element could not be located on the page, throws a custom 'could not be located' error message.

    template

    ResultType the result type of the executed function

    Type parameters

    • ResultType

    Parameters

    • func: function

      the function to be executed

        • (): ResultType
        • Returns ResultType

    Returns ResultType

    the result value of the executed function

__getNodeId

  • __getNodeId(): string

__setLastDiff

  • __setLastDiff(diff: IDiff): void

__typeToString

  • __typeToString(value: any): any
  • Converts value to the type string.

    This function is used to write a value of an arbitrary type into error messages and log outputs.

    By default, the comparison is only implemented for the types string, number, boolean, undefined and for the value null.

    If the implementation is missing for the type of value, an error will be thrown.

    Parameters

    • value: any

      the value whose type should be converted

    Returns any

__wait

  • __wait(func: function, errorMessage: string, timeout: number): this
  • Provides custom error handling of 'could not be located' and 'WaitUntilTimeoutError' errors for functions that wait for a condition to become true within a specific timeout and throw an error if the condition does not become true.

    Parameters

    • func: function

      the function which is supposed to return true within a specific timeout and throws an error if the condition does not become true

        • (): boolean
        • Returns boolean

    • errorMessage: string

      an errorMessage that describes the condition which did not become true within a specific timeout

    • timeout: number

      the timeout used to wait for the result of the passed func to return true

    Returns this

    this (an instance of PageNode)

__waitUntil

  • __waitUntil(waitFunc: function, errorMessageFunc: function, timeout: number, interval?: number): this
  • This function executes a waitFunc until it returns true or a specific timeout is reached. If the return value of waitFunc does not become true within the timeout, this function throws a 'WaitUntilTimeoutError'.

    __waitUntil also provides custom error handling for 'could not be located' errors.

    Parameters

    • waitFunc: function

      the function which is supposed to return true within a specific timeout

        • (): boolean
        • Returns boolean

    • errorMessageFunc: function

      a function that returns an errorMessage which describes the condition that did not become true within a specific timeout

        • (): string
        • Returns string

    • timeout: number

      the timeout used to wait for the result of the waitFunc to return true

    • Optional interval: number

      the interval used to check for the result of the waitFunc to return true

    Returns this

    this (an instance of PageNode)

Protected _executeAfterInitialWait

  • _executeAfterInitialWait<ResultType>(func: function): ResultType
  • Executes func after initial wait and, if an error occurs during execution of func, throws a custom error message that the page element could not be located on the page.

    template

    ResultType the type of the executed function's result

    Type parameters

    • ResultType

    Parameters

    • func: function

      the function to be executed after performing the initial wait condition

        • (): ResultType
        • Returns ResultType

    Returns ResultType

Protected _handleWaitError

  • _handleWaitError(error: any, errorMessage: string, timeout: number): void
  • This function implements custom error handling for 'could not be located' and 'WaitUntilTimeoutError' errors.

    Parameters

    • error: any

      an arbitrary type of error

    • errorMessage: string

      used to describe the failed condition check which caused a WaitUntilTimeoutError

    • timeout: number

      the timeout used to wait for an element to be located or for a wait condition to return true

    Returns void

Protected _scrollTo

click

  • Clicks on PageElement after performing PageElement's initial waiting condition.

    Before clicking on PageElement, it is scrolled into the viewport.

    If the clicked HTML element is obscured by another HTML element, the click will be repeated until the clicked HTML element is no longer obscured and can therefore receive the click or until a specific timeout is reached.

    If a postCondition is defined in click's options, the click will be repeated until the postCondition function returns true or until a specific timeout is reached.

    Parameters

    • Default value opts: IClickOpts = {}

      includes options used to configure the behavior of the click function:

      • postCondition: If defined, a click on PageElement will be repeated until the result this function returns true.
      • customScroll: Overwrites the default custom scrolling behavior used by the click function.
      • timeout: Defines how long the PageElement can take to become clickable and the postCondition to be met.
      • interval: The interval used to wait for PageElement to become clickable and the postCondition to be met.

      If no timeout is specified, PageElement's default timeout is used. If no interval is specified, PageElement's default interval is used.

    Returns this

    this (an instance of PageElement)

getAttribute

  • getAttribute(attributeName: string): string
  • Returns PageElement's HTML attribute with the passed attribute name after performing the initial waiting condition.

    Parameters

    • attributeName: string

      the name of the HTML attribute whose value should be returned

    Returns string

getClass

  • getClass(): string

getContainsDirectText

  • getContainsDirectText(directText: string): boolean
  • Returns a PageElement's 'containsDirectText' status after performing the initial waiting condition.

    A PageElement's 'containsDirectText' status is set to true if its actual direct text contains the expected direct text.

    A direct text is a text that resides on the level directly below the selected HTML element. It does not include any text of the HTML element's nested children HTML elements.

    Parameters

    • directText: string

      the expected direct text used in the comparison which sets the 'containsDirectText' status

    Returns boolean

getContainsText

  • getContainsText(text: string): boolean
  • Returns a PageElement's 'containsText' status after performing the initial waiting condition.

    A PageElement's 'containsText' status is set to true if its actual text contains the expected text.

    Parameters

    • text: string

      the expected text used in the comparison which sets the 'containsText' status

    Returns boolean

getDirectText

  • getDirectText(): string
  • Returns PageElement's direct text after performing the initial waiting condition.

    A direct text is a text that resides on the level directly below the selected HTML element. It does not include any text of the HTML element's nested children HTML elements.

    Returns string

getHTML

  • getHTML(): string

getHasAnyDirectText

  • getHasAnyDirectText(): boolean
  • Returns a PageElement's 'hasAnyDirectText' status after performing the initial waiting condition.

    A PageElement's 'hasAnyDirectText' status is set to true if it has any direct text.

    Returns boolean

getHasAnyText

  • getHasAnyText(): boolean

getHasDirectText

  • getHasDirectText(directText: string): boolean
  • Returns a PageElement's 'hasDirectText' status after performing the initial waiting condition.

    A PageElement's 'hasDirectText' status is set to true if its actual direct text equals the expected direct text.

    A direct text is a text that resides on the level directly below the selected HTML element. It does not include any text of the HTML element's nested children HTML elements.

    Parameters

    • directText: string

      the expected direct text used in the comparison which sets the 'hasDirectText' status

    Returns boolean

getHasText

  • getHasText(text: string): boolean
  • Returns a PageElement's 'hasText' status after performing the initial waiting condition.

    A PageElement's 'hasText' status is set to true if its actual text equals the expected text.

    Parameters

    • text: string

      the expected text used in the comparison which sets the 'hasText' status

    Returns boolean

getHeight

  • getHeight(): number

getId

  • getId(): string

getInterval

  • getInterval(): number

getIsEnabled

  • getIsEnabled(): boolean

getLocation

getName

  • getName(): string

getSelector

  • getSelector(): string

getSize

getText

  • getText(): string

getTimeout

  • getTimeout(): number

getWidth

  • getWidth(): number

getX

  • getX(): number

getY

  • getY(): number

initialWait

  • initialWait(): this
  • This function performs PageElement's initial waiting condition.

    It supports the following waiting types:

    • 'exist' to wait for an element to exist in the DOM
    • 'visible' to wait for an element to become visible (not obscured by other elements, not set to 'hidden'...)
    • 'text' to wait for an element to have any text

    Returns this

    this (an instance of PageElement)

scrollTo

toJSON

Generated using TypeDoc