Created
September 9, 2014 23:53
-
-
Save eoinkelly/69be6c27beb0106aa555 to your computer and use it in GitHub Desktop.
A capybara helper to fill in text into a TinyMCE editor instance
This file contains hidden or 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
## | |
# id must be the id attribute of the editor instance (without the #) e.g. | |
# <textarea id="foo" ...></textarea> | |
# would be filled in by calling | |
# tinymce_fill_in 'foo', 'some stuff' | |
# | |
def tinymce_fill_in(id, val) | |
# wait until the TinyMCE editor instance is ready. This is required for cases | |
# where the editor is loaded via XHR. | |
sleep 0.5 until page.evaluate_script("tinyMCE.get('#{id}') !== null") | |
js = "tinyMCE.get('#{id}').setContent('#{val}')" | |
page.execute_script(js) | |
end |
thanks! worked for me. I spent a whole day trying to figure this out and then I found your helper. and now I feel stupid for waiting a whole day to look on stackoverflow
If you have any sort of code snippet or latex, this (very helpful) helper method might not work for you. If I come across a / up with a solution, I'll post it here.
I recommend to use expect(page).to have_css('#tinymce-editor_ifr')
(this waits for an element created by tinymce isntance) instead of sleep 0.5
to make waiting für tinymce more solid and fast
Thanks @eoinkelly and @kjoscha! I adapted it slightly to work with minitest and mimic the syntax of the regular fill_in
method:
# `id` must be the id attribute of the editor instance e.g.
# <textarea id="foo" ...></textarea>
def tinymce_fill_in(id, with:)
assert_css("##{id}_ifr")
js = "tinyMCE.get('#{id}').setContent('#{with}')"
page.execute_script(js)
end
Thanks for sharing @lbraun
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This worked for me, thank you.
However,t if you are improving it, you might like to consider testing if id exists. Currently, if the id does not exist, then the test just hangs.