This class represents the actor's ability to use a Browser. This ability enables the actor to interact with the browser and browse web user interfaces.

Hierarchy

  • Ability
    • BrowseTheWeb

Properties

alias?: string
name: string

Name with which the ability is identified internally on actor level.

Methods - Factory

Methods - Other

  • Parameters

    • name: string

    Returns this

Methods - called internally

  • Use this Ability as an Actor. Required by Actions to get access to the ability functions.

    Parameters

    • actor: Actor

      Actor is using this ability

    • Optional alias: string

    Returns BrowseTheWeb

    Returns the ability to use a browser

Methods - getter

Methods - related to cookies

  • Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be obtained via BrowseTheWeb.getCookies([urls]).

    Parameters

    • cookies: Cookie[]

      Cookies to add at browser context

    Returns Promise<void>

    Returns after adding cookies into this browser context.

    Example

    await BrowseTheWeb.as(actor).addCookies([{
    name: 'my cookie',
    value: 'my value',
    url: 'http://www.myapp.com',
    }]);
  • Clear the browser context cookies.

    Returns Promise<void>

    Clears context cookies.

    Example

    await BrowseTheWeb.as(actor).clearCookies();
    
  • Get the cookies of the current browser context. If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs are returned.

    Parameters

    • Optional urls: string | string[]

      affected urls

    Returns Promise<Cookie[]>

    Returns the cookies of the current browser context.

    Example

    get all cookies

    await BrowseTheWeb.as(actor).getCookies();
    

    get cookies for one single domain

    await BrowseTheWeb.as(actor).getCookies('https://example.com');
    

    get cookies for two domains

    await BrowseTheWeb.as(actor).getCookies(['https://example.com', 'https://www.com']);
    

Methods - related to storage

  • Get a local storage item specified by the given key.

    Parameters

    • key: string

      the key that specifies the item.

    Returns Promise<any>

    Returns the local storage item

    Example

    await BrowseTheWeb.as(actor).getLocalStorageItem('some key');
    
  • Get a session storage item specified by given key.

    Parameters

    • key: string

      the key that specifies the item.

    Returns Promise<any>

    Retrieves a session storage item

    Example

    await BrowseTheWeb.as(actor).getSessionStorageItem('some key');
    
  • Delete a local storage item, if a key/value pair with the given key exists.

    Parameters

    • key: string

      the key that specifies the item.

    Returns Promise<void>

    Returns after deleting a local storage item

    Example

    await BrowseTheWeb.as(actor).removeLocalStorageItem('some key');
    
  • Delete a session storage item, if a key/value pair with the given key exists.

    Parameters

    • key: string

      the key that specifies the item.

    Returns Promise<void>

    Returns after removing a session storage item.

    Example

    await BrowseTheWeb.as(actor).removeSessionStorageItem('some key');
    
  • Save storage state for this browser context, contains current cookies and local storage snapshot.

    Parameters

    • path: string

      The file path to save the storage state to.

    Returns Promise<Object>

    Returns storage state.

    Example

    await BrowseTheWeb.as(actor).removeSessionStorageItem('some key');
    
  • Set a local storage item identified by the given key + value, creating a new key/value pair if none existed for key previously.

    Parameters

    • key: string

      the key that specifies the item.

    • value: any

      the value to set.

    Returns Promise<void>

    Returns after adding the local storage item

    Example

    await BrowseTheWeb.as(actor).setLocalStorageItem('some key', 'some value');
    
  • Set a session storage item identified by the given key + value, creating a new key/value pair if none existed for key previously.

    Parameters

    • key: string

      the key that specifies the item.

    • value: any

      the value to set.

    Returns Promise<void>

    Set the session storage item

    Example

    await BrowseTheWeb.as(actor).setSessionStorageItem('some key', 'some value');
    

