Created
May 28, 2012 06:32
-
-
Save sj26/2817695 to your computer and use it in GitHub Desktop.
Helper for capybara to fill in wysihtml5 fields respecting `within` scopes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
What JS driver are you using to achieve line 6?
Getting Capybara::NotSupportedByDriverError from standard Selenium