1

Context: I'm testing a rails app with Cucumber/Capybara/PhantomJS/Poltergeist. I have a click_link call in one of my cucumber step definition files. This click_link call then results in Rails calling the show method of a controller. The controller finds an object by a particular id and responds in javascript format (format.js). The response, given by the show.js.erb file, then performs some text string substitution on a Twitter Bootstrap modal dialog box to show a custom status message in the box. The modal dialog box is then displayed.

This all works in production. But it doesn't seem to work in testing. I get an error message " no button with value or id or text 'Close' found (Capybara::ElementNotFound)". Also, puts page.html simply displays this:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">

which makes me think the modal dialog box is never being shown at all. Anyone have any ideas as to what's going on?

cucumber_steps.rb

When /^I click this link$/ do

  click_link "Some link to call show method"

  puts page.html

end

And /^I click close button in the modal box$/ do

   click_button 'Close'

end

HTML in page for modal box for Twitter Bootstrap:

<ul>
  <li><a href="/kites/24" data-remote="true">Some link to call show method</a></li>
</ul>
 :
 :
    <form>

<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

  <div class="modal-header">

    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

    <h3 id="myModalLabel">Modal header</h3>

  </div>

  <div class="modal-body">

    <p>One fine body…</p>

  </div>

  <div class="modal-footer">

    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>

    <button class="btn btn-primary">Save changes</button>

  </div>

</div>

</form>

Rails show method

def show

    @kite = Kite.find(params[:id])

    respond_to do |format|

      format.js

    end

  end

1 Answer 1

2

Close Button Error

You're getting the error because you're using click_button "Close" and the click button doesn't use "Close" for its id or text: <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

To get around error you're getting back I would do the following:

close_button = page.find('button.close')
click_button close_button

General Issue

You've left out a lot of details on your immplementation so it's hard to pin point where you've gone wrong. The first thing I'd check is to ensure you have poltergeist set up in you env.rb file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy