Check redirection with Capybara and Javascript

I am trying to use capybara with rspec to test my rails application. I've simplified one problem:

I click a link and redirects me via javascript



I click this link to capybara and looking for a page to have the "Sports" content but it always fails.

When I open a file on the test server and click the "Submit Payment" method, I am drawn to my sports page. When I look at the selenium tests I can see that no redirects are happening.

Here are the files:


requires "spec_helper"

describe "Swipes" do
  describe "can view index page" do

    it "has checkout in h2" do
      visit swipe_index_path
      page.should have_selector("h2", text: "Checkout")
    it "should have link test js" do
      visit swipe_index_path
      page.should have_link("test js")
    it "responds to js", js: true do
      visit swipe_index_path
      click_link "test js"
      page.should have_selector('a', text: "js works")
    it "responds to button press", js: true do
      visit swipe_index_path
      click_button "Submit Payment"
      wait_until(10) do
        page.has_content?("Select a Sport")
      page.should have_selector('h2', text: "Select")


rocker / index.html.erb:

<span class="payment-errors"></span>
<form action="" method="POST" id="payment-form">
    <div class="form-row">
        <label>Card Number</label>
        <input type="text" size="20" autocomplete="off" id ="card-number" class="card-number"/>
    <div class="form-row">
        <input type="text" size="4" autocomplete="off" class="card-cvc"/>
    <div class="form-row">
        <label>Expiration (MM/YYYY)</label>
        <input type="text" size="2" class="card-expiry-month"/>
        <span> / </span>
        <input type="text" size="4" class="card-expiry-year"/>
    <button type="submit" class="submit-button">Submit Payment</button>

<%= link_to_function "test js", '$(this).html("js works")' %>

<script type="text/javascript" src=""></script>
<script type="text/javascript">

    $(document).ready(function() {
      $("#payment-form").submit(function(event) {
        // disable the submit button to prevent repeated clicks
        $('.submit-button').attr("disabled", "disabled");
        window.location =  "/sports";
        return false;


    function stripeResponseHandler(status, response) {
        if (response.error) {
            //show the errors on the form

        } else {
            var form$ = $("#payment-form");
            // token contains id, last4, and card type
            var token = response['id'];
            // insert the token into the form so it gets submitted to the server
            form$.append("<input type='hidden' name='stripeToken' value='" + token + "'/>");
            // and submit



source to share

1 answer

I had some kind of error. I ran gem update

to update some other gems and this started working. I downloaded QT as well. One of these things made everyone happy.



All Articles