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
, useControl+Insert
- to cut, instead of
Meta+X
, useControl+Delete
- to paste, instead of
Meta+V
, useShift+Insert
Extends:
Examples:
<form>
<input type="text" name="example" id="example" />
</form>
import { by, Target } from '@serenity-js/webdriverio';
class Form {
static exampleInput = Target.the('example input')
.located(by.id('example'));
}
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:
See also:
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 |
Static Public Methods
public static the(keys: ...keys: Array<Answerable<Key|string|Key[]|string[]>>): PressBuilder source
Instantiates this Interaction.
Params:
Name | Type | Attribute | Description |
keys | ...keys: Array<Answerable<Key|string|Key[]|string[]>> | A sequence of one or more keys to press |
Tests:
- Press single keys allows the actor to enter keys individually into a field
- Press key chords allows the actor to use modifier keys
- Press key chords allows the actor to use keyboard shortcuts outside the context of any specific input box
- Press key chords allows the actor to use keyboard shortcuts in the context of a specific input box
Public Constructors
public constructor(keys: Answerable<Array<Key|string>>) source
Override:
WebElementInteraction#constructorParams:
Name | Type | Attribute | Description |
keys | Answerable<Array<Key|string>> | A sequence of one or more keys to press |
Public Methods
public in(field: Answerable): Interaction source
Params:
Name | Type | Attribute | Description |
field | Answerable |
public async performAs(actor: UsesAbilities & AnswersQuestions): PromiseLike<void> source
Makes the provided Actor perform this Interaction.
Params:
Name | Type | Attribute | Description |
actor | UsesAbilities & AnswersQuestions | An Actor to perform this Interaction |
Returns:
PromiseLike<void> |