@serenity-js/web
Version:
Serenity/JS Screenplay Pattern library offering a flexible, web driver-agnostic approach for interacting with web-based user interfaces and components, suitable for various testing contexts
92 lines • 3.7 kB
TypeScript
import type { Activity, Answerable, AnswersQuestions, UsesAbilities } from '@serenity-js/core';
import { Interaction } from '@serenity-js/core';
import type { PageElement } from '../models';
import { Key } from '../models';
import { PageElementInteraction } from './PageElementInteraction';
/**
* Instructs an [actor](https://serenity-js.org/api/core/class/Actor/) who has the [ability](https://serenity-js.org/api/core/class/Ability/) to [`BrowseTheWeb`](https://serenity-js.org/api/web/class/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](https://webdriver.io/docs/automationProtocols/#devtools-protocol).
*
* For example:
* - to *copy*, instead of [`Key.Meta`](https://serenity-js.org/api/web/class/Key/#Meta)+`C`, use [`Key.Control`](https://serenity-js.org/api/web/class/Key/#Control)+[`Key.Insert`](https://serenity-js.org/api/web/class/Key/#Insert)
* - to *cut*, instead of [`Key.Meta`](https://serenity-js.org/api/web/class/Key/#Meta)+`X`, use [`Key.Control`](https://serenity-js.org/api/web/class/Key/#Control)+[`Key.Delete`](https://serenity-js.org/api/web/class/Key/#Delete)
* - to *paste*, instead of [`Key.Meta`](https://serenity-js.org/api/web/class/Key/#Meta)+`V`, use [`Key.Shift`](https://serenity-js.org/api/web/class/Key/#Shift)+[`Key.Insert`](https://serenity-js.org/api/web/class/Key/#Insert)
*
* ## Example widget
*
* ```html
* <form>
* <input type="text" name="example" id="example" />
* </form>
* ```
*
* ## Lean Page Object describing the widget
*
* ```ts
* import { By, PageElement } from '@serenity-js/web'
*
* class Form {
* static exampleInput = () =>
* PageElement.located(By.id('example'))
* .describedAs('example input')
* }
* ```
*
* ## Pressing keys
*
* ```ts
* 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
*
* - [`Key`](https://serenity-js.org/api/web/class/Key/)
* - [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/)
* - [`PageElement`](https://serenity-js.org/api/web/class/PageElement/)
*
* @group Activities
*/
export declare class Press extends PageElementInteraction {
private readonly keys;
/**
* Instantiates an [interaction](https://serenity-js.org/api/core/class/Interaction/)
* that instructs the [actor](https://serenity-js.org/api/core/class/Actor/)
* to press a sequence of [keys](https://serenity-js.org/api/web/class/Key/),
*
* 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.
*
* @param keys
* A sequence of one or more keys to press
*/
static the(...keys: Array<Answerable<Key | string | Key[] | string[]>>): Activity & {
in: (field: Answerable<PageElement>) => Interaction;
};
/**
* Send the key sequence to a specific element.
*
* @param field
*/
in(field: Answerable<PageElement>): Interaction;
/**
* @param keys
* A sequence of one or more keys to press
*/
protected constructor(keys: Answerable<Array<Key | string>>);
/**
* @inheritDoc
*/
performAs(actor: UsesAbilities & AnswersQuestions): Promise<void>;
}
//# sourceMappingURL=Press.d.ts.map