Problem

WebformElementComputedJavaScriptTest::testComputedElementAjax intermittently fails with a StaleElementReference exception or incorrect hidden field values.

Root cause

Three issues:

  1. Wrong method for the select field: The test used fillField for the a[select] element. On select elements, fillField does not reliably fire a change event in WebDriver. selectFieldOption should be used instead.
  2. Field order matters: selectFieldOption fires a change event which triggers the computed element's 500ms debounce AJAX. fillField on a number input does not fire change (only sets the value). So the number field must be filled before the select, ensuring both values are present when the select's change event triggers the AJAX computation.
  3. waitForText is ambiguous: The test form has multiple computed elements (webform_computed_twig and webform_computed_twig_token) that both produce the same visible text "1 + 1 = 2". waitForText scans the entire page and can match the other element's output before the one being asserted has updated, causing the subsequent hiddenFieldValueEquals check to fail.

Fix

  • Use selectFieldOption instead of fillField for the select element
  • Fill the number field (b) before selecting the option (a[select]) so both values are set when AJAX fires
  • Replace the executeScript jQuery call and waitForText with $session->wait() polling for the specific hidden field value by name, which reliably handles the debounce timing and avoids ambiguity with other computed elements on the page

Issue fork webform-3576379

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mably created an issue. See original summary.

mably’s picture

Issue summary: View changes

mably’s picture

Category: Task » Bug report
Status: Active » Needs review

liam morland made their first commit to this issue’s fork.

  • liam morland committed f101dd66 on 6.3.x
    fix: #3576379 Use random numbers in WebformElementComputedJavaScriptTest
    

  • mably committed 55044182 on 6.3.x
    fix: #3576379 Fix flaky WebformElementComputedJavaScriptTest
    

  • liam morland committed f101dd66 on 6.x
    fix: #3576379 Use random numbers in WebformElementComputedJavaScriptTest
    

  • mably committed 55044182 on 6.x
    fix: #3576379 Fix flaky WebformElementComputedJavaScriptTest
    
liam morland’s picture

Status: Needs review » Fixed

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.