Methods - to ensure

  • Verify if the given element is checked.

    Parameters

    • locator: Locator

      the locator of the element.

    • positive: boolean

      whether to check the property of the locator positive or not.

    • Optional options: {
          checked?: boolean;
          timeout?: number;
      }
      • Optional checked?: boolean
      • Optional timeout?: number

        Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.

    Returns Promise<boolean>

    true if the element is checked/not as expected, false if the timeout was reached.

  • Verify if a locator on the page is editable or not.

    Parameters

    • locator: Locator

      the locator to search for.

    • positive: boolean

      whether to check the state of the locator positive or not.

    • Optional options: {
          editable?: boolean;
          timeout?: number;
      }

      (optional) options for assertion.

      • Optional editable?: boolean
      • Optional timeout?: number

        Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.

    Returns Promise<boolean>

    true if the element is editable/not as expected, false if the timeout was reached.

    Example

    simple call with just locator

    await BrowseTheWeb.as(actor).checkEditableState(
    page.locator('myLocator'),
    true
    );

    with options

    await BrowseTheWeb.as(actor).checkEditableState(
    page.locator('myLocator'),
    false,
    { timeout: 1000 }
    );
  • Verify if a locator on the page is enabled or disabled.

    Parameters

    • locator: Locator

      the locator to search for.

    • positive: boolean

      whether to check the state of the locator positive or not.

    • Optional options: {
          enabled?: boolean;
          timeout?: number;
      }

      (optional) options for assertion.

      • Optional enabled?: boolean
      • Optional timeout?: number

        Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.

    Returns Promise<boolean>

    true if the element is enabled/disabled as expected, false if the timeout was reached.

    Example

    simple call with just locator

    await BrowseTheWeb.as(actor).checkEnabledState(
    page.locator('myLocator'),
    true
    );

    with options

    await BrowseTheWeb.as(actor).checkEnabledState(
    page.locator('myLocator'),
    false,
    { timeout: 1000 }
    );
  • Verify if a locator on the page is focused or not.

    Parameters

    • locator: Locator

      the locator to search for.

    • positive: boolean

      whether to check the property of the locator positive or not.

    • Optional options: {
          timeout?: number;
      }

      (optional) options for assertion.

      • Optional timeout?: number

        Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.

    Returns Promise<boolean>

    true if the element is editable/not as expected, false if the timeout was reached.

    Example

    simple call with just locator

    await BrowseTheWeb.as(actor).checkFocusedState(
    page.locator('myLocator'),
    true
    );

    with options

    await BrowseTheWeb.as(actor).checkFocusedState(
    page.locator('myLocator'),
    false,
    { timeout: 1000 }
    );
  • Verify if the given element contains the given text or not.

    Parameters

    • locator: Locator

      the locator of the element to hover over.

    • text: string | RegExp | (string | RegExp)[]

      the text to check.

    • positive: boolean

      whether to check the property of the locator positive or not.

    • Optional options: {
          ignoreCase?: boolean;
          timeout?: number;
          useInnerText?: boolean;
      }

      (optional) options for assertion.

      • Optional ignoreCase?: boolean

        Whether to perform case-insensitive match. ignoreCase option takes precedence over the corresponding regular expression flag if specified.

      • Optional timeout?: number

        Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.

      • Optional useInnerText?: boolean

        Whether to use element.innerText instead of element.textContent when retrieving DOM node text.

    Returns Promise<boolean>

  • Verify if the given element has the given CSS or not.

    Parameters

    • locator: Locator

      the locator of the element to hover over.

    • style: {
          name: string;
          value: (string | RegExp) & (undefined | string | RegExp);
      }

      the style name and value to check.

      • name: string
      • value: (string | RegExp) & (undefined | string | RegExp)
    • positive: boolean

      whether to check the property of the locator positive or not.

    • Optional options: {
          timeout?: number;
      }

      (optional) options for assertion.

      • Optional timeout?: number

        Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.

    Returns Promise<boolean>

    true if the element has CSS/not as expected, false if the timeout was reached.

  • Verify if the element has exact number of DOM node.

    Parameters

    • locator: Locator

      the locator of the element.

    • count: number

      the minimum count of the element to be visible.

    • positive: boolean

      whether to check the property of the locator positive or not.

    • Optional options: {
          timeout?: number;
      }

      (optional) options for assertion.

      • Optional timeout?: number

        Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.

    Returns Promise<boolean>

    true if the element has exact number of DOM node, false if the timeout was reached.

  • Verify if the given element has the given screenshot or not.

    Parameters

    • locator: Locator

      the locator of the element to hover over.

    • name: string | string[]

      the screenshot name.

    • positive: boolean

      whether to check the property of the locator positive or not.

    • Optional options: {
          animations?: "disabled" | "allow";
          caret?: "hide" | "initial";
          mask?: Locator[];
          maskColor?: string;
          maxDiffPixelRatio?: number;
          maxDiffPixels?: number;
          omitBackground?: boolean;
          scale?: "css" | "device";
          threshold?: number;
          timeout?: number;
      }

      (optional) options for assertion.

      • Optional animations?: "disabled" | "allow"

        When set to "disabled", stops CSS animations, CSS transitions and Web Animations. Animations get different treatment depending on their duration:

        • finite animations are fast-forwarded to completion, so they'll fire transitionend event.
        • infinite animations are canceled to initial state, and then played over after the screenshot.

        Defaults to "disabled" that disables animations.

      • Optional caret?: "hide" | "initial"

        When set to "hide", screenshot will hide text caret. When set to "initial", text caret behavior will not be changed. Defaults to "hide".

      • Optional mask?: Locator[]

        Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box #FF00FF (customized by maskColor) that completely covers its bounding box.

      • Optional maskColor?: string

        Specify the color of the overlay box for masked elements, in CSS color format. Default color is pink #FF00FF.

      • Optional maxDiffPixelRatio?: number

        An acceptable ratio of pixels that are different to the total amount of pixels, between 0 and 1. Default is configurable with TestConfig.expect. Unset by default.

      • Optional maxDiffPixels?: number

        An acceptable amount of pixels that could be different. Default is configurable with TestConfig.expect. Unset by default.

      • Optional omitBackground?: boolean

        Hides default white background and allows capturing screenshots with transparency. Not applicable to jpeg images. Defaults to false.

      • Optional scale?: "css" | "device"

        When set to "css", screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this will keep screenshots small. Using "device" option will produce a single pixel per each device pixel, so screenshots of high-dpi devices will be twice as large or even larger.

        Defaults to "css".

      • Optional threshold?: number

        An acceptable perceived color difference in the YIQ color space between the same pixel in compared images, between zero (strict) and one (lax), default is configurable with TestConfig.expect. Defaults to 0.2.

      • Optional timeout?: number

        Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.

    Returns Promise<boolean>

    true if the element has screenshot/not as expected, false if the timeout was reached.

  • Verify if the given element has the given text or not.

    Parameters

    • locator: Locator

      the locator of the element to hover over.

    • text: string | RegExp | (string | RegExp)[]

      the text to check.

    • positive: boolean

      whether to check the property of the locator positive or not.

    • Optional options: {
          ignoreCase?: boolean;
          timeout?: number;
          useInnerText?: boolean;
      }

      options for assertion.

      • Optional ignoreCase?: boolean

        Whether to perform case-insensitive match. ignoreCase option takes precedence over the corresponding regular expression flag if specified.

      • Optional timeout?: number

        Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.

      • Optional useInnerText?: boolean

        Whether to use element.innerText instead of element.textContent when retrieving DOM node text.

    Returns Promise<boolean>

    true if the element has text/not as expected, false if the timeout was reached.

  • Verify if the given element has the given input value or not.

    Parameters

    • locator: Locator

      the locator of the element to hover over.

    • value: string | RegExp

      the single value to check.

    • positive: boolean

      whether to check the property of the locator positive or not.

    • Optional options: {
          timeout?: number;
      }

      (optional) options for assertion.

      • Optional timeout?: number

        Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.

    Returns Promise<boolean>

    true if the element has value/not as expected, false if the timeout was reached.

  • Verify if the page has specified title.

    Parameters

    • positive: boolean

      whether to check the property of the page positive or not.

    • name: string | string[]

      the screenshot name

    • Optional options: {
          timeout?: number;
      }

      (optional) options for assertion.

      • Optional timeout?: number
    • Optional page: Page

      (optional) the playwright page object to verify.

    Returns Promise<boolean>

    Promise true if the page has title as expected, false if the timeout was reached.

  • Verify if the page has specified title.

    Parameters

    • positive: boolean

      whether to check the property of the page positive or not.

    • expectedTitle: string | RegExp

      the expected title of the page.

    • Optional options: {
          timeout?: number;
      }

      (optional) options for assertion.

      • Optional timeout?: number
    • Optional page: Page

      (optional) the playwright page object to verify.

    Returns Promise<boolean>

    Promise true if the page has title as expected, false if the timeout was reached.

  • Verify if the page has specified URL.

    Parameters

    • positive: boolean

      whether to check the property of the page positive or not.

    • expectedUrl: string | RegExp

      the expected url of the page.

    • Optional options: {
          timeout?: number;
      }

      (optional) options for assertion.

      • Optional timeout?: number
    • Optional page: Page

      (optional) the playwright page object to verify.

    Returns Promise<boolean>

    Promise true if the page has URL as expected, false if the timeout was reached.

  • Verify if a locator on the page is visible or hidden.

    Parameters

    • locator: Locator

      the locator to search for.

    • positive: boolean

      whether to check the visibility of the locator positive or not.

    • Optional options: {
          timeout?: number;
          visible?: boolean;
      }

      (optional) options for assertion.

      • Optional timeout?: number

        Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.

      • Optional visible?: boolean

    Returns Promise<boolean>

    Promise true if the element is visible/hidden as expected, false if the timeout was reached.

    Example

    simple call with just locator

    await BrowseTheWeb.as(actor).checkVisibilityState(
    page.locator('myLocator'),
    true
    );

    with options

    await BrowseTheWeb.as(actor).checkVisibilityState(
    page.locator('myLocator'),
    false,
    { timeout: 1000 }
    );

