In a Functional test, I am doing:


    $page->fillField('title[0][value]', 'Page 1 EN');

    $page->pressButton('Add image');
    // Using TestFileCreationTrait::getTestFiles().
    $image = current($this->getTestFiles('image'));
    $page->attachFileToField('field_image', $this->container->get('file_system')->realpath($image->uri));

This appears to work, in that if I then do:


I get a form error because the image alt text is required.

But this doesn't work:

    $page->fillField('field_image[0][alt]', 'Image alt text EN');

and in the browser output, I don't see the subfields for the image.

In FunctionalJavascript tests that use attachFileToField(), there's typically a waitForFoo() call which waits for the form AJAX to update and show the image subfields.

But that's not available in Functional tests, and besides, there's no AJAX since there's no JS.

How can I get this to work?

(I'd really rather not use drupalPost() to send a massive edit array; using Mink to fill fields one by one is much better DX I find.)

1 Answer 1


Ah, it looks like this might do it:

    $page->fillField('field_image[0][alt]', 'Image alt text EN');
    // This reloads the page and the alt text field is now present.
  • I think it'd be more helpful for others if you update your answer with the full solution, i.e. where are you adding this line of code.
    – sonfd
    Commented Apr 30, 2021 at 11:55
  • Added the original line in the answer for context.
    – joachim
    Commented Apr 30, 2021 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.