Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ChrisTaylorDeveloper/703e206a338b14173779f26dcb01a04f to your computer and use it in GitHub Desktop.
Save ChrisTaylorDeveloper/703e206a338b14173779f26dcb01a04f to your computer and use it in GitHub Desktop.
Testing jQuery autocomplete suggestion list with Behat and Mink

The pre-defined step I fill in "field" with "text" removes focus from the input element and does not hold open the suggestion list. The step definition below resolves this issue.

Feature file step

And I fill in "autocomplete-ajax" with "J" maintaining focus

Step definition

/**
 * @Given I fill in :arg1 with :arg2 maintaining focus
 */
public function iFillInWithMaintainingFocus($element_id, $text)
{
    $script = '$("#' . $element_id . '").val("' . $text . '");';
    $this->getSession()->evaluateScript( $script );
    $element = $this->getSession()->getPage()->findById( $element_id );
    $element->focus();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment