Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

test(a11y): stop focus assertions racing the focus move

joshistoast2533f3a16165
diff --git a/invokeai/frontend/webv2/scripts/run-accessibility-journeys.mjs b/invokeai/frontend/webv2/scripts/run-accessibility-journeys.mjs
index 03273290b5..828d4f46ec 100644
--- a/invokeai/frontend/webv2/scripts/run-accessibility-journeys.mjs
+++ b/invokeai/frontend/webv2/scripts/run-accessibility-journeys.mjs
@@ -165,8 +165,28 @@ const runAxeSurface = async (browser, surface) => {
}
};
+/**
+ * Roving-tabindex and focus-restore moves land on a later task than the key
+ * press that causes them, so sampling `document.activeElement` once races the
+ * behaviour under test. Poll to a deadline instead: the assertion is unchanged
+ * (focus must reach this element) but it no longer depends on scheduling.
+ */
const expectFocused = async (locator, message) => {
- assert.equal(await locator.evaluate((element) => element === document.activeElement), true, message);
+ const deadline = Date.now() + 5_000;
+
+ for (;;) {
+ if (await locator.evaluate((element) => element === document.activeElement)) {
+ return;
+ }
+
+ if (Date.now() >= deadline) {
+ assert.fail(message);
+ }
+
+ await new Promise((resolveWait) => {
+ setTimeout(resolveWait, 25);
+ });
+ }
};
const runKeyboardJourney = async (browser) => {