Obromios
Obromios

Reputation: 16383

rspec feature test not finding modal input

I have a rspec test that is trying to fill in a field in pop up modal form. The relevant line is

fill_in 'Name', with: 'Jo Blo'

and the error message is

Capybara::ElementNotFound:
       Unable to find visible field "Name" that is not disabled

which implies it is finding the field but sees it as disabled. However, if I use the capybara-screenshot to view the page at the time of failure, the field is visible and the html for the field is

<div class="field">
        <label for="user_name">Name</label><sup>*</sup><br>
        <input type="text" name="user[name]" id="user_name">
</div>

i.e it is not disabled. The field is in a div#modal_new_user. If I change the test to

expect(page).to have_css '#modal_new_user'
fill_in 'Name', with: 'Jo Blo'

the error message becomes

    Failure/Error: expect(page).to have_css '#modal_new_user'
           expected to find visible css "#modal_new_user" but there were no 

matches. Also found "", which matched the selector but not all filters.

Which seems to imply the modal is not being found, but again, if I look a the capybara screenshot, the html for the modal is visible. How do I fix this?

I am using capybara 3.0.2 and rspec-rails 3.7.2.

The code for bootstrap modal is

 <div id='modal_new_user' class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">Warning</h4>
          <p>enter code here Right now there is a 10 day free trial. Just fill in the form below.</p>
      </div>
      <div class="modal-body">
    <form class="edit_user" id="edit_user_12004" action="/users" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="&#x2713;" /><input type="hidden" name="authenticity_token" value="306T/5kB9pqb9sW6mdW+tXyCzfydEF2tf8wQMJXEICO5uQ/YEDVVYqg12l7Qe+lU4uELZy/d1VIhzZObk/FVcQ==" />

      <div class="field">
        <label for="user_name">Name</label><sup>*</sup><br />
        <input type="text" name="user[name]" id="user_name" />
      </div>
      <div class="field">
        <label for="user_email">Email</label><sup>*</sup><br />
        <input type="email" name="user[email]" id="user_email" />
      </div>
      <div class="field">
        <label for="user_password">Password</label><sup>*</sup><br />
        <input type="password" name="user[password]" id="user_password" />
      </div>

      <p id="terms">By creating your account, you are agreeing to the site <a target="_blank" href="/legal">Terms and Conditions</a>.  You will not be spammed, we dislike spam as much as you do.
      </p>
      <input type="hidden" value="clubs#edit" name="user[referral]" id="user_referral" />
      <div class="actions">
      <input type="submit" name="commit" value="Join Now" class="btn btn-cta btn-cta-primary" data-disable-with="Join Now" />
      </div>
</form>  </div>
  <div class="modal-footer right_close_button">
      <button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
  </div>
</div>

Upvotes: 0

Views: 1391

Answers (1)

Obromios
Obromios

Reputation: 16383

It turned out that the test had type: :system, so when I removed this, the test passed. It appears there is an issue with rails system tests if puma.rb specified concurrency.

Upvotes: 0

Related Questions