See https://github.com/jhedstrom/drupalextension/pull/17
Drupal's autocomplete is awfully incompatible with Mink. While it is easy to open an autocomplete suggestion box with setValue()
or 'I fill in "LABEL" with "VALUE"', it is impossible to close the resulting autocomplete suggestion box without writing tricky custom code or something really ugly like 'Press "save", Wait for one second, Press "save"'.
And if the autocomplete suggestion boxes are not closed, then form-submission fails, because they are blocked by Drupal's autocomplete.js
.
This patch introduces two methods to improve the situation:
-
pressButton($button)
overridesMinkExtension->pressButton()
to callwait()
before passing execution back toMinkExtension->pressButton()
.wait()
uses a javascript condition parameter that waits for any#autocomplete
suggestion boxes to close. If there are none open, Mink will not wait, so there is no performance impact for pages that don't ever open an autocomplete suggestion list.This new method duplicates the features of the existing method
assertPressButton()
, so I have deleted that one, and included the corresponding@When
step definition in the new method. -
pressKey($char, $field)
allows a key to be "pressed" on a field. Special keys like escape, enter and tab are supported. Support for other special keys would be useful. This is necessary to allow autocomplete suggestion boxes to be closed. If they are not closed, then thewait()
inpressButton()
will time out and corresponding form-submit will get blocked by Drupal'sautocomplete.js
.NOTE once Behat/Mink#345 is merged we can detect whether there are still any autocomplete boxes open by evaluating
wait()
's return value. We should do that and possibly even throw an exception or warning if there are boxes that are still open.The step definition for the new method is
/^(?:|I )press the "([^"]*)" key in the "([^"]*)" field$/
. E.g.And I press the "Esc" key in the "LABEL" field
Patch is in the form of a GitHub pull request: https://github.com/jhedstrom/drupalextension/pull/17
Comments
Comment #1
jhedstromMerged on github. Thanks!
Comment #3
sethcohn CreditAttribution: sethcohn commentedThis is no longer working in Behat 3.0 ?
Selenium server returns error above, and behat is working fine otherwise. (Fires up Firefox, other tests work as expected)