Skip to content

Instantly share code, notes, and snippets.

@racheldonovan
Created April 18, 2013 21:55
Show Gist options
  • Save racheldonovan/5416557 to your computer and use it in GitHub Desktop.
Save racheldonovan/5416557 to your computer and use it in GitHub Desktop.
a helper to assit in integration testing (rspec / capybara) wysihtml5 text editors.
module Wysihtml5Helper
def fill_in_wysihtml5(text)
#js must be enabled
page.execute_script("editor.setValue('#{text}')")
end
end
@karledurante
Copy link

10 months later, hooking a brother up. Thanks!

@dannio
Copy link

dannio commented Apr 9, 2015

This only selects the last editor on the page right? What about if there were multiple editors?

@zedtux
Copy link

zedtux commented Apr 27, 2015

@dannio you can use the following in order to access the editor of a specific element:

var editor = $('#some-textarea').data("wysihtml5").editor;
editor.getValue();
editor.setValue('Test');

@RileyMills
Copy link

You are my hero. Was going nuts trying to interact with this in Capybara.

@Carpela
Copy link

Carpela commented May 12, 2017

Getting
ReferenceError: Can't find variable: editor

Assuming it's not instantiated yet, though it certainly should be...

@rfkdali
Copy link

rfkdali commented May 13, 2019

(Thanks to @zedtux) if you got ReferenceError: Can't find variable: editor, you can try this:

page.evaluate_script %{(function() {
  var editor = $('.test-textarea').data("wysihtml5").editor;
  editor.getValue();
  editor.setValue('A text');
})()}

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