TinyMCE not being saved when submitting using capybara and selenium

117 Views Asked by At

I have this feature test in rspec

 fill_in "Name", "title"
 #fill_in "Body", "my blog" # this is the old implementation before tinymce 
 within_frame("mce_0_ifr") do 
   page.driver.browser.find_element(:id, 'tinymce').send_keys("blog 123")
   puts page.html
 end
 click_button "Submit"

From the output I can clearly see that the word "blog 123" was written in the body via

<body id="tinymce"><p>blog 123</p></body>

But I get a test fail because it does not create a new blog post.

1

There are 1 best solutions below

0
Berimbolo On

Turns out the code is fine. I was getting an error due to tinymce and html5 required validation not working together. Therefore the data is never sent, and capybara moves on to the next expect thus rendering an error. Just incase someone get's into this problem I'll post how I solved it.

 <script>
  tinymce.init({
    selector: "textarea.tinymce",
    editor.on('change', function () {
      editor.save();
    })
})
</script>