0
votes

I have a form which I am submitting using remote=>true

<%= form_tag fetch_data_path, :remote => true do %> 
    Date: <%= text_field_tag :date %>
    Amount:<%= text_field_tag :amount %>
    From:<%= text_field_tag :from %>
    To:<%= text_field_tag :to %>

 <%= submit_tag "Convert"%> &nbsp;

<% end %>


<span style="font-weight: bold;">Converted Amount:</span> 
<div id="converted_amount"></div>

On submitting the form, the converted value is displayed in the div with id

#converted_amount

Here is my rspec:

RSpec.feature "User performs exchange", :type => :feature do
  scenario "with valid input" do
    visit exchanges_path
    fill_in 'date', :with => "2017-08-24"
    fill_in 'amount', :with => "100"
    fill_in 'from', :with => "pound"
    fill_in 'to', :with => "dollar"
    click_button('Convert')

    expect(page).to have_text("Converted Amount:")
  end
end

The issue is that when I run it, I get

Capybara::ElementNotFound: Unable to find xpath "/html" and yet when I comment out click_button, it works.

What am I doing wrong?

1
What driver are you using with Capybara? Additionally, what version of Capybara and the specific driver are you using?Thomas Walpole
capybara (2.15), capybara-webkit (1.14.0)Kim
I should mention that I am using Ruby on Rails 3.2Kim

1 Answers

0
votes

Here is my solution:

I added the following gems to my Gemfile

  gem 'capybara-webkit'
  gem 'selenium-webdriver'

and then added :js => true to my spec file. It became:

RSpec.feature "User performs exchange", :type => :feature do
  scenario "with valid input", :js => true do
    visit exchanges_path
    fill_in 'date', :with => "2017-08-24"
    fill_in 'amount', :with => "100"
    fill_in 'from', :with => "pound"
    fill_in 'to', :with => "dollar"
    click_button('Convert')

    expect(page).to have_text("Converted Amount:")
  end
end