User login

Testing an image file upload for Drupal 8 with Behat, maddeningly requiring a web driver with JavaScript

For a how-to, see Using JavaScript in Behat tests (manual steps for installing, running).

For my stumbling around in the dark... read on.

On the unenviable proposition of having to add JavaScript support to Behat

behat mink extension cannot find fields

Claims it will find it on id, name, anything, and that looks straightforward:
http://mink.behat.org/en/latest/guides/traversing-pages.html
My problem was not what other people had: http://stackoverflow.com/questions/27288332/why-behat-mink-cantt-find-input-field-by-id-only-by-name
For me it seems to only work when i search for the field by label

mink js
phantomjs behat
uploading file with phantomjs

PhantomJs looks the easiest to install (just download, no Java or npm): http://phantomjs.org/download.html

And use like this:
https://github.com/jmauerhan/phantomjs-behat-selenium-example

With feature https://github.com/jmauerhan/phantomjs-behat-selenium-example/blob/master/features/hello-world.feature

So PhantomJS is working ... but not for uploading the image it seems. At least, it doesn't care if i gave it a nonexistent filename, it never causes the alt text field to show up...

Here's how it's probably doing it under the hood-- don't know where to look to see how Behat maps to PhantomJS
http://phantomjs.org/api/webpage/method/upload-file.html

The issues other people have is it hanging indefinitely:

drupal 8 "Alternative text" for image requires JavaScript

Should the Alternative text field for images really require JavaScript to input? It seems rather anti-accessibility.


@javascript
@api
Scenario: A content editor can add an image paragraph
Given I am logged in as a user with the "content_editor" role
And I go to "/node/add/work"
When I fill in "Title" with "The Checklist Manifesto"
And I select the radio button "Training"
And I press the "List additional actions" button
And I press the "Add Image" button
And I wait for AJAX to finish
Then I should not see the text "Alternative text"
And I fill in "This is not actually a video grid" for "Caption"
And I attach the file "Video-Grid-Item.png" to "Image"
And I wait for AJAX to finish
Then I should see the error message containing "File upload error"
Then I should see the text "Alternative text"
And I wait for AJAX to finish
And I fill in "A video grid item" for "Alternative text"

OK i got this error trying to add an image myself:

File upload error. Could not move uploaded file.
This value should not be null.

So probably that's why the alternative text field isn't showing up.

I wish behat tests would automatically tell you what status codes they get, what error messages they see etc. when they fail.

See also:
https://davidwinter.me/testing-javascript-websites-with-behat/

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.