If all else fails, you could insert your text using Javascript:
page.execute_script '$("#bibtex").val("' << sample('jabref') << '")'
If you do this often enough, I'd extract this in a helper method (fill_in_plain
or similar), maybe without using the help of jQuery (using plain old Javascript, i.e. document.getElementById
et cetera).
Here's a proper helper, still using jQuery:
module CapybaraWebkitWorkarounds
def fill_in_plain(selector, with: nil)
value = with.gsub '"', "\\\"" # poor man's escaping
page.execute_script %Q{ $("#{selector}").val("#{value}") }
end
end
RSpec.configure do |config|
# make it available in all feature specs
config.include CapybaraWebkitWorkarounds, type: :feature
end
Then, in your feature spec, you'll do simply
feature 'Import a record' do
scenario 'from JabRef' do
fill_in_plain 'textarea[name="bibtex"]', with: sample('jabref')
in_dialog.click_button 'Import'
...
end
end
Please note, that the fill_in_plain
helper now only understands jQuery selector (i.e. CSS selectors) strings as its first argument.