Read more

Cucumber: Wait until CKEditor is loaded

Deleted user #6
February 21, 2014Software engineer

I had to deal with JavaScript Undefined Error while accessing a specific CKEditor instance to fill in text.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

Ensure everything is loaded with

patiently do
  page.execute_script("return isCkeditorLoaded('#{selector}');").should be_true
end

Example

The fill in text snippet for Cucumber:

When /^I fill in the "([^\"]+)" WYSIWYG editor with:$/ do |selector, html|
  patiently do
    page.execute_script("return isCkeditorLoaded('#{selector}');").should be_true
  end
  html.gsub!(/\n+/, "") # otherwise: unterminated string literal (Selenium::WebDriver::Error::JavascriptError)
  page.execute_script("CKEDITOR.instances['#{selector}'].setData('#{html}');")
end

The snippet for JavaScript:

function isCkeditorLoaded(instance_selector) {
  // instance_selector is e.g. 'template_html'
  var status;
  if (window.CKEDITOR && CKEDITOR.instances && CKEDITOR.instances[instance_selector]) {
    status = CKEDITOR.instances[instance_selector].status;
  }
  return status === 'ready';
};
Posted to makandra dev (2014-02-21 11:15)