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:

  1. pressButton($button) overrides MinkExtension->pressButton() to call wait() before passing execution back to MinkExtension->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.

  2. 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 the wait() in pressButton() will time out and corresponding form-submit will get blocked by Drupal's autocomplete.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

jhedstrom’s picture

Status: Needs review » Fixed

Merged on github. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sethcohn’s picture

Category: Feature request » Bug report
Issue summary: View changes
Status: Closed (fixed) » Needs work

This is no longer working in Behat 3.0 ?

    And I fill in "Alice" for "Field to fill in"    # Drupal\DrupalExtension\Context\MinkContext::fillField()
    And I press the "Esc" key in the "Field to fill in" field   # Drupal\DrupalExtension\Context\MinkContext::pressKey()

      a is undefined
      Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33'
      System info: host: 'Seth', ip: '192.168.1.xx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.2', java.version: '1.8.0_25'
      Driver info: driver.version: unknown (WebDriver\Exception\UnknownError)

Selenium server returns error above, and behat is working fine otherwise. (Fires up Firefox, other tests work as expected)