import {Press} from '@serenity-js/webdriverio/lib/screenplay/interactions'
public class | source

Press

Instructs the Actor to send a key press or a sequence of keys to a Web element.

Please note: On macOS, some keyboard shortcuts might not work with the devtools protocol.

For example:

  • to copy, instead of Meta+C, use Control+Insert
  • to cut, instead of Meta+X, use Control+Delete
  • to paste, instead of Meta+V, use Shift+Insert

Extends:

Examples:

Example widget
 <form>
   <input type="text" name="example" id="example" />
 </form>
Lean Page Object describing the widget
 import { by, Target } from '@serenity-js/webdriverio';

 class Form {
     static exampleInput = Target.the('example input')
         .located(by.id('example'));
 }
Pressing keys
 import { actorCalled } from '@serenity-js/core';
 import { BrowseTheWeb, Key, Press, Value } from '@serenity-js/webdriverio';
 import { Ensure, equals } from '@serenity-js/assertions';

 actorCalled('Priyanka')
     .whoCan(BrowseTheWeb.using(browser))
     .attemptsTo(
         Press.the('H', 'i', '!', Key.ENTER).in(Form.exampleInput),
         Ensure.that(Value.of(Form.exampleInput), equals('Hi!')),
     );

Tests:

Static Method Summary

Static Public Methods
public static

the(keys: ...keys: Array<Answerable<Key|string|Key[]|string[]>>): PressBuilder

Instantiates this Interaction.

Constructor Summary

Public Constructor
public

constructor(keys: Answerable<Array<Key|string>>)

Method Summary

Public Methods
public

in(field: Answerable): Interaction

public

async performAs(actor: UsesAbilities & AnswersQuestions): PromiseLike<void>

Makes the provided Actor perform this Interaction.

Inherited Summary

From class WebElementInteraction
public

toString(): string

Generates a description to be used when reporting this Activity.

protected

async resolve(actor: AnswersQuestions, element: Answerable<Element<'async'>>): Promise<Element<'async'>>

Returns the resolved Element, or throws a LogicError if the element is undefined.

Static Public Methods

public static the(keys: ...keys: Array<Answerable<Key|string|Key[]|string[]>>): PressBuilder source

Instantiates this Interaction.

Params:

NameTypeAttributeDescription
keys ...keys: Array<Answerable<Key|string|Key[]|string[]>>

A sequence of one or more keys to press

Returns:

PressBuilder

Public Constructors

public constructor(keys: Answerable<Array<Key|string>>) source

Params:

NameTypeAttributeDescription
keys Answerable<Array<Key|string>>

A sequence of one or more keys to press

Public Methods

public in(field: Answerable): Interaction source

Params:

NameTypeAttributeDescription
field Answerable

Returns:

Interaction

public async performAs(actor: UsesAbilities & AnswersQuestions): PromiseLike<void> source

Makes the provided Actor perform this Interaction.

Params:

NameTypeAttributeDescription
actor UsesAbilities & AnswersQuestions

An Actor to perform this Interaction

Returns:

PromiseLike<void>