It would be helpful to have a class indicate when the editor is fully loaded. The closest thing we have now is a 'ckeditor-processed' class which is added when the editor is initialized, but at this time the editor is not yet fully usable.

I need this to be able to test the editor using Selenium. I need a reliable marker that indicates when the editor is ready to accept user input.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pfrenssen’s picture

Status: Active » Needs review
FileSize
909 bytes
pfrenssen’s picture

Status: Needs review » Fixed

I have found a way to do this in phpunit-selenium without having to set a class. We can wait until the instance becomes populated in the javascript variable space:

    /**
     * Waits until the CKEditor with the given id is ready to accept input.
     *
     * @param string $editor_id
     *   The CKEditor id.
     */
    protected function waitUntilCKEditorInstanceReady($editor_id)
    {
        $this->waitUntilJavascriptVariableIsDefined('CKEDITOR.instances["' . $editor_id . '"]');
    }

    /**
     * Wait until a javascript variable is defined.
     *
     * @param string $variable
     *   The name of the variable.
     */
    protected function waitUntilJavascriptVariableIsDefined($variable)
    {
        $webdriver = $this->webdriver;
        $this->webdriver->waitUntil(function () use($webdriver, $variable) {
            return 'undefined' != $webdriver->execute(array(
                'script' => 'return typeof ' . $variable . ';',
                'args' => array(),
            ));
        }, $this->webdriver->getTimeout());
    }

Call it with the id of the textarea that is to receive the text, for example:

  $this->waitUntilCKEditorInstanceReady('edit-body-und-0-value');

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.