A thenable wrapper around a webdriver.IWebDriver IWebDriver instance that allows commands to be issued directly instead of having to repeatedly call then:

let driver = new Builder().build();
driver.then(d => d.get(url)); // You can do this...
driver.get(url); // ...or this

If the driver instance fails to resolve (e.g. the session cannot be created), every issued command will fail.

Hierarchy

Properties

[toStringTag]: string

Methods

  • Creates a new action sequence using this driver. The sequence will not be scheduled for execution until actions.ActionSequence#perform is called. Example:

    driver.actions().
    mouseDown(element1).
    mouseMove(element2).
    mouseUp().
    perform();

    Parameters

    • Optional options: {
          async: boolean;
          bridge: boolean;
      } | {
          async: boolean;
      } | {
          bridge: boolean;
      }

    Returns Actions

    A new action sequence for this instance.

  • Attaches a callback for only the rejection of the Promise.

    Type Parameters

    • TResult = never

    Parameters

    • Optional onrejected: null | ((reason) => TResult | PromiseLike<TResult>)

      The callback to execute when the Promise is rejected.

    Returns Promise<WebDriver | TResult>

    A Promise for the completion of the callback.

  • Schedules a command to close the current window.

    Returns Promise<void>

    A promise that will be resolved when this command has completed.

  • Creates a new WebSocket connection.

    Parameters

    • target: string

    Returns Promise<any>

    A new CDP instance.

  • Schedules a command.Command to be executed by this driver's command.Executor.

    Type Parameters

    • T

    Parameters

    • command: Command

      The command to schedule.

    • Optional description: string

      A description of the command for debugging.

    Returns Promise<T>

    A promise that will be resolved with the command result.

  • Schedules a command to execute asynchronous JavaScript in the context of the currently selected frame or window. The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window.

    Any arguments provided in addition to the script will be included as script arguments and may be referenced using the {@code arguments} object. Arguments may be a boolean, number, string, or {@code WebElement}. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned.

    Unlike executing synchronous JavaScript with #executeScript, scripts executed with this function must explicitly signal they are finished by invoking the provided callback. This callback will always be injected into the executed function as the last argument, and thus may be referenced with {@code arguments[arguments.length - 1]}. The following steps will be taken for resolving this functions return value against the first argument to the script's callback function:

    • For a HTML element, the value will resolve to a WebElement
    • Null and undefined return values will resolve to null
    • Booleans, numbers, and strings will resolve as is
    • Functions will resolve to their string representation
    • For arrays and objects, each member item will be converted according to the rules above

    Example #1: Performing a sleep that is synchronized with the currently selected window:

    var start = new Date().getTime();
    driver.executeAsyncScript(
    'window.setTimeout(arguments[arguments.length - 1], 500);').
    then(function() {
    console.log(
    'Elapsed time: ' + (new Date().getTime() - start) + ' ms');
    });

    Example #2: Synchronizing a test with an AJAX application:

    var button = driver.findElement(By.id('compose-button'));
    button.click();
    driver.executeAsyncScript(
    'var callback = arguments[arguments.length - 1];' +
    'mailClient.getComposeWindowWidget().onload(callback);');
    driver.switchTo().frame('composeWidget');
    driver.findElement(By.id('to')).sendKeys('dog@example.com');

    Example #3: Injecting a XMLHttpRequest and waiting for the result. In this example, the inject script is specified with a function literal. When using this format, the function is converted to a string for injection, so it should not reference any symbols not defined in the scope of the page under test.

    driver.executeAsyncScript(function() {
    var callback = arguments[arguments.length - 1];
    var xhr = new XMLHttpRequest();
    xhr.open('GET', '/resource/data.json', true);
    xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
    callback(xhr.responseText);
    }
    }
    xhr.send('');
    }).then(function(str) {
    console.log(JSON.parse(str)['food']);
    });

    Type Parameters

    • T

    Parameters

    • script: string | Function

      The script to execute.

    • Rest ...var_args: any[]

      The arguments to pass to the script.

    Returns Promise<T>

    A promise that will resolve to the scripts return value.

  • Schedules a command to execute JavaScript in the context of the currently selected frame or window. The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window.

    Any arguments provided in addition to the script will be included as script arguments and may be referenced using the {@code arguments} object. Arguments may be a boolean, number, string, or {@code WebElement}. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned.

    The script may refer to any variables accessible from the current window. Furthermore, the script will execute in the window's context, thus {@code document} may be used to refer to the current document. Any local variables will not be available once the script has finished executing, though global variables will persist.

    If the script has a return value (i.e. if the script contains a return statement), then the following steps will be taken for resolving this functions return value:

    • For a HTML element, the value will resolve to a WebElement
    • Null and undefined return values will resolve to null
  • Booleans, numbers, and strings will resolve as is
  • Functions will resolve to their string representation
  • For arrays and objects, each member item will be converted according to the rules above

Type Parameters

Parameters

Returns Promise<T>

A promise that will resolve to the scripts return value.

Generated using TypeDoc