import {Press} from '@serenity-js/protractor/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 that modifier keys, such as Command ⌘, won't work on Mac

Extends:

Interaction → Press

Examples:

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

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

 actorCalled('Priyanka')
     .whoCan(BrowseTheWeb.using(protractor.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: string[]): PressBuilder

Instantiates this Interaction.

Constructor Summary

Public Constructor
public

constructor(keys: string[], field: Question<ElementFinder> | ElementFinder)

Method Summary

Public Methods
public

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

Makes the provided Actor perform this Interaction.

public

toString(): string

Generates a description to be used when reporting this Activity.

Static Public Methods

public static the(keys: ...keys: string[]): PressBuilder source

Instantiates this Interaction.

Params:

NameTypeAttributeDescription
keys ...keys: string[]

A sequence of one or more keys to press

Returns:

PressBuilder

Public Constructors

public constructor(keys: string[], field: Question<ElementFinder> | ElementFinder) source

Params:

NameTypeAttributeDescription
keys string[]

A sequence of one or more keys to press

field Question<ElementFinder> | ElementFinder

Web element to send the keys to

Public Methods

public 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>

public toString(): string source

Generates a description to be used when reporting this Activity.

Returns:

string