Skip to content

Instantly share code, notes, and snippets.

@sj26
Created May 28, 2012 06:32
Show Gist options
  • Save sj26/2817695 to your computer and use it in GitHub Desktop.
Save sj26/2817695 to your computer and use it in GitHub Desktop.
Helper for capybara to fill in wysihtml5 fields respecting `within` scopes
module Wysihtml5Helper
def fill_in_html name, options
options.to_options!.assert_valid_keys :with
if Capybara.current_driver == Capybara.javascript_driver
# Dip inside capybara session to respect current `within` scope
scope = page.send(:current_node).path
# Find the textarea based on label name within the given scope
query = "$('label:contains(#{name.inspect}) ~ textarea:eq(0)', document.evaluate(#{scope.inspect}, document).iterateNext())"
# Make sure the editor is instantiated -- this is us, not wysihtml5
wait_until { page.evaluate_script("!!#{query}.data('editor')") }
# Set the value using wysihtml5 api
page.execute_script %{#{query}.data('editor').setValue(#{options[:with].to_json})}
else
fill_in name, options
end
end
end
@rposborne
Copy link

What JS driver are you using to achieve line 6?

Getting Capybara::NotSupportedByDriverError from standard Selenium

@racheldonovan
Copy link

I wasn't able to get this to work, but found an alternative solution, see https://gist.github.com/racheldonovan/5416557

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment