Actions

Actions

The class responsible of creating action objects, which are a list of UI actions to be carried out.

Once the action object is created, you can add "ticks" to it using the property tick (which is actually a getter). The way you use tick depends on the devices you created.

If you call the constructor lile this:

var actions = new Actions()

It's the same as typing:

var actions = new Actions(
  new Actions.Keyboard('keyboard'),
  new Actions.Pointer('mouse', Pointer.Type.MOUSE)
)

This will make two devices, mouse and keyboard, available.

Such a scenario will allow you to call:

actions.tick.keyboardDown('r').mouseDown()
actions.tick.keyboardUp('r').mouseUp()

Here, keyboardUp was available as a combination of the keyboard ID keyboard and the keyboard action Up.

In short:

    • Keyboard devices will have the methods Up, Down
    • Pointer devices will have the methors Move, Up, Down, Cancel
    • Both of them have the method pause

If you create an actions object like this:

 var actions = new Actions(new Actions.Keyboard('cucumber'))

You are then able to run:

 actions.tick.cucumberDown('r')
 actions.tick.cucumberUp('r')

However running:

 actions.tick.cucumberMove('r')

Will result in an error, since cucumber is a keyboard device, and it doesn't implement move (only pointers do)

If you have two devices set (like the default keyboard and mouse, which is the most common use-case), you can set one action per tick:

 var actions = new Actions() // By default, mouse and keyboard
 // Only a keyboard action in this tick. Mouse will pause
 actions.tick.keyboardDown('r')
 // Only a mouse action in this tick. Keyboard will pause
 actions.tick.mouseDown()
 // Both a mouse and a keyboard action this tick
 actions.tick.keyboardUp('r').mouseUp()

You can only add one action per device in each tick. This will give an error, because the mouse device is trying to define two different actions in the same tick:

 actions.tick.mouseDown().mouseUp()

You are able to chain tick calls if you want to:

 actions
 .tick.keyboardDown('r').mouseDown()
 .tick.keyboardUp('r').mouseUp()

Once you have decided your actions, you can submit them:

await driver.performActions(actions)

Constructor

new Actions(…inputDevice)

The constructor

Parameters:
Name Type Attributes Description
inputDevice InputDevice <repeatable>

Input devices that will be used to carry out actions. By default, two devices are created: keyboard and mouse

Source:
Example
// Creating an actions object. This...
var actions = new Actions()
// Is the same as:
var Pointer = Actions.Pointer
var Keyboard = Actions.Keyboard
var actions = new Actions( new Actions.Keyboard('keyboard'), new Actions.Pointer('mouse', Pointer.Type.MOUSE))

// You can also be creative with names
var actions = new Actions.Pointer('da_mouse', Pointer.Type.MOUSE)

Members

(static) Key

Constant returning special KEY characters (enter, etc.) Constant are from the global variable KEY

Source:
Example
var actions = new Actions()
actions.tick.keyboardDown(Actions.Key.ENTER).keyboardUp(Actions.Key.ENTER)

(static) Keyboard

The Keyboard class constructor

Source:

(static) Pointer

The Keyboard class constructor

Source:

tick

As a getter, it will return an object with the right methods depending on what devices were passed when constructing the object. For example running:

 var actions = new Actions(new Actions.Keyboard('cucumber'))

Will ensure that tick will return an object with the properties cucumberUp, cucumberDown and pause More conventionally, creating the action object like this:

 var actions = new Actions()

Will default to two devices, mouse and keyboard. So, the object returned by the tick getter will return an object with the methods keyboardUp(), keyboardDown(), keyboardPause(), mouseUp(), mouseDown(), mouseCancel(), mousePause()

Source:

Methods

compile()

Compiles the stored actions into a compiledActions object, which is an object compatible with the webdriver protocol for actions

There is no need to call this method directly, since the driver always tries to compile() actions before sending them over.

Source: