Created
October 12, 2015 12:49
-
-
Save johnennewdeeson/22dd976773e7d6d608e6 to your computer and use it in GitHub Desktop.
Use behat extension to fill in a Drupal autocomplete field and select the right option which appears.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @When I fill in the autocomplete :autocomplete with :text and click :popup | |
*/ | |
public function fillInDrupalAutocomplete($autocomplete, $text, $popup) { | |
$el = $this->getSession()->getPage()->findField($autocomplete); | |
$el->focus(); | |
// Set the autocomplete text then put a space at the end which triggers | |
// the JS to go do the autocomplete stuff. | |
$el->setValue($text); | |
$el->keyUp(' '); | |
// Sadly this grace of 1 second is needed here. | |
sleep(1); | |
$this->minkContext->iWaitForAjaxToFinish(); | |
// Drupal autocompletes have an id of autocomplete which is bad news | |
// if there are two on the page. | |
$autocomplete = $this->getSession()->getPage()->findById('autocomplete'); | |
if (empty($autocomplete)) { | |
throw new ExpectationException(t('Could not find the autocomplete popup box'), $this->getSession()); | |
} | |
$popup_element = $autocomplete->find('xpath', "//div[text() = '{$popup}']"); | |
if (empty($popup_element)) { | |
throw new ExpectationException(t('Could not find autocomplete popup text @popup', array( | |
'@popup' => $popup)), $this->getSession()); | |
} | |
$popup_element->click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can simply use
Given I fill in "My Autocomplete Value" for "my_autocomplete_field"