webdriverio
Version:
Next-gen browser and mobile automation test framework for Node.js
40 lines (34 loc) • 976 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = keys;
var _utils = require("../../utils");
function keys(value) {
let keySequence = [];
if (typeof value === 'string') {
keySequence = (0, _utils.checkUnicode)(value, this.isDevTools);
} else if (value instanceof Array) {
for (const charSet of value) {
keySequence = keySequence.concat((0, _utils.checkUnicode)(charSet, this.isDevTools));
}
} else {
throw new Error('"keys" command requires a string or array of strings as parameter');
}
if (!this.isW3C) {
return this.sendKeys(keySequence);
}
const keyDownActions = keySequence.map(value => ({
type: 'keyDown',
value
}));
const keyUpActions = keySequence.map(value => ({
type: 'keyUp',
value
}));
return this.performActions([{
type: 'key',
id: 'keyboard',
actions: [...keyDownActions, ...keyUpActions]
}]).then(() => this.releaseActions());
}