diff --git a/test/tests/disclosure_navigation_hybrid.js b/test/tests/disclosure_navigation_hybrid.js index 3a9748f41..5d1400fda 100644 --- a/test/tests/disclosure_navigation_hybrid.js +++ b/test/tests/disclosure_navigation_hybrid.js @@ -82,6 +82,18 @@ ariaTest( if (links.length > 0) { await buttons[b].click(); + // Add explicit wait for menu visibility + await t.context.session.wait( + async () => await menus[b].isDisplayed(), + 1000, + 'Menu should be displayed' + ); + // Ensure link is interactive + await t.context.session.wait( + async () => await links[0].isEnabled(), + 1000, + 'Link should be enabled' + ); await links[0].click(); t.is( diff --git a/test/tests/toolbar_toolbar.js b/test/tests/toolbar_toolbar.js index f793c524a..1e1ad4b44 100644 --- a/test/tests/toolbar_toolbar.js +++ b/test/tests/toolbar_toolbar.js @@ -7,7 +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 translatePlatformKey = require('../util/translatePlatformKey'); const exampleFile = 'content/patterns/toolbar/examples/toolbar.html'; @@ -1116,8 +1116,8 @@ ariaTest( 'toolbar-button-enter-or-space', async (t) => { let textarea = await t.context.session.findElement(By.css('textarea')); - let modifierKey = getOSPreferredModifierKey(); - await textarea.sendKeys(Key.chord(modifierKey, 'a')); + let modifierKey = translatePlatformKey(Key.CONTROL); + await textarea.sendKeys(Key.chord(...modifierKey, 'a')); let originalText = await textarea.getAttribute('value'); const buttons = await t.context.queryElements( @@ -1208,8 +1208,8 @@ ariaTest( 'toolbar-button-enter-or-space', async (t) => { let textarea = await t.context.session.findElement(By.css('textarea')); - let modifierKey = getOSPreferredModifierKey(); - await textarea.sendKeys(Key.chord(modifierKey, 'a')); + let modifierKey = translatePlatformKey(Key.CONTROL); + 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 deleted file mode 100644 index 64060b367..000000000 --- a/test/util/getOSPreferredModifierKey.js +++ /dev/null @@ -1,6 +0,0 @@ -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 index a5f09a4db..4bca64e4f 100644 --- a/test/util/isMacOS.js +++ b/test/util/isMacOS.js @@ -1,3 +1,8 @@ +/** + * Returns true if the current platform is macOS + * + * @returns {boolean} + */ module.exports = function isMacOS() { return process.platform === 'darwin'; }; diff --git a/test/util/translatePlatformKey.js b/test/util/translatePlatformKey.js new file mode 100644 index 000000000..692727892 --- /dev/null +++ b/test/util/translatePlatformKey.js @@ -0,0 +1,26 @@ +const { Key } = require('selenium-webdriver'); +const isMacOS = require('./isMacOS'); + +const MAC_KEY_MAPPINGS = { + [Key.CONTROL]: Key.META, +}; + +/** + * Translates a key or key combination for the current OS + * + * @param {string|string[]} keys - The key(s) to translate + * @returns {string[]} - The translated key(s) as a flat array ready for spreading + */ +function translatePlatformKey(keys) { + const keyArray = Array.isArray(keys) ? keys : [keys]; + if (!isMacOS()) { + return keyArray; + } + + return keyArray.reduce((acc, key) => { + const mappedKey = MAC_KEY_MAPPINGS[key] || key; + return acc.concat(mappedKey); + }, []); +} + +module.exports = translatePlatformKey;