From 25084fdd5536813abe5aca017ec758072717f512 Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Mon, 16 Sep 2024 09:46:48 -0700 Subject: [PATCH] Use getOSPreferredModifierKey() utility to off cross-platform support --- test/tests/toolbar_toolbar.js | 7 +++++-- test/util/getOSPreferredModifierKey.js | 6 ++++++ test/util/isMacOS.js | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/util/getOSPreferredModifierKey.js create mode 100644 test/util/isMacOS.js diff --git a/test/tests/toolbar_toolbar.js b/test/tests/toolbar_toolbar.js index 8ad497661d..f793c524ab 100644 --- a/test/tests/toolbar_toolbar.js +++ b/test/tests/toolbar_toolbar.js @@ -7,6 +7,7 @@ const assertAttributeValues = require('../util/assertAttributeValues'); const assertRovingTabindex = require('../util/assertRovingTabindex'); const assertHasFocus = require('../util/assertHasFocus'); const assertAttributeCanBeToggled = require('../util/assertAttributeCanBeToggled'); +const getOSPreferredModifierKey = require('../util/getOSPreferredModifierKey'); const exampleFile = 'content/patterns/toolbar/examples/toolbar.html'; @@ -1115,7 +1116,8 @@ ariaTest( 'toolbar-button-enter-or-space', async (t) => { let textarea = await t.context.session.findElement(By.css('textarea')); - await textarea.sendKeys(Key.chord(Key.META, 'a')); + let modifierKey = getOSPreferredModifierKey(); + await textarea.sendKeys(Key.chord(modifierKey, 'a')); let originalText = await textarea.getAttribute('value'); const buttons = await t.context.queryElements( @@ -1206,7 +1208,8 @@ ariaTest( 'toolbar-button-enter-or-space', async (t) => { let textarea = await t.context.session.findElement(By.css('textarea')); - await textarea.sendKeys(Key.chord(Key.META, 'a')); + let modifierKey = getOSPreferredModifierKey(); + await textarea.sendKeys(Key.chord(modifierKey, 'a')); let originalText = await textarea.getAttribute('value'); const buttons = await t.context.queryElements( diff --git a/test/util/getOSPreferredModifierKey.js b/test/util/getOSPreferredModifierKey.js new file mode 100644 index 0000000000..64060b3670 --- /dev/null +++ b/test/util/getOSPreferredModifierKey.js @@ -0,0 +1,6 @@ +const { Key } = require('selenium-webdriver'); +const isMacOS = require('./isMacOS'); + +module.exports = function getOSPreferredModifierKey() { + return isMacOS() ? Key.META : Key.CONTROL; +}; diff --git a/test/util/isMacOS.js b/test/util/isMacOS.js new file mode 100644 index 0000000000..a5f09a4db6 --- /dev/null +++ b/test/util/isMacOS.js @@ -0,0 +1,3 @@ +module.exports = function isMacOS() { + return process.platform === 'darwin'; +};