Skip to content

Instantly share code, notes, and snippets.

@fddn
Last active August 1, 2017 10:45
Show Gist options
  • Save fddn/21291efa1800ca548b16429d70d0011c to your computer and use it in GitHub Desktop.
Save fddn/21291efa1800ca548b16429d70d0011c to your computer and use it in GitHub Desktop.
Codeception function to test Select2 dropdown
/**
* Select2Select is for select data from select2 dropdown menu via fill input field
* @param string $id
* @param string $value
*/
public function Select2Select($id, $value)
{
$nonHashmarkId = substr($id, 1);
$this->seeElement($id . ' + .select2');
$this->executeJS('$("' . $id . ' + .select2 .select2-selection").trigger({type: "mousedown", which: 1})');
$this->waitForElementVisible('//*[@id="select2-' . $nonHashmarkId . '-results"]', 5);
// SELECT2 Search input field
$this->fillField('body > .select2-container .select2-search__field', $value);
$this->waitForText($value, 5, '//*[@id="select2-' . $nonHashmarkId . '-results"]');
$this->pressKey('body > .select2-container .select2-search__field', \WebDriverKeys::ENTER);
$this->see($value, $id . ' + .select2-container .select2-selection__rendered');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment