在从Poltergeist迁移到Selenium WebDriver / ChromeDriver之后,尝试从旧的Rails 4项目中获取规范。 .native.send_key(:Enter)
周围的典型故障
我们应该切换到等效或最佳实践吗?
17) Comment creation for image changes counter
Failure/Error: find('input[name="comment[body]"]').native.send_key(:Enter)
Selenium::WebDriver::Error::UnsupportedOperationError:
no such key :Enter
# ./spec/support/helpers/comments_page_helpers.rb:13:in `add_comment'
# ./spec/features/comments/creation_spec.rb:72:in `block (4 levels) in <top (required)>'
# ./spec/features/comments/creation_spec.rb:71:in `block (3 levels) in <top (required)>'
#规格/功能/评论/ creation_spec.rb
require 'spec_helper'
feature 'Comment creation', type: :feature, js: true do
...
context 'for image' do
background do
open_image_comments_modal section_position: 1, photo_position: 1
within '.modal-comments-container' do
add_comment 'First comment message'
end
end
...
end
#规格/支持/助理/ comments_page_helpers.rb
module CommentsPageHelpers
...
def add_comment(text)
fill_in 'comment[body]', with: text
find('input[name="comment[body]"]').native.send_key(:Enter)
expect(page).to have_css '.comments .comment-body', text: text
end
...
end
如果您需要发送回车键,则不应在native
上调用任何内容,并且您应该使用小写字母作为符号,然后使用Poltergeist或Selenium作为驱动程序
find('input[name="comment[body]"]').send_keys(:enter)
见https://www.rubydoc.info/gems/capybara/Capybara/Node/Element#send_keys-instance_method