Skip to content

Commit 563aa5e

Browse files
committed
fix(tests): Make tabNavigateToWorkspace idempotent
Previously this function would just send a bunch of tabs, which depended on focus state being as-on-document-load. Some tests (notably the ones in basic_test.ts) that have only a suiteSetup and not a (per-test) setup method were only were only passing because of the combination of: * Due to issue #632, pressing tab when the workspace is focused (and there are no further focusable elements on the page) incorrectly causes focus to move to the first focusable element on the page instead of (as would normally be the case) to the browser controls, and * The fact that the index.html had exactly one additional focusable div on the page, preceding the injection div. This meant that calling tabNavigateToWorkspace when the workspace was already focused would, only by sheer coincidence, result in the focus remaining on the workspace. By explicitly focusing a known element, tabNavigateToWorkspace should work correctly regardless of how many focusable elements are on the page and which one (if any) was focused before the call.
1 parent 0d726a2 commit 563aa5e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

test/webdriverio/test/test_setup.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,14 @@ export async function tabNavigateToWorkspace(
455455
hasToolbox = true,
456456
hasFlyout = true,
457457
) {
458-
// Navigate past the initial pre-injection focusable div element.
459-
await tabNavigateForward(browser);
458+
// Move focus to initial pre-injection focusable div element.
459+
//
460+
// Ideally we'd just rest focus state to the state it is in when the
461+
// document initially loads (and then send one tab), but alas
462+
// there's no straightforward way to do that; see
463+
// https://stackoverflow.com/q/51518855/4969945
464+
await browser.execute(() => document.getElementById('focusableDiv')?.focus());
465+
// Navigate to workspace.
460466
if (hasToolbox) await tabNavigateForward(browser);
461467
if (hasFlyout) await tabNavigateForward(browser);
462468
await tabNavigateForward(browser); // Tab to the workspace itself.

0 commit comments

Comments
 (0)