module Polyblock module CapybaraHelpers def fill_in_polyblock(locator, params={}) # Find out ckeditor id at runtime using its label locator = find('label', text: locator)[:for] if page.has_css?('label', text: locator) # Fill the editor content page.execute_script <<-SCRIPT var ckeditor = CKEDITOR.instances['#{locator}']; ckeditor.setData('#{params[:with]}'); ckeditor.focus(); ckeditor.updateElement(); SCRIPT end def fill_in_inline_polyblock(name, params={}) page.execute_script <<-SCRIPT var element = $('.polyblock[data-pbname="#{name}"]'); var ckeditor = CKEDITOR.instances[element.attr('id')]; ckeditor.fire('focus'); ckeditor.setData('#{params[:with]}'); ckeditor.focus(); ckeditor.updateElement(); SCRIPT end end end