Skip to content

Conversation

@cpcallen
Copy link
Collaborator

@cpcallen cpcallen commented Aug 8, 2025

A bunch of small fixes and refactors of tests:

  • fix: Have scroll_test.ts restore the original browser window size after it's done.
  • docs: Use "WebdriverIO" instead of "Selenium" (since we don't use Selenium!)
  • chore: Make timeout(0) calls only when PAUSE_TIME is nonzero (and make them in every suite).
  • fix: Set PAUSE_TIME to 0, making tests run about 50% faster.
  • refactor: Use sendKeyAndWait almost everywhere (instead of browser.keys).
  • fix(tests): Make tabNavigateToWorkspace idempotent, to avoid relying on a bug Tabbing past workspace fails to move focus to browser controls #632.
  • chore(tests): Remove tabNavigateToWorkspace calls that are immediately followed by a focusOnBlock call.

This is a rebase, with updates, of the changes from (and supercedes) PR #660, and incorporates changes based on the comments thereto.

We aren't using Selenium, so we shouldn't be saying we do.
With PAUSE_TIME set to zero, on my relatively fast laptop none of
these tests run slow enough to fail due to the default 2s timeous, and
even with PAUSE_TIME set to 50ms the slowest test is 1024ms (of which
700ms is spent in brower.pause calls inside sendKeyAndWait).

We do want to disable timeouts when debugging tests, both because we
might set PAUSE_TIME to a larger value and because we might use the
debugger to pause things entirely, but we don't need to disable
timeouts when running tests just to check their results.
It's very useful to be able to make tests run more slowly so you
can watch them, but they should run as fast as possible by default.

This cuts total test execution time on a 2021 MacBook Pro M1
approximately in half, from 42s to 22s.
In most places we were already following browser.keys with a
browser.pause(PAUSE_TIME), so using sendKeysAndWait is more
succinct; in other places we didn't have the pause but it is
not harmful to add a pause (especially now the default PAUSE_TIME
is zero) and could be helpful when watching tests run with a
non-zero PAUSE_TIME.
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 RaspberryPiFoundation#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.
Any time a tabNavigateToWorkspace call is followed by a call to
focusOnBlock the former can be removed with no discernable effect
except to make tests run slightly faster and with less flashing
of the flyout.
Copy link
Collaborator

@maribethb maribethb left a comment

Choose a reason for hiding this comment

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

also 1 lint warning

@cpcallen
Copy link
Collaborator Author

@maribethb: If this LGTY then please go ahead and merge it so it does not get stale again.

@cpcallen cpcallen merged commit 7991855 into RaspberryPiFoundation:main Aug 19, 2025
8 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Blockly 2025 Aug 19, 2025
@cpcallen cpcallen deleted the refactor/tests branch August 19, 2025 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants