How to set text into Summernote textarea with Capybara + Poltergeist

前端 未结 2 412
借酒劲吻你
借酒劲吻你 2021-01-19 14:20

I have a textarea which is using Summernote and I set onChange event to it. I want to write test with RSpec + Capybara + Poltergeist to confirm the onChange event is working

相关标签:
2条回答
  • 2021-01-19 14:47

    After updating Summernote to 0.8.2, find('div[contenteditable]').set('This is awesome blog.') does not work.

    I had to call Summernote API via execute_script like:

    script = <<-JS
    $('.some-field').summernote('editor.insertText', 'This is awesome blog.');
    JS
    execute_script(script)
    

    EDIT

    After updating Summernote to 0.8.2, find('div[contenteditable]').set('This is awesome blog.') does not work.

    Sorry, this was not what I wanted to say. I should have said like this:

    After updating Summernote to 0.8.2, find('div[contenteditable]').set('This is awesome blog.') does not fire Summernotes's onChange callback. So I had to call execute_script.

    I have to test onChange behavior in my specs.

    EDIT 2

    As Thomas Walpole wrote, send_keys method could be used instead of execute_script. Thanks Thomas Walpole!

    find('div[contenteditable]').send_keys('This is awesome blog.')
    
    0 讨论(0)
  • 2021-01-19 14:54

    Capybaras fill_in only works with html form elements. Since the JS version of your page is using a DIV with the contenteditable attribute as its text area to be filled #fill_in will not work. Instead you need to find the div and call #set on it directly. In your project the following should work

    find('div[contenteditable]').set('This is awesome blog.')
    
    0 讨论(0)
提交回复
热议问题