Methods - to interact

  • Brings page to front to activate it.

    Parameters

    • page: Page

    Returns Promise<void>

    Example

    await BrowseTheWeb.as(actor).bringToFront(page);
    
  • Check the specified checkbox.

    Parameters

    • locator: Locator

      the locator of the checkbox.

    • Optional options: CheckActionOptions

      (optional) options for interaction.

    Returns Promise<void>

    Returns after checking the element

    Example

    simple call with just locator

    await BrowseTheWeb.as(actor).checkBox(page.locator('myLocator'));
    

    call with options

    await BrowseTheWeb.as(actor)
    .checkBox(
    page.locator('myLocator'),
    { timeout: 1000 }
    );
  • Click the element specified by the locator.

    Parameters

    • locator: Locator

      the locator of the element to click.

    • Optional options: ClickActionOptions

      (optional) options for interaction.

    Returns Promise<void>

    Returns after clicking the element

    Example

    simple call with just locator

    await BrowseTheWeb.as(actor).click(
    page.locator('myLocator')
    );

    with options

    await BrowseTheWeb.as(actor).click(
    page.locator('myLocator'),
    { timeout: 1000 }
    );
  • Double click the element specified by the locator.

    Parameters

    • locator: Locator

      the locator of the element to double click.

    • Optional options: DblclickActionOptions

      (optional) options for interaction.

    Returns Promise<void>

    Returns after double clicking the element

    Example

    simple call with just locator

    await BrowseTheWeb.as(actor).dblclick(
    page.locator('myLocator')
    );

    with options

    await BrowseTheWeb.as(actor).dblclick(
    page.locator('myLocator'),
    { timeout: 1000 }
    );
  • Drag the specified source element to the specified target element and drop it.

    Parameters

    • sourceLocator: Locator

      the locator of the source element.

    • targetLocator: Locator

      the locator of the target element.

    • Optional options: DragAndDropActionOptions

      (optional) options for interaction.

    Returns Promise<void>

    Returns after dragging the locator to another target locator or target position

    Example

    simple call with just source and target locator

    await BrowseTheWeb.as(actor).dragAndDrop(
    page.locator('sourceLocator'),
    page.locator('targetLocator')
    );

    with options

    await BrowseTheWeb.as(actor).dragAndDrop(
    page.locator('sourceLocator'),
    page.locator('targetLocator'),
    { timeout: 1000 }
    );
  • Fill the element specified by the locator with the given input.

    Parameters

    • locator: Locator

      the locator of the source element.

    • input: string

      the input to fill the element with.

    • Optional options: FillActionOptions

      (optional) options for interaction.

    Returns Promise<void>

    Returns after checks, focuses the element, fills it and triggers an input event after filling.

    Example

    simple call with just locator and input value

    await BrowseTheWeb.as(actor).fill(
    page.locator('myLocator'),
    'myInput'
    );

    with options

    await BrowseTheWeb.as(actor).fill(
    page.locator('myLocator'),
    'myInput',
    { timeout: 1000 }
    );
  • Focus the element specified by the locator.

    Parameters

    • locator: Locator

      the locator of the element to focus.

    • Optional options: {
          timeout?: number;
      }

      (optional) options for interaction.

      • Optional timeout?: number

    Returns Promise<void>

    Returns after focus the element

    Example

    simple call with just locator

    await BrowseTheWeb.as(actor).focus(
    page.locator('myLocator')
    );

    with options

    await BrowseTheWeb.as(actor).focus(
    page.locator('myLocator'),
    { timeout: 1000 }
    );
  • Use the page to navigate to the specified URL.

    Parameters

    • url: string

      the url to access.

    • Optional options: NavigateActionOptions

      (optional) options for interaction.

    Returns Promise<null | Response>

    Returns the main resource response

    Example

    await BrowseTheWeb.as(actor).goto('myURL');
    
  • Use the page mouse to hover over the specified element.

    Parameters

    Returns Promise<void>

    Returns when hovered over the element

    Example

    simple call with just locator

    await BrowseTheWeb.as(actor).hover(page.locator("myLocator"));
    

    with options

    await BrowseTheWeb.as(actor).hover(page.locator("myLocator"), {
    modifiers: ['Alt', 'Shift']
    });
  • Press the specified key(s) on the keyboard.

    Parameters

    • input: string

      the key(s). multiple keys can be pressed by concatenating with "+"

    • Optional options: PressActionOptions

      (optional) options for interaction.

    Returns Promise<void>

    Returns when the key can specify the intended value or a single character to generate the text for.

    Example

    Press a single button

    await BrowseTheWeb.as(actor).press('A');
    

    Press multiple buttons

    await BrowseTheWeb.as(actor).press('Control+A');
    
  • Press the specified keys sequentially for each string character. To press a special key, like Control or ArrowDown, use press.

    Parameters

    • locator: Locator

      the locator of the source element.

    • input: string

      string of characters to sequentially press into a focused element

    • Optional options: PressActionOptions

      (optional) options for interaction.

    Returns Promise<void>

    Returns when the keys can specify the intended values or characters to generate the text for.

    Example

    simple call with just locator and input value

    await BrowseTheWeb.as(actor).pressSequentially('ABC');
    
  • Reload the current page.

    Parameters

    Returns Promise<null | Response>

    Returns the main resource response

    Example

    await BrowseTheWeb.as(actor).reload();
    
  • Set the value of a Locator of type select to the given option.

    Parameters

    • locator: Locator

      the string representing the (select) locator.

    • values: string | string[] | {
          index?: number;
          label?: string;
          value?: string;
      } | {
          index?: number;
          label?: string;
          value?: string;
      }[]

      options to select.

    • Optional options: SelectActionOptions

      (optional) options for interaction.

    Returns Promise<string[]>

    Returns the array of option values that have been successfully selected.

    Example

    simple call with just locator and input value

    await BrowseTheWeb.as(actor).selectOption(
    page.locator('myLocator'),
    'myOptionLabel'
    );

    with options

    await BrowseTheWeb.as(actor).selectOption(
    page.locator('myLocator'),
    'myOptionLabel'
    { timeout: 1000 }
    );
  • Type the given input into the element specified by the locator.

    Parameters

    • locator: Locator

      the locator of the source element.

    • input: string

      the input to type into the element.

    • Optional options: TypeActionOptions

      (optional) options for interaction.

    Returns Promise<void>

    Focuses the element, and then sends a keydown, keypress/input, and keyup event for each character in the text.

    Deprecated

    In most cases, you should use fill instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use pressSequentially.

    Example

    simple call with just locator and input value

    await BrowseTheWeb.as(actor).type(
    page.locator('myLocator'),
    'myInput'
    );

    with options

    await BrowseTheWeb.as(actor).type(
    page.locator('myLocator'),
    'myInput',
    { timeout: 1000 }
    );
  • Wait for the specified event in browser.

    Parameters

    • event: string

      the event in browser to wait for.

    • Optional options: WaitForEventActionOptions<Page | Response | BrowserContext | ConsoleMessage | Dialog | Request | WebError | Worker>

      (optional) options for interaction.

    Returns Promise<Page | Response | BrowserContext | ConsoleMessage | Dialog | Request | WebError | Worker>

    Returns the event data value.

    Example

    await BrowseTheWeb.as(actor).waitForEvent('page');
    
  • Wait for the specified event on page.

    Parameters

    • event: string

      the event on page to wait for.

    • Optional options: WaitForEventActionOptions<Error | Page | Response | ConsoleMessage | Dialog | Request | Worker | Download | FileChooser | Frame | WebSocket>

      (optional) options for interaction.

    Returns Promise<Error | Page | Response | ConsoleMessage | Dialog | Request | Worker | Download | FileChooser | Frame | WebSocket>

    Returns the event data value.

    Example

    await BrowseTheWeb.as(actor).waitForEventOnPage('console');
    
  • Wait for the specified loading state.

    Parameters

    • status: "load" | "domcontentloaded" | "networkidle"

      the status to wait for. Allowed: "load" | "domcontentloaded" | "networkidle".

    • Optional options: WaitForLoadStateActionOptions

      (optional) options for interaction.

    Returns Promise<void>

    Returns when the required load state has been reached.

    Example

    await BrowseTheWeb.as(actor).waitForLoadState('networkidle');
    
  • Wait until the element of the specified locator exists.

    Parameters

    Returns Promise<void>

    Returns when the element exists

    Example

    simple call with just locator

    await BrowseTheWeb.as(actor).waitForLocator(
    page.locator('myLocator')
    );

    with options

    await BrowseTheWeb.as(actor).waitForLocator(
    page.locator('myLocator'),
    { state: "visible" }
    );
  • Wait for the specified URL.

    Parameters

    • url: string | RegExp | ((url) => boolean)

      the url to wait for.

    • Optional options: WaitForUrlActionOptions

      (optional) options for interaction.

    Returns Promise<void>

    Returns when the page specified url has been reached.

    Example

    await BrowseTheWeb.as(actor).waitForUrl('example.com');
    

Generated using TypeDoc