rspec - How to set text into Summernote textarea with Capybara + Poltergeist -
i have textarea using summernote , set onchange event it. want write test rspec + capybara + poltergeist confirm onchange event working.
as far checked, textarea displayed in browser div tag 'note-editable' css class. how can set text , fire onchange event?
i wrote code this, got error capybara::elementnotfound: unable find field "some label"
:
visit edit_foo_path fill_in 'some label', with: 'foo bar'
edit
i created sample app issue:
https://github.com/junichiito/summernote-rspec-sandbox
raw html
<!doctype html> <html> <head> <title>summernoterspecsandbox</title> <link rel="stylesheet" media="all" href="/assets/application.self-f866ffa01bf26be2b8a8ac982e49d917be3b9a46604dfdc9fc8c139b62409465.css?body=1" data-turbolinks-track="true" /> <script src="/assets/jquery.self-d03a5518f45df77341bdbe6201ba3bfa547ebba8ed64f0ea56bfa5f96ea7c074.js?body=1" data-turbolinks-track="true"></script> <script src="/assets/jquery_ujs.self-ca5248a2fad13d6bd58ea121318d642f195f0b2dd818b30615f785ff365e8d1f.js?body=1" data-turbolinks-track="true"></script> <script src="/assets/bootstrap.self-2bbd2c0465f01b1f8270958ddfc2e62a08915f295a35d22df2971eb936cf3c64.js?body=1" data-turbolinks-track="true"></script> <script src="/assets/summernote.self-612431947ae9c3f1f0283dbbbc757153947f8e5de408f9bd8886b1232e8a54f7.js?body=1" data-turbolinks-track="true"></script> <script src="/assets/blogs.self-b9a3bc0ee16e0bc44fb466bd5c7833ebec276447634d25729280397c65cff176.js?body=1" data-turbolinks-track="true"></script> <script src="/assets/application.self-f8806224e027f3e3f0138ea9ce99319e298dfdb323304d1f1be6eae8e8c74724.js?body=1" data-turbolinks-track="true"></script> <meta name="csrf-param" content="authenticity_token" /> <meta name="csrf-token" content="4iu31ugtgvmerb1xqrjtcyssssjmthlwclgihme60ahgmec3imenkzlkffskt33hnuvdquuguntuaqecobl9mw==" /> </head> <body> <h1>new blog</h1> <form class="new_blog" id="new_blog" action="/blogs" accept-charset="utf-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="authenticity_token" value="tbkcvk38/42cx9coe717kkpb1h2cmdpv8kz7lrefkiloa0s3hsjwvx/mfg2w6uu6ucklhbuoeg1ufdgtdrw+ew==" /> <div class="field"> <label for="blog_title">title</label><br> <input type="text" name="blog[title]" id="blog_title" /> </div> <div class="field"> <label for="blog_content">content</label><br> <textarea class="summernote" name="blog[content]" id="blog_content"> </textarea> </div> <div class="actions"> <input type="submit" name="commit" value="create blog" /> </div> </form> <a href="/blogs">back</a> </body> </html>
coffeescript
$ -> $('.summernote').summernote()
rspec
require 'rails_helper' feature 'blogs' scenario 'create blog' visit new_blog_path fill_in 'title', with: 'hello, world!' fill_in 'content', with: 'this awesome blog.' click_button 'create blog' expect(page).to have_content 'blog created.' expect(page).to have_content 'hello, world!' expect(page).to have_content 'this awesome blog.' end scenario 'create blog js', js: true visit new_blog_path fill_in 'title', with: 'hello, world!' pending 'capybara::elementnotfound: unable find field "content"' fill_in 'content', with: 'this awesome blog.' click_button 'create blog' expect(page).to have_content 'blog created.' expect(page).to have_content 'hello, world!' expect(page).to have_content 'this awesome blog.' end end
capybaras fill_in works html form elements. since js version of page using div contenteditable attribute text area filled #fill_in not work. instead need find div , call #set on directly. in project following should work
find('div[contenteditable]').set('this awesome blog.')
Comments
Post a Comment