From efaa27c36f58da197e984348180c712075cd3ba1 Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Mon, 16 Sep 2024 09:39:30 -0700 Subject: [PATCH 01/14] Use Key.META for text area all text selection for OS agnostic testing toolbar_toolbar --- test/tests/toolbar_toolbar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tests/toolbar_toolbar.js b/test/tests/toolbar_toolbar.js index 928b75bd6d..8ad497661d 100644 --- a/test/tests/toolbar_toolbar.js +++ b/test/tests/toolbar_toolbar.js @@ -1115,7 +1115,7 @@ 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')); + await textarea.sendKeys(Key.chord(Key.META, 'a')); let originalText = await textarea.getAttribute('value'); const buttons = await t.context.queryElements( @@ -1206,7 +1206,7 @@ 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')); + await textarea.sendKeys(Key.chord(Key.META, 'a')); let originalText = await textarea.getAttribute('value'); const buttons = await t.context.queryElements( From 25084fdd5536813abe5aca017ec758072717f512 Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Mon, 16 Sep 2024 09:46:48 -0700 Subject: [PATCH 02/14] 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'; +}; From ef0f7ba5030194480c82b05dad3592a8ee179e2d Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Thu, 21 Nov 2024 18:07:14 -0800 Subject: [PATCH 03/14] Fix disclosure_navigation_hybrid test, support platform specific key conversion to key chord --- test/tests/disclosure_navigation_hybrid.js | 12 ++++++++++ test/tests/toolbar_toolbar.js | 10 ++++----- test/util/getOSPreferredModifierKey.js | 6 ----- test/util/isMacOS.js | 5 +++++ test/util/translatePlatformKey.js | 26 ++++++++++++++++++++++ 5 files changed, 48 insertions(+), 11 deletions(-) delete mode 100644 test/util/getOSPreferredModifierKey.js create mode 100644 test/util/translatePlatformKey.js diff --git a/test/tests/disclosure_navigation_hybrid.js b/test/tests/disclosure_navigation_hybrid.js index 3a9748f418..5d1400fda3 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 f793c524ab..1e1ad4b443 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 64060b3670..0000000000 --- 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 a5f09a4db6..4bca64e4fa 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 0000000000..6927278920 --- /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; From 0a84f3917b3b65b31743ef8166249767ee2bd88e Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Thu, 21 Nov 2024 18:52:21 -0800 Subject: [PATCH 04/14] Skip tests in combobox that cannot be replicated on macOS, reset disclosure to previous code --- test/tests/combobox_grid-combo.js | 16 +++++++++++++++- test/tests/disclosure_navigation_hybrid.js | 12 ------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/test/tests/combobox_grid-combo.js b/test/tests/combobox_grid-combo.js index 799acaac94..a5df1461cf 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 = { @@ -874,6 +874,13 @@ ariaTest( const combobox = t.context.session.findElement(By.css(ex.comboboxSelector)); await combobox.sendKeys('a', Key.ARROW_DOWN); + // "ARROW_HOME" is not valid on macos, equivalent is an FN + ARROW_LEFT key chord + // Selenium WebDriver does not support FN keys, so this test is not valid on macos + if (isMacOS()) { + t.pass('Skipping test on macOS - HOME key not supported'); + return; + } + // Send key "ARROW_HOME" await combobox.sendKeys(Key.HOME); @@ -899,6 +906,13 @@ ariaTest( const combobox = t.context.session.findElement(By.css(ex.comboboxSelector)); await combobox.sendKeys('a', Key.ARROW_DOWN); + // "ARROW_END" is not valid on macos, equivalent is an FN + ARROW_RIGHT key chord + // Selenium WebDriver does not support FN keys, so this test is not valid on macos + if (isMacOS()) { + t.pass('Skipping test on macOS - END key not supported'); + return; + } + // Send key "END_ARROW" await combobox.sendKeys(Key.END); diff --git a/test/tests/disclosure_navigation_hybrid.js b/test/tests/disclosure_navigation_hybrid.js index 5d1400fda3..3a9748f418 100644 --- a/test/tests/disclosure_navigation_hybrid.js +++ b/test/tests/disclosure_navigation_hybrid.js @@ -82,18 +82,6 @@ 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( From 75bf7885d9dc45b2e69d275a1432df7deb9b0486 Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Wed, 4 Dec 2024 10:13:41 -0800 Subject: [PATCH 05/14] Remove errant Home and End assumption in combobox test --- test/tests/combobox_grid-combo.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/test/tests/combobox_grid-combo.js b/test/tests/combobox_grid-combo.js index a5df1461cf..febaf22f65 100644 --- a/test/tests/combobox_grid-combo.js +++ b/test/tests/combobox_grid-combo.js @@ -4,7 +4,6 @@ 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 = { @@ -874,16 +873,8 @@ ariaTest( const combobox = t.context.session.findElement(By.css(ex.comboboxSelector)); await combobox.sendKeys('a', Key.ARROW_DOWN); - // "ARROW_HOME" is not valid on macos, equivalent is an FN + ARROW_LEFT key chord - // Selenium WebDriver does not support FN keys, so this test is not valid on macos - if (isMacOS()) { - t.pass('Skipping test on macOS - HOME key not supported'); - return; - } - // 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' @@ -906,13 +897,6 @@ ariaTest( const combobox = t.context.session.findElement(By.css(ex.comboboxSelector)); await combobox.sendKeys('a', Key.ARROW_DOWN); - // "ARROW_END" is not valid on macos, equivalent is an FN + ARROW_RIGHT key chord - // Selenium WebDriver does not support FN keys, so this test is not valid on macos - if (isMacOS()) { - t.pass('Skipping test on macOS - END key not supported'); - return; - } - // Send key "END_ARROW" await combobox.sendKeys(Key.END); From 900f7837cf853a170d323423b1f7b593d44410dd Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Wed, 4 Dec 2024 11:28:02 -0800 Subject: [PATCH 06/14] Example click retry logic for flakey macOS disclosure_navigation_hybrid test --- test/tests/disclosure_navigation_hybrid.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/tests/disclosure_navigation_hybrid.js b/test/tests/disclosure_navigation_hybrid.js index 3a9748f418..cc55651639 100644 --- a/test/tests/disclosure_navigation_hybrid.js +++ b/test/tests/disclosure_navigation_hybrid.js @@ -82,6 +82,24 @@ ariaTest( if (links.length > 0) { await buttons[b].click(); + + let retries = 1; + let menuVisible = false; + + while (retries >= 0 && !menuVisible) { + await buttons[b].click(); + + menuVisible = await menus[b].isDisplayed(); + + if (!menuVisible && retries === 0) { + throw new Error( + `Failed to make menu ${b} visible after multiple attempts` + ); + } + retries--; + } + + t.true(menuVisible, `Menu ${b} should be visible before clicking link`); await links[0].click(); t.is( From 856188e890cf281a42424df13f7ac79b0b31cf77 Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Wed, 4 Dec 2024 11:46:25 -0800 Subject: [PATCH 07/14] Add small delay to handle scroll event, disclosure_navigation_hybrid test --- test/tests/disclosure_navigation_hybrid.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/test/tests/disclosure_navigation_hybrid.js b/test/tests/disclosure_navigation_hybrid.js index cc55651639..24bebd57fd 100644 --- a/test/tests/disclosure_navigation_hybrid.js +++ b/test/tests/disclosure_navigation_hybrid.js @@ -83,24 +83,10 @@ ariaTest( if (links.length > 0) { await buttons[b].click(); - let retries = 1; - let menuVisible = false; - - while (retries >= 0 && !menuVisible) { - await buttons[b].click(); - - menuVisible = await menus[b].isDisplayed(); - - if (!menuVisible && retries === 0) { - throw new Error( - `Failed to make menu ${b} visible after multiple attempts` - ); - } - retries--; - } - - t.true(menuVisible, `Menu ${b} should be visible before clicking link`); 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'), From 05cdaa6c5c5ea3ed7c0e608a4f001e185839d2fc Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Wed, 4 Dec 2024 12:05:25 -0800 Subject: [PATCH 08/14] Add macOS regression test runner, don't test cursor move on macOS --- .github/workflows/regression.yml | 1 + test/tests/combobox_grid-combo.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index dd69c29409..b6e98f316d 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -25,6 +25,7 @@ jobs: strategy: fail-fast: false matrix: + os: [ubuntu-latest, macos-latest] CI_NODE_INDEX: [0, 1, 2, 3, 4] steps: diff --git a/test/tests/combobox_grid-combo.js b/test/tests/combobox_grid-combo.js index febaf22f65..57b93c5f3e 100644 --- a/test/tests/combobox_grid-combo.js +++ b/test/tests/combobox_grid-combo.js @@ -4,6 +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 = { @@ -875,10 +876,15 @@ 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. + 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'), From 7b3c6a54212764496a1f62f0d104efa9e8283f17 Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Wed, 4 Dec 2024 15:16:23 -0800 Subject: [PATCH 09/14] Missing matrix os yaml property for macos regression testing --- .github/workflows/regression.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index b6e98f316d..19237cc14e 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -21,7 +21,7 @@ on: jobs: regression: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: From a0b7fdef854c84f3c1f699345815decaf1da760c Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Thu, 5 Dec 2024 09:39:02 -0800 Subject: [PATCH 10/14] Use GNU grep in regression tests --- .github/workflows/regression.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index 19237cc14e..ad93fb90af 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -33,6 +33,14 @@ jobs: with: fetch-depth: 0 + - name: Set up firefox for macos + if: matrix.os == 'macos-latest' + run: | + brew install firefox + # Install GNU grep to use 'grep -P' + brew install grep + echo "/opt/homebrew/opt/grep/libexec/gnubin" >> $GITHUB_PATH + - name: Set up Node.js uses: actions/setup-node@v4 with: From a4688c03add445fecbe3243c8f93a2cd6d679246 Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Thu, 5 Dec 2024 09:42:19 -0800 Subject: [PATCH 11/14] Add GNU grep for macOS in regression-tests workflow Co-authored-by: Howard Edwards --- .github/workflows/regression.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index 19237cc14e..ad93fb90af 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -33,6 +33,14 @@ jobs: with: fetch-depth: 0 + - name: Set up firefox for macos + if: matrix.os == 'macos-latest' + run: | + brew install firefox + # Install GNU grep to use 'grep -P' + brew install grep + echo "/opt/homebrew/opt/grep/libexec/gnubin" >> $GITHUB_PATH + - name: Set up Node.js uses: actions/setup-node@v4 with: From 60d40b12c3d0873af7452b7da68945751fba0662 Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Thu, 5 Dec 2024 10:51:42 -0800 Subject: [PATCH 12/14] Revert mac os CI testing --- .github/workflows/regression.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index ad93fb90af..dd69c29409 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -21,11 +21,10 @@ on: jobs: regression: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest] CI_NODE_INDEX: [0, 1, 2, 3, 4] steps: @@ -33,14 +32,6 @@ jobs: with: fetch-depth: 0 - - name: Set up firefox for macos - if: matrix.os == 'macos-latest' - run: | - brew install firefox - # Install GNU grep to use 'grep -P' - brew install grep - echo "/opt/homebrew/opt/grep/libexec/gnubin" >> $GITHUB_PATH - - name: Set up Node.js uses: actions/setup-node@v4 with: From aa905f638bbea694cde78fc7b386647bdcc4ac8c Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Wed, 11 Dec 2024 08:57:12 -0800 Subject: [PATCH 13/14] JSDoc example for translatePlatformKeys, rename translatePlatformKey --- test/tests/toolbar_toolbar.js | 12 ++++---- test/util/translatePlatformKey.js | 26 ----------------- test/util/translatePlatformKeys.js | 45 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 31 deletions(-) delete mode 100644 test/util/translatePlatformKey.js create mode 100644 test/util/translatePlatformKeys.js diff --git a/test/tests/toolbar_toolbar.js b/test/tests/toolbar_toolbar.js index 1e1ad4b443..76b21b1d27 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 translatePlatformKey = require('../util/translatePlatformKey'); +const translatePlatformKey = require('../util/translatePlatformKeys'); const exampleFile = 'content/patterns/toolbar/examples/toolbar.html'; @@ -1116,8 +1116,9 @@ ariaTest( 'toolbar-button-enter-or-space', async (t) => { let textarea = await t.context.session.findElement(By.css('textarea')); - let modifierKey = translatePlatformKey(Key.CONTROL); - await textarea.sendKeys(Key.chord(...modifierKey, '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( @@ -1208,8 +1209,9 @@ ariaTest( 'toolbar-button-enter-or-space', async (t) => { let textarea = await t.context.session.findElement(By.css('textarea')); - let modifierKey = translatePlatformKey(Key.CONTROL); - await textarea.sendKeys(Key.chord(...modifierKey, '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/translatePlatformKey.js b/test/util/translatePlatformKey.js deleted file mode 100644 index 6927278920..0000000000 --- a/test/util/translatePlatformKey.js +++ /dev/null @@ -1,26 +0,0 @@ -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; 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; From 607299d75a0603db60489ba4f739c55d86e80a51 Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Wed, 11 Dec 2024 09:18:32 -0800 Subject: [PATCH 14/14] Add TODO and issue link for combobox grid combo --- test/tests/combobox_grid-combo.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/tests/combobox_grid-combo.js b/test/tests/combobox_grid-combo.js index 57b93c5f3e..35f80d53c3 100644 --- a/test/tests/combobox_grid-combo.js +++ b/test/tests/combobox_grid-combo.js @@ -879,6 +879,9 @@ ariaTest( // 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),