Problem/Motivation

The "attachFile()" function, declared in line 50 of DrupalSelenium2Driver, fails due to race condition when called in quick succession.

While creating tests for "drupal/photoswipe", I used the attachFile() function, to attach pictures to two different fields, see here (testTwoPhotoswipeFieldFormatterOnNodeDisplay()), using this code:

$image_realpath = $this->container->get('file_system')->realpath($image->uri);
$image_upload_field->attachFile($image_realpath);
$this->assertNotEmpty($session->waitForElementVisible('css', 'input[id*="edit-field-test-0-alt"]'));
$image_upload_field_2->attachFile($image_realpath);
$this->assertNotEmpty($session->waitForElementVisible('css', 'input[id*="edit-field-test2-0-alt"]'));
$page->pressButton('edit-submit');

For some reason this did not work, because the second "attachFile()" was not called and therefore, the second alt text would not appear. I fixed this with waiting 2 seconds between attaching and checking for the alt texts right before I submit the form:

    $image_realpath = $this->container->get('file_system')->realpath($image->uri);
    $image_upload_field_2->attachFile($image_realpath);
    $page->waitFor(2, function () {
      return FALSE;
    });
    $image_upload_field->attachFile($image_realpath);
    $this->assertNotEmpty($session->waitForElementVisible('css', 'input[id*="edit-field-test-0-alt"]'));
    $this->assertNotEmpty($session->waitForElementVisible('css', 'input[id*="edit-field-test2-0-alt"]'));
    $page->pressButton('edit-submit');

"attachFile()" is not used much in core, so there isn't a test calling this method in quick succession, reporting this so future tests won't fail because of it.

The tests are soon uploaded for the photoswipe module: https://www.drupal.org/project/photoswipe.

Comments

Grevil created an issue. See original summary.

Version: 10.0.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.