我已经附上了日志,但是,基本上,我一整天都在和它战斗它在大多数情况下都会成功,但在没有可预测模式的情况下随机失败。
这些也是非常简单的水豚试验:

    t.visit '/signup'
    t.fill_in 'user_email', :with => email
    t.fill_in 'user_password', :with => password
    t.fill_in 'user_password_confirmation', :with => password
    t.click_on 'Create Login'
    expect(page).to have_content('Welcome!')

我不知道是什么原因我很感激你的洞察力。
$ repeat 12 {rspec}

Randomized with seed 64607
.WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
....

Finished in 1 minute 6 seconds (files took 1.94 seconds to load)
5 examples, 0 failures

Randomized with seed 64607


Randomized with seed 64579
WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
.....

Finished in 1 minute 10.06 seconds (files took 2.16 seconds to load)
5 examples, 0 failures

Randomized with seed 64579


Randomized with seed 19540
.WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
....

Finished in 1 minute 9.6 seconds (files took 2.17 seconds to load)
5 examples, 0 failures

Randomized with seed 19540


Randomized with seed 14891
WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
.....

Finished in 1 minute 10.32 seconds (files took 2.27 seconds to load)
5 examples, 0 failures

Randomized with seed 14891


Randomized with seed 18405
WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
..F..

Failures:

  1) User accounts Creating a new account does proceed with valid  information
     Failure/Error: expect(page).to have_content('Welcome!')

     Capybara::Webkit::NodeNotAttachedError:
       Element at 24 no longer present in the DOM
     # ./spec/features/create_account_spec.rb:24:in `block (3 levels) in <top (required)>'

Finished in 1 minute 10.47 seconds (files took 2.36 seconds to load)
5 examples, 1 failure

Failed examples:

rspec ./spec/features/create_account_spec.rb:21 # User accounts Creating a new account does proceed with valid  information

Randomized with seed 18405


Randomized with seed 44934
WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
..F..

Failures:

  1) User accounts Creating a new account responds with an error if a password is invalid
     Failure/Error: t.visit '/signup'

     Capybara::Webkit::TimeoutError:
       Request timed out after 30 second(s)

Finished in 1 minute 37.2 seconds (files took 2.14 seconds to load)
5 examples, 1 failure

Failed examples:

rspec ./spec/features/create_account_spec.rb:34 # User accounts Creating a new account responds with an error if a password is invalid

Randomized with seed 44934


Randomized with seed 2418
WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
.....

Finished in 1 minute 38.48 seconds (files took 2.22 seconds to load)
5 examples, 0 failures

Randomized with seed 2418


Randomized with seed 62514
WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
..F..

Failures:

  1) User accounts Creating a new account does proceed with valid  information
     Failure/Error: expect(page).to have_content('Welcome!')

     Capybara::Webkit::NodeNotAttachedError:
       Element at 25 no longer present in the DOM
     # ./spec/features/create_account_spec.rb:24:in `block (3 levels) in <top (required)>'

Finished in 1 minute 44.84 seconds (files took 2.18 seconds to load)
5 examples, 1 failure

Failed examples:

rspec ./spec/features/create_account_spec.rb:21 # User accounts Creating a new account does proceed with valid  information

Randomized with seed 62514


Randomized with seed 61981
WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
Request to unknown URL: https://api.stripe.com/v1/tokens?...
To block requests to unknown URLs:
  Capybara::Webkit.configure do |config|
    config.block_unknown_urls
  end
To allow just this URL:
  Capybara::Webkit.configure do |config|
    config.allow_url("https://api.stripe.com/v1/tokens?key=pk_test_ahWNI8gsTepFWYX9nnO0Kgxv&payment_user_agent=stripe.js/699b119&card[name]=Bob+Tomato&card[number]=42&card[cvc]=567&card[address_zip]=37069&card[exp_month]=1&card[exp_year]=2026&callback=sjsonp1452131002689&_method=POST&_accept_language=en-US")
  end
To allow requests to URLs from this host:
  Capybara::Webkit.configure do |config|
    config.allow_url("api.stripe.com")
  end
F....

Failures:

  1) User accounts Creating a new account does not proceed if any  information is missing
     Failure/Error: expect(page).to have_content('This Card Number Looks Invalid')
       expected to find text "This Card Number Looks Invalid" in ...
     # ./spec/features/create_account_spec.rb:18:in `block (3 levels) in <top (required)>'

Finished in 1 minute 50.89 seconds (files took 2.41 seconds to load)
5 examples, 1 failure

Failed examples:

rspec ./spec/features/create_account_spec.rb:15 # User accounts Creating a new account does not proceed if any  information is missing

Randomized with seed 61981


Randomized with seed 55263
WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
.....

Finished in 1 minute 27.56 seconds (files took 2.26 seconds to load)
5 examples, 0 failures

Randomized with seed 55263


Randomized with seed 21927
WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
.....

Finished in 1 minute 23.52 seconds (files took 2.22 seconds to load)
5 examples, 0 failures

Randomized with seed 21927


Randomized with seed 8605
WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
....F

Failures:

  1) User accounts Creating a new account does not proceed if any information is missing
     Failure/Error: t.visit '/signup'

     Capybara::Webkit::TimeoutError:
       Request timed out after 30 second(s)

Finished in 1 minute 32.47 seconds (files took 2.02 seconds to load)
5 examples, 1 failure

Failed examples:

rspec ./spec/features/create_account_spec.rb:15 # User accounts Creating a new account does not proceed if any information is missing

Randomized with seed 8605

最佳答案

像这样的零星错误通常是由规范中的计时问题引起的。通常当页面加载时间过长时,页面上不存在的元素。
我发现修复这些类型错误的最简单方法是将您的期望值包装在within block中然后,您的测试实际上将等待找到用于内部块的选择器,然后再继续进行您的期望。
像这样添加内部块

t.visit '/signup'
within "form" do
  t.fill_in 'user_email', :with => email
  t.fill_in 'user_password', :with => password
  t.fill_in 'user_password_confirmation', :with => password
  t.click_on 'Create Login'
end
expect(page).to have_content('Welcome!')

07-24 09:55