Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infrastructure: Address failing macOS regression tests #3115

Merged
merged 15 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions test/tests/combobox_grid-combo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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.
stalgiag marked this conversation as resolved.
Show resolved Hide resolved
// 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'),
Expand Down
4 changes: 4 additions & 0 deletions test/tests/disclosure_navigation_hybrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was giving intermittent failures. I determined that this was due to the scroll to focus event fired by the link click interfering with the assertion (buttons[1] always failed). This small delay fixes this issue.


t.is(
await links[0].getAttribute('aria-current'),
Expand Down
9 changes: 7 additions & 2 deletions test/tests/toolbar_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions test/util/isMacOS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Returns true if the current platform is macOS
*
* @returns {boolean}
*/
module.exports = function isMacOS() {
return process.platform === 'darwin';
};
45 changes: 45 additions & 0 deletions test/util/translatePlatformKeys.js
Original file line number Diff line number Diff line change
@@ -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;
Loading