2

I am using an @javascript test in Behat on CircleCI to check my Drupal 8 site.

When I use the standard I fill in "my field" with "value" step, it works for fields with the plain text format, but it fails for fields that use CKEditor.

How can I fill in fields on CKEditor?

1 Answer 1

2

This doesn't yet have official support in the Drupal Extension. The linked thread has some examples that use traits.

However, I found this gist by johnennewdeeson to be a faster, easier solution for me, just cut and paste into FeatureContext.php:

  /**
   * @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\");");
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.