Capybara rspec测试需要很长时间才能执行 - 为什么?

时间:2016-04-20 01:10:08

标签: ruby-on-rails ruby rspec capybara capybara-webkit

我有一个使用rspec 3.4.0 capybara 2.6.2capybara-webkit 1.8.0的rails项目。

我有一个简单的功能测试,如下所示:

require 'rails_helper'

RSpec.feature "Seller Features", type: :feature do

  let!(:sub_category) { FactoryGirl.create(:sub_category) }

#all tests will create a user - sign them in and land them on the homepage
  background do
    sign_in_as
  end

 scenario "Buyer creates a seller profile", :js => true do

   click_link("SELL ON SITE",match: :first)
   expect(page).to have_text("Reach thousands of customers in your area")
   click_link("Create an Activity",match: :first)
   expect(current_path).to eql (new_seller_profile_path)

    fill_in "seller_profile[business_name]", :with => "Test company"
    fill_in "seller_profile[business_email]", :with => "test@email.com"
    fill_in "seller_profile[business_phone_number]", :with => "07771330510"
    fill_in "seller_profile[business_description]", :with => "This is a test company"

    find('label[for="social"]').click


    find("#facebook-placeholder").click

    fill_in "seller_profile[business_facebook_url]", :with => "https://www.facebook.com/test"

    click_button("CREATE AN ACTIVITY")

    fill_in "seller_profile[requested_postcode]", :with => "EH21 8PB"

    click_button("Submit")

    click_link("Continue")

    expect(page).to have_text("Choose the type of activity that you want to create")

 end

end

测试通过成功。问题是需要这么长的时间才能运行:

Finished in 4 minutes 26.2 seconds (files took 7.19 seconds to load)

这看起来非常漫长!在执行期间我的CPU几乎空闲,所以我不确定是什么导致执行时间长度?对于这样一个简单的功能测试,这是一个合理的正常时间吗?!请帮忙!

我不知道这是否会有所帮助,但这是我的spec_helper.rb文件:

ENV["RAILS_ENV"] ||= "test"
ENV['SERVER_NAME'] = "user.myapp.com"

require File.expand_path("../../config/environment", __FILE__)
require "rspec/rails"


Capybara::Webkit.configure do |config|
  # Enable debug mode. Prints a log of everything the driver is doing.
  config.debug = false

  config.allow_unknown_urls
  # Allow pages to make requests to any URL without issuing a warning.

  # Allow a specifc domain without issuing a warning.
  config.allow_url("https://checkout.stripe.com")
config.allow_url("https://checkout.stripe.com/v3/data/languages/en.json")


  # Timeout if requests take longer than 5 seconds
  config.timeout = 60

  # Don't raise errors when SSL certificates can't be validated
  config.ignore_ssl_errors

end

Capybara.javascript_driver = :webkit

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  # rspec-expectations config goes here. You can use an alternate
  # assertion/expectation library such as wrong or the stdlib/minitest
  # assertions if you prefer.
  config.use_transactional_fixtures = false
  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do |example|
    DatabaseCleaner.strategy= example.metadata[:js] ? :truncation : :transaction
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

  config.include SignInHelpers, type: :feature
  config.mock_with :rspec

  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  # rspec-mocks config goes here. You can use an alternate test double
  # library (such as bogus or mocha) by changing the `mock_with` option here.
  config.mock_with :rspec do |mocks|
    # Prevents you from mocking or stubbing a method that does not exist on
    # a real object. This is generally recommended, and will default to
    # `true` in RSpec 4.
    mocks.verify_partial_doubles = true
  end
end

1 个答案:

答案 0 :(得分:1)

正在等待第三方javascripts - 打开调试模式是找出悬挂capybara webkit的关键。谢谢Tom Walpole。