Module: Polyblock::CapybaraHelpers
- Defined in:
- lib/polyblock/capybara_helpers.rb
Instance Method Summary collapse
- #fill_in_inline_polyblock(name, params = {}) ⇒ Object
- #fill_in_polyblock(locator, params = {}) ⇒ Object
Instance Method Details
#fill_in_inline_polyblock(name, params = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/polyblock/capybara_helpers.rb', line 33 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].gsub("'", "\\\'")}'); ckeditor.focus(); ckeditor.updateElement(); }, 1); SCRIPT sleep 0.1 end |
#fill_in_polyblock(locator, params = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/polyblock/capybara_helpers.rb', line 3 def fill_in_polyblock(locator, params={}) # Find out ckeditor id at runtime using its label # if page.has_css? "##{locator}" locator = locator.to_s if locator.is_a? Symbol if !locator.include?(' ') && page.evaluate_script("$('##{locator}').is('*')") # Locator is fine as is for capybara. # elsif page.has_css? 'label', text: locator elsif page.evaluate_script("$(\"label:contains('#{locator}')\").is('*')") locator = find('label', text: locator)[:for] elsif page.evaluate_script("$(\"label:contains('#{locator.titleize}')\").is('*')") locator = find('label', text: locator.titleize)[:for] elsif page.evaluate_script(( sel = "$(\"label[for$='_#{locator.underscore}_attributes_content']\")" ) + '.is("*")') locator = find('label', text: page.evaluate_script(sel+'.text()'))[: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].gsub("'", "\\\\'")}'); ckeditor.focus(); setTimeout(function(){ ckeditor.updateElement(); }, 1); SCRIPT sleep 0.1 end |