diff --git a/test/tests/combobox_grid-combo.js b/test/tests/combobox_grid-combo.js index 799acaac94..35f80d53c3 100644 --- a/test/tests/combobox_grid-combo.js +++ b/test/tests/combobox_grid-combo.js @@ -4,7 +4,7 @@ const assertAriaLabelledby = require('../util/assertAriaLabelledby'); const assertAttributeValues = require('../util/assertAttributeValues'); const assertAttributeDNE = require('../util/assertAttributeDNE'); const assertAriaRoles = require('../util/assertAriaRoles'); - +const isMacOS = require('../util/isMacOS'); const exampleFile = 'content/patterns/combobox/examples/grid-combo.html'; const ex = { @@ -877,10 +877,17 @@ ariaTest( // Send key "ARROW_HOME" await combobox.sendKeys(Key.HOME); - t.true( - await confirmCursorIndex(t, ex.comboboxSelector, 0), - 'Cursor should be at index 0 after one ARROW_HOME key' - ); + // On macOS, the HOME key deselects the grid popup + // but it doesn't move the cursor. + // This is being tracked in issue #3191 + // https://github.com/w3c/aria-practices/issues/3191 + // TODO: Remove this once the issue is fixed + if (!isMacOS()) { + t.true( + await confirmCursorIndex(t, ex.comboboxSelector, 0), + 'Cursor should be at index 0 after one ARROW_HOME key' + ); + } t.is( await combobox.getAttribute('aria-activedescendant'), diff --git a/test/tests/disclosure_navigation_hybrid.js b/test/tests/disclosure_navigation_hybrid.js index 3a9748f418..24bebd57fd 100644 --- a/test/tests/disclosure_navigation_hybrid.js +++ b/test/tests/disclosure_navigation_hybrid.js @@ -82,7 +82,11 @@ ariaTest( if (links.length > 0) { await buttons[b].click(); + await links[0].click(); + // Add a small delay here to ensure that the scroll to focus event + // has time to complete and doesn't interfere with the next assertion + await t.context.session.sleep(300); t.is( await links[0].getAttribute('aria-current'), diff --git a/test/tests/toolbar_toolbar.js b/test/tests/toolbar_toolbar.js index 928b75bd6d..76b21b1d27 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 translatePlatformKey = require('../util/translatePlatformKeys'); const exampleFile = 'content/patterns/toolbar/examples/toolbar.html'; @@ -1115,7 +1116,9 @@ ariaTest( 'toolbar-button-enter-or-space', async (t) => { let textarea = await t.context.session.findElement(By.css('textarea')); - await textarea.sendKeys(Key.chord(Key.CONTROL, 'a')); + let selectAllKeys = translatePlatformKey([Key.CONTROL, 'a']); + let selectAllChord = Key.chord(...selectAllKeys); + await textarea.sendKeys(selectAllChord); let originalText = await textarea.getAttribute('value'); const buttons = await t.context.queryElements( @@ -1206,7 +1209,9 @@ ariaTest( 'toolbar-button-enter-or-space', async (t) => { let textarea = await t.context.session.findElement(By.css('textarea')); - await textarea.sendKeys(Key.chord(Key.CONTROL, 'a')); + let selectAllKeys = translatePlatformKey([Key.CONTROL, 'a']); + let selectAllChord = Key.chord(...selectAllKeys); + await textarea.sendKeys(selectAllChord); let originalText = await textarea.getAttribute('value'); const buttons = await t.context.queryElements( diff --git a/test/util/isMacOS.js b/test/util/isMacOS.js new file mode 100644 index 0000000000..4bca64e4fa --- /dev/null +++ b/test/util/isMacOS.js @@ -0,0 +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/translatePlatformKeys.js b/test/util/translatePlatformKeys.js new file mode 100644 index 0000000000..333e0a1fcc --- /dev/null +++ b/test/util/translatePlatformKeys.js @@ -0,0 +1,45 @@ +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 + * + * @example + * // On macOS, translates CONTROL to META (Command key) + * translatePlatformKey(Key.CONTROL) + * // Returns: [Key.META] + * + * // On non-macOS systems, returns key unchanged + * translatePlatformKey(Key.CONTROL) + * // Returns: [Key.CONTROL] + * + * // Works with arrays of keys for key combinations + * translatePlatformKey([Key.CONTROL, 'a']) + * // Returns on macOS: [Key.META, 'a'] + * // Returns on Windows/Linux: [Key.CONTROL, 'a'] + * + * // Usage with Selenium WebDriver: + * const selectAllKeys = translatePlatformKey([Key.CONTROL, 'a']); + * const selectAllChord = Key.chord(...selectAllKeys); + * await element.sendKeys(selectAllChord); + */ +function translatePlatformKeys(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 = translatePlatformKeys;