The new interface introduced in this document provides web developers a way to generate synthetic input events from different devices and interact with their app as if the user is interacting with it. This API make testing a web page that needs user input possible across multiple browsers. This work extends WebDriver spec by introducing some Javascript APIs to accomplish the task of generating synthetic input.

Introduction

The InputDriver event

The proposed solution to the problem above is a new interface to expose injecting inputs to the web page. It gets a json object which provides all the input that needs to be sent to the page and will return a promise that gets resolved when the input is injected.

interface InputDriver {
    Promise sendPointerActions(actions);
};
              

sendPointerActions

A function that gets a json input unique identifier for the pointer causing the event. The format of the json parameter is similar to what Pointer Actions section describes.

Examples

The following are examples that demonstrate how the new interface in this specification might be used


if (window.InputDriver) {
    var driver = new InputDriver();
    var result = driver.sendpointerActions([
      {
        "source": "mouse",
        "actions": [
          { "name": "pointerDown", "x": 5, "y": 5 },
          { "name": "pointerMove", "x": 5, "y": 8 },
          { "name": "pause"},
          { "name": "pointerUp" }
        ]
      },
      {
        "source": "touch",
        "actions": [
          { "name": "pause" },
          { "name": "pause" },
          { "name": "pointerDown", "x": 9, "y": 9 },
          { "name": "pointerMove", "x": 9, "y": 12 },
          { "name": "pointerUp" }
        ]
      }
    ]);
    result.then(function() {
      // Sending the input was successful.
    });
} else {
    // Input automation is not supported on your browser. You may need
    // to enable a flag to enable this API. 
}