Testing CKEditor in Ruby on Rails with Cucumber/Capybara

I have a textarea with the id of “request_details”, made into a CKEditor instance by jQuery: $(‘#request_details’).ckeditor();

(Check this page if you need some help getting CKEditor to work with jQuery, it’s dead simple)

Feature looks like this:  And I fill in "Here are some details" in the CKEditor instance "request_details"

Step looks like this:

When /^I fill in "([^"]*)" in the CKEditor instance "([^"]*)"$/ do |value, input_id|
browser = page.driver.browser
browser.execute_script("CKEDITOR.instances['#{input_id}'].setData('#{value}');")
end

8 Comments

  1. Most helpful, thanks.

    To be complete, it’s probably best to replace the ‘#{value}’ with #{value.to_json}, as this will escape quotes and thus avoid potential javascript errors.

    @Michael: Works perfectly for me with capybara-webkit

Leave a Reply

Your email address will not be published. Required fields are marked *