Skip to main content

externalPress

Instructs an actor who has the ability to BrowseTheWeb to send a key press or a sequence of keys to a Web element.

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

For example:

Example widget

<form>
<input type="text" name="example" id="example" />
</form>

Lean Page Object describing the widget

import { By, PageElement } from '@serenity-js/web'

class Form {
static exampleInput = () =>
PageElement.located(By.id('example'))
.describedAs('example input')
}

Pressing keys

import { actorCalled } from '@serenity-js/core'
import { Key, Press, Value } from '@serenity-js/web'
import { Ensure, equals } from '@serenity-js/assertions'

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

Learn more

Hierarchy

Index

Methods

staticexternalthe

  • Instantiates an interaction that instructs the actor to press a sequence of keys,

    When no field is specified, the key sequence will be sent to the currently focused element, and if no element is focused - to the document.body to handle.


    Parameters

    • externalrest...keys: Answerable<string | string[] | Key | Key[]>[]

      A sequence of one or more keys to press

    Returns Activity & { in: (field: Answerable<PageElement<any>>) => Interaction }

externalinstantiationLocation

  • instantiationLocation(): FileSystemLocation
  • Returns the location where this Activity was instantiated.


    Returns FileSystemLocation

externaldescribedBy

  • Resolves the description of this object in the context of the provided actor.


    Parameters

    Returns Promise<string>

externaltoString

  • toString(): string
  • Returns a human-readable description of this object.


    Returns string

externalin

externalperformAs