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