Problem/Motivation

Some tests are sometimes a bit flaky, let's try to improve that.

Issue fork pathauto-3573353

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

Status: Active » Needs review

Problem

PathautoLocaleTest::testLanguagePatterns was intermittently failing on CI with:

The text "Pattern French articles saved." was not found anywhere in the text of the current page.

The first pattern creation had sleep(1) after the AJAX request for the type selector, but the second pattern creation had no wait at all. On slow CI environments, the AJAX-loaded form fields were not ready when submitForm() tried to interact with them.

Additionally, both FunctionalJavascript test classes were missing the #[RunTestsInSeparateProcesses] attribute required since Drupal 11.3.

Changes

  • Replaced sleep(1) with waitForField('pattern') as a targeted wait after the AJAX request completes.
  • Extracted addPathautoPattern() helper method to ensure both pattern creations use the same consistent wait behavior.
  • Added waitForElementVisible() in enableArticleTranslation() after checking the entity_types[node] checkbox.
  • Added #[RunTestsInSeparateProcesses] and #[Group] attributes to PathautoLocaleTest and PathautoUiTest as required by Drupal 11.3+.
  • Added waitForField('pattern') to PathautoUiTest after AJAX.
  • Added void return types to test methods.
mably’s picture

Assigned: Unassigned » berdir
berdir’s picture

Status: Needs review » Reviewed & tested by the community

Using the waitFor methods certainly makes sense, the sleep tends to be very old stuff from before those existed.

  • mably committed ee8732ce on 8.x-1.x
    task: #3573353 Improve flaky tests
    
    By: mably
    By: berdir
    
mably’s picture

Assigned: berdir » Unassigned
Status: Reviewed & tested by the community » Fixed

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.

mably’s picture

Continuation of flaky FunctionalJavascript test fixes.

Use selectFieldOption() for the pattern type select

The pattern type <select> triggers an AJAX request on change. fillField() doesn't properly trigger the change event on select elements, leading to unreliable AJAX behavior. Replaced with selectFieldOption() followed by assertExpectedAjaxRequest(1) in both test classes (see change record). This also allowed removing the unnecessary waitForField() calls and the workarounds in PathautoLocaleTest (waitForElementVisible() for machine name, separate fillField('label')).

Replace pageTextContains with waitForText after form submissions

pageTextContains() does not wait for the page to load after a submitForm() — it checks immediately, which causes flaky failures when the browser hasn't finished navigating. Replaced with assertTrue(waitForText(...)) where the text check is the primary assertion, or bare waitForText() where it only serves as a synchronization point before subsequent assertions.

Other fixes

  • Added waitForText() after node creation and content language settings submitForm() to ensure the page has finished loading before proceeding.
  • Added waitForText('Page pattern') after the weight save form to wait for page reload before interacting with the dropbutton.
  • Removed duplicate 'type' key from $edit array in PathautoUiTest — the type select is already set via selectFieldOption() before submitForm(), including it in $edit would re-trigger the AJAX.
  • Used ConfigurableLanguage::createFromLangcode('fr') instead of the UI language add form for more reliable test setup.
  • Moved pattern save assertions into addPathautoPattern() to avoid checking stale page text after navigation.

  • mably committed 80896214 on 8.x-1.x
    task: #3573353 Improve flaky tests (2)
    
    By: mably
    

Status: Fixed » Closed (fixed)

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