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

window.location="/sports"

      

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:

swipes_spec.rb:

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")
    end
    it "should have link test js" do
      visit swipe_index_path
      page.should have_link("test js")
    end
    it "responds to js", js: true do
      visit swipe_index_path
      click_link "test js"
      page.should have_selector('a', text: "js works")
    end
    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")
      end
      page.should have_selector('h2', text: "Select")
    end
  end
end

      

rocker / index.html.erb:

<h2>Checkout</h2>
<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>
    <div class="form-row">
        <label>CVC</label>
        <input type="text" size="4" autocomplete="off" class="card-cvc"/>
    </div>
    <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"/>
    </div>
    <button type="submit" class="submit-button">Submit Payment</button>
</form>


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


<script type="text/javascript" src="https://js.stripe.com/v1/"></script>
<script type="text/javascript">
    Stripe.setPublishableKey('pk_xIm00GVAKVLMWmfeR2J8GlmeHcyhL');

    $(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) {
            $('.submit-button').removeAttr("disabled");
            //show the errors on the form
            $(".payment-errors").html(response.error.message);

        } 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
            form$.get(0).submit();
        }
    }
</script>

      

+3


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.



-1


source







All Articles