Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capybara::Apparition::WrongWorld when waiting for a page to redirect #45

Open
macfanatic opened this issue Mar 27, 2020 · 1 comment
Open

Comments

@macfanatic
Copy link

First time using this instead of any other JS drivers, so thanks for the framework and exciting!

I'm trying to write a test for a Stripe checkout.js page (subscribing to a plan) and get intermittent failures. I'm trying to use capybara matchers that wait for the page to change before asserting that things happen. I haven't tried with a chromedriver based setup yet, but I imagine it will work.

For the script below, a sleep will cause capybara to wait and the assertions work. If I try to use the content changing on the page (content or css) then it fails intermittently. It appears the page object is stale while the redirect is happening?

Any thoughts or recommendations?

require 'rails_helper'

RSpec.feature 'Subscriptions' do
  let(:user) { create(:user) }

  background do
    login_user(user)
  end

  context 'as a new customer' do
    background do
      visit organization_path
    end

    scenario 'I can subscribe', js: true do
      click_link 'Subscribe Now'

      expect do
        within 'form.new_pay_subscription' do
          select 'Freelancer Plan', from: 'Subscription Plan'
          fill_in 'Name on Card', with: 'Johnny Appleseed'
          fill_stripe_elements(card: '4111 1111 1111 1111') # stripe elements for interacting with iframe contents

          click_link_or_button 'Create Subscription'
        end

        # ----HERE----
        #
        # If I simply sleep after the button is clicked, enough time is given for the
        # page to redirect and my assertions below pass.
        #
        # If I am a "good" capybara dev and wait for visual or DOM changes to indicate my
        # operation has completed instead, I get failures.  I have tried several with the same outcome.
        #

        # WORKS, not ideal obviously and brittle
        # sleep 2 

        # all of the following will fail and raise an exception about being in the wrong world
        # they are not consistent about failing with this error.  I'm assuming that the faster the operation
        # completes and the page moves one (without the sleep of course) that the failure occurrs. 

        # expect(page).to have_no_css('form.new_pay_subscription')
        # expect(page).to_not have_css('form.new_pay_subscription')
        # expect(page).to have_current_path(after_registration_path)

      end.to change { user.organization.subscriptions.count }.by(1)
    end
  end
@macfanatic
Copy link
Author

I feel like this is the same scenario, using different methods/interactions, as originally described in issue #12 and resolved in this SHA: 2537511

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant