Sha256: 17f2e159c6a61f071a142f587e9d5961fd6e618bfe07e2c1c8012418b0c585b7

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

module Polyblock
  module CapybaraHelpers
    def fill_in_polyblock(locator, params={})
      # Find out ckeditor id at runtime using its label
      # if page.has_css? "##{locator}"
      if page.evaluate_script("$('##{locator}').is('*')")
      # elsif page.has_css? 'label', text: locator
      elsif page.evaluate_script("$(\"label:contains('#{locator}')\").is('*')")
        locator = find('label', text: locator)[:for]
      else
        raise "Locator #{locator} not found!!"
      end
      # Fill the editor content
      page.execute_script <<-SCRIPT
          var ckeditor = CKEDITOR.instances['#{locator}'];
          ckeditor.setData('#{params[:with]}');
          ckeditor.focus();
          setTimeout(function(){
            ckeditor.updateElement();
          }, 1);
      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')];
          setTimeout(function(){
            ckeditor.fire('focus');
            ckeditor.setData('#{params[:with]}');
            ckeditor.focus();
            ckeditor.updateElement();
          }, 1);
      SCRIPT
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
polyblock-1.0.5 lib/polyblock/capybara_helpers.rb
polyblock-1.0.4 lib/polyblock/capybara_helpers.rb
polyblock-1.0.3 lib/polyblock/capybara_helpers.rb
polyblock-1.0.2 lib/polyblock/capybara_helpers.rb
polyblock-1.0.1 lib/polyblock/capybara_helpers.rb
polyblock-1.0.0 lib/polyblock/capybara_helpers.rb