Skip to content

Skip full pageload wait on non-jQuery pages in waitForAjaxLoad#926

Open
lbajsarowicz wants to merge 1 commit into
magento:developfrom
lbajsarowicz:perf/waitforajaxload-skip-nonjquery-wait
Open

Skip full pageload wait on non-jQuery pages in waitForAjaxLoad#926
lbajsarowicz wants to merge 1 commit into
magento:developfrom
lbajsarowicz:perf/waitforajaxload-skip-nonjquery-wait

Conversation

@lbajsarowicz

Copy link
Copy Markdown
Contributor

Description

MagentoWebDriver::waitForAjaxLoad() waits for jQuery to be idle:

$this->waitForJS('return !!window.jQuery && window.jQuery.active == 0;', $timeout);

On a page that does not load jQuery, !!window.jQuery is always false, so the
expression is never truthy. waitForJS() therefore polls until it times out and
throws, and the catch block then sleeps another full pageload_timeout:

} catch (\Exception $exceptione) {
    $this->debug("js never executed, performing {$timeout} second wait.");
    $this->wait($timeout);
}

Net effect: roughly WAIT_TIMEOUT (60s with the default 30s timeout) is burned on
every waitForAjaxLoad() call on any non-jQuery page — and waitForPageLoad() calls
waitForAjaxLoad() on every navigation. This penalizes storefront/headless flows and any
theme that does not ship jQuery.

Fixed Issues

Part of #925

Fix

Treat an absent jQuery as "no AJAX pending" so the condition resolves immediately instead
of timing out:

$this->waitForJS('return (typeof window.jQuery === "undefined") || window.jQuery.active == 0;', $timeout);
  • On pages with jQuery (all Magento Admin pages): behavior is unchanged — the
    window.jQuery.active == 0 branch is evaluated exactly as before.
  • On pages without jQuery: the check returns immediately, eliminating the double
    full-timeout wait.

The trailing $this->wait(1) settle buffer is intentionally left in place.

Manual testing scenarios

  1. Run any test that navigates to a storefront page not using jQuery and observe that the
    step no longer stalls for ~2 × WAIT_TIMEOUT.
  2. Run existing Admin tests (jQuery present) and confirm timing/behavior is unchanged.

Questions or comments

Isolated one-line change. Follow-ups from #925 (per-step getLog/getCurrentURL chatter,
loading-mask polling, session reuse) will come as separate PRs with timing evidence.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (unit suite green locally; develop)

waitForAjaxLoad() waited on 'window.jQuery.active == 0', but on pages
without jQuery the expression is never truthy, so waitForJS() polls until
it times out and throws; the catch then sleeps another full pageload_timeout.
That is ~2x WAIT_TIMEOUT (60s by default) burned on every call on any
non-jQuery page, for no benefit.

Treat an absent jQuery as 'no AJAX pending' so the check resolves
immediately. Behavior on jQuery pages (all Magento admin pages) is
unchanged.

Ref magento#925
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.

1 participant