@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
90 lines • 4.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Key = void 0;
/**
* Represents keyboard keys that aren't text, and that can be used with the [interaction](https://serenity-js.org/api/core/class/Interaction/) to [`Press`](https://serenity-js.org/api/web/class/Press/).
*
* **Note:** Modifier keys like [`Key.Shift`](https://serenity-js.org/api/web/class/Key/#Shift), [`Key.Alt`](https://serenity-js.org/api/web/class/Key/#Alt) and [`Key.Meta`](https://serenity-js.org/api/web/class/Key/#Meta) (a.k.a. "Command" on Mac) will stay pressed,
* so there's no need to depress them.
*
* ## Learn more
*
* - [`Press`](https://serenity-js.org/api/web/class/Press/)
* - [`Page.sendKeys`](https://serenity-js.org/api/web/class/Page/#sendKeys)
* - [W3C WebDriver Spec: Keyboard Actions](https://w3c.github.io/webdriver/webdriver-spec.html#keyboard-actions)
* - [Selenium WebDriver: Inputs](https://github.com/SeleniumHQ/selenium/blob/trunk/javascript/node/selenium-webdriver/lib/input.js#L46)
* - [WebdriverIO: Constants](https://github.com/webdriverio/webdriverio/blob/main/packages/wdio-utils/src/constants.ts#L5)
*
* @group Models
*/
class Key {
devtoolsName;
utf16codePoint;
isModifier;
static Alt = new Key('Alt', '\uE00A', true);
static ArrowDown = new Key('ArrowDown', '\uE015');
static ArrowLeft = new Key('ArrowLeft', '\uE012');
static ArrowRight = new Key('ArrowRight', '\uE014');
static ArrowUp = new Key('ArrowUp', '\uE013');
static Backspace = new Key('Backspace', '\uE003');
static Cancel = new Key('Cancel', '\uE001');
static Clear = new Key('Clear', '\uE005');
static Control = new Key('Control', '\uE009', true);
static Delete = new Key('Delete', '\uE017');
static End = new Key('End', '\uE010');
static Enter = new Key('Enter', '\uE007');
static Escape = new Key('Escape', '\uE00C');
static F1 = new Key('F1', '\uE031');
static F2 = new Key('F2', '\uE032');
static F3 = new Key('F3', '\uE033');
static F4 = new Key('F4', '\uE034');
static F5 = new Key('F5', '\uE035');
static F6 = new Key('F6', '\uE036');
static F7 = new Key('F7', '\uE037');
static F8 = new Key('F8', '\uE038');
static F9 = new Key('F9', '\uE039');
static F10 = new Key('F10', '\uE03A');
static F11 = new Key('F11', '\uE03B');
static F12 = new Key('F12', '\uE03C');
static Help = new Key('Help', '\uE002');
static Home = new Key('Home', '\uE011');
static Insert = new Key('Insert', '\uE016');
static Meta = new Key('Meta', '\uE03D', true);
static Numpad0 = new Key('Numpad0', '\uE01A');
static Numpad1 = new Key('Numpad1', '\uE01B');
static Numpad2 = new Key('Numpad2', '\uE01C');
static Numpad3 = new Key('Numpad3', '\uE01D');
static Numpad4 = new Key('Numpad4', '\uE01E');
static Numpad5 = new Key('Numpad5', '\uE01F');
static Numpad6 = new Key('Numpad6', '\uE020');
static Numpad7 = new Key('Numpad7', '\uE021');
static Numpad8 = new Key('Numpad8', '\uE022');
static Numpad9 = new Key('Numpad9', '\uE023');
static NumpadAdd = new Key('NumpadAdd', '\uE025');
static NumpadDecimal = new Key('NumpadDecimal', '\uE028');
static NumpadDivide = new Key('NumpadDivide', '\uE029');
static NumpadEqual = new Key('NumpadEqual', '\uE019');
static NumpadMultiply = new Key('NumpadMultiply', '\uE024');
static NumpadSubtract = new Key('NumpadSubtract', '\uE027');
static PageDown = new Key('PageDown', '\uE00F');
static PageUp = new Key('PageUp', '\uE00E');
static Pause = new Key('Pause', '\uE00B');
static Semicolon = new Key('Semicolon', '\uE018');
static Shift = new Key('Shift', '\uE008', true);
static Space = new Key('Space', '\uE00D');
static Tab = new Key('Tab', '\uE004');
static isKey(maybeKey) {
return !!maybeKey
&& maybeKey instanceof Key;
}
constructor(devtoolsName, utf16codePoint, isModifier = false) {
this.devtoolsName = devtoolsName;
this.utf16codePoint = utf16codePoint;
this.isModifier = isModifier;
}
toString() {
return this.devtoolsName.replaceAll(/([a-z])([\dA-Z])/g, '$1 $2');
}
}
exports.Key = Key;
//# sourceMappingURL=Key.js.map