Capybara(驱动程序 capybara-webkit)偶尔会失败,成功率超过 50%

Capybara (driver capybara-webkit) fails sporadically, succeeds over 50% of the time

我附上了日志,但是,基本上,我整天都在为这个问题而战。它在大多数情况下都会成功,但随后会随机失败且没有可预测的模式。

这些也是非常简单的水豚测试:

    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 中。然后,您的测试实际上会等待找到用于 within 块的选择器,然后再继续您的期望。

像这样添加一个内部块

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!')