从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)>'
#spec / features / comments / 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
#spec / support / helpers / 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
答案 0 :(得分:2)
如果您需要发送Enter键,则不应该在native
上调用任何东西,而应使用小写字母作为符号,然后将其与Poltergeist或Selenium作为驱动程序一起使用
find('input[name="comment[body]"]').send_keys(:enter)
请参见https://www.rubydoc.info/gems/capybara/Capybara/Node/Element#send_keys-instance_method