Skip to content

Instantly share code, notes, and snippets.

@johnennewdeeson
Created January 17, 2016 21:22
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnennewdeeson/240e2b60c23ea3217887 to your computer and use it in GitHub Desktop.
Save johnennewdeeson/240e2b60c23ea3217887 to your computer and use it in GitHub Desktop.
CKEditor fill in field in a Behat step definition
/**
* @Then I fill in wysiwyg on field :locator with :value
*/
public function iFillInWysiwygOnFieldWith($locator, $value) {
$el = $this->getSession()->getPage()->findField($locator);
if (empty($el)) {
throw new ExpectationException('Could not find WYSIWYG with locator: ' . $locator, $this->getSession());
}
$fieldId = $el->getAttribute('id');
if (empty($fieldId)) {
throw new Exception('Could not find an id for field with locator: ' . $locator);
}
$this->getSession()
->executeScript("CKEDITOR.instances[\"$fieldId\"].setData(\"$value\");");
}
@mathiasselleslach
Copy link

Many thanks for this!

@joejoseph00
Copy link

works great, thanks!

@bmxpapr
Copy link

bmxpapr commented Feb 7, 2019

You saved my day, thanks :)

@duddelito
Copy link

Saved my day too :)

@duddelito
Copy link

When I had to tag my scenario with @javascript my normal line And I fill in "field" with "value" stopped working. Now it's working fine again thanks to this :)

@francebenoit
Copy link

francebenoit commented Oct 28, 2021

Thanks a lot ! Still useful 6 years later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment