Skip to content

Commit

Permalink
Fix for the commands -> at-driver translation layer
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarf committed Nov 9, 2023
1 parent 93249de commit c55c190
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
4 changes: 4 additions & 0 deletions src/agent/at-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export const webDriverCodePoints = {
SHIFT: '\ue008',
CONTROL: '\ue009',
ALT: '\ue00a',
OPT: '\ue00a',
OPTION: '\ue00a',
PAUSE: '\ue00b',
ESCAPE: '\ue00c',
SPACE: '\ue00d',
Expand All @@ -135,8 +137,10 @@ export const webDriverCodePoints = {
ARROWRIGHT: '\ue014',
DOWN: '\ue015',
ARROWDOWN: '\ue015',
INS: '\ue016',
INSERT: '\ue016',
DELETE: '\ue017',
DEL: '\ue017',
SEMICOLON: '\ue018',
EQUALS: '\ue019',

Expand Down
46 changes: 24 additions & 22 deletions src/agent/driver-test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,28 +197,30 @@ export class DriverTestRunner {

export function validateKeysFromCommand(command) {
const errors = [];
for (const { keystroke } of command.keypresses) {
// Some old test plans have keys that contain indications of unspecified
// instructions ('/') or additional instructions that are not standardized
// in test plans. These keys should be updated to be separate commands or
// use a standardized approach.
if (/\//.test(keystroke)) {
errors.push(`'${keystroke}' cannot contain '/'.`);
for (const { id } of command.keypresses) {
if (/\//.test(id)) {
errors.push(`'${id}' cannot contain '/'.`);
}
if (/[()]/.test(keystroke)) {
errors.push(`'${keystroke}' cannot contain '(' or ')'.`);
if (/[()]/.test(id)) {
errors.push(`'${id}' cannot contain '(' or ')'.`);
}
if (/\bor\b/.test(keystroke)) {
errors.push(`'${keystroke}' cannot contain 'or'.`);
if (/\bor\b/.test(id)) {
errors.push(`'${id}' cannot contain 'or'.`);
}
if (/\bfollowed\b/.test(keystroke)) {
errors.push(`'${keystroke}' cannot contain 'followed' or 'followed by'.`);
if (/\bfollowed\b/.test(id)) {
errors.push(`'${id}' cannot contain 'followed' or 'followed by'.`);
}

if (keystroke.length != 1 && !webDriverCodePoints[keystroke.toUpperCase()]) {
errors.push(
`'${keystroke}' is not a recognized key - use single characters or "Normalized" values from https://w3c.github.io/webdriver/#keyboard-actions`
);
for (const part of id.split('_')) {
// Some old test plans have keys that contain indications of unspecified
// instructions ('/') or additional instructions that are not standardized
// in test plans. These keys should be updated to be separate commands or
// use a standardized approach.

if (part.length != 1 && !webDriverCodePoints[part.toUpperCase()]) {
errors.push(
`'${part}' of '${id}' is not a recognized key - use single characters or "Normalized" values from https://w3c.github.io/webdriver/#keyboard-actions`
);
}
}
}

Expand All @@ -233,16 +235,16 @@ export function validateKeysFromCommand(command) {
*/
export function atKeysFromCommand(command) {
return ATKey.sequence(
...command.keypresses.map(({ keystroke }) =>
...command.keypresses.map(({ id }) =>
ATKey.chord(
...keystroke
.split('+')
...id
.split('_')
.map(key => key.trim().toLowerCase())
// `up arrow`, `down arrow`, etc are sent as `up`, `down`, etc
.map(key => key.replace(/\s?arrow\s?/g, ''))
// remove whitespace for keys like 'page up'
.map(key => key.replace(/\s/g, ''))
.map(key => ATKey.key(key))
.map(key => ATKey.key(key.toLowerCase()))
)
)
);
Expand Down

0 comments on commit c55c190

Please sign in to comment.