【问题标题】:Rails - debugging selenium-webdriver 404 errorsRails - 调试 selenium-webdriver 404 错误
【发布时间】:2014-03-29 07:09:42
【问题描述】:

我正在使用 Rspec、Capybara 和 Selenium (WebDriver) 来测试我的 Rails 应用程序,这是一个简单的在线商店。这是失败的规范的简化版本:

describe 'Team Order' do

  let(:product) { Product.last }

  before do
    create :product_with_color_and_size
  end

  it 'goes to product page', js: true do
    visit add_team_order_path(product)
    expect(page).to have_content(product.name)
  end

end

具体来说,Selenium 驱动的 Firefox 窗口显示我的应用程序的 404 页面,导致检查产品名称失败。

当我从it 块内调用debugger 并查询Product.last 时,我可以在测试数据库中看到有问题的产品。所以我怀疑 Selenium 击中了我的应用程序的错误实例......或其他东西。

不确定这是否相关,但浏览器指向 http://127.0.0.1:49736/products/product-10/add-team-order(尽管端口在 rspec 运行之间发生变化)。

我的问题是,我能做些什么来验证它是否击中了正确的实例?如果不是,我可以采取哪些步骤来解决?

编辑:

spec_helper.rb 中的database_cleaner 配置:

RSpec.configure do |config|

  config.before :suite do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with :truncation
  end

  config.before :each do
    DatabaseCleaner.start
  end

  config.after :each do
    DatabaseCleaner.clean
  end

【问题讨论】:

    标签: ruby-on-rails-3.2 selenium-webdriver


    【解决方案1】:

    问题原来是 database_cleaner 与我的 js: true 规范发生冲突。一个很好的总结:

    问题总是一样的:测试被包装在数据库事务中,因此在实际测试进程之外运行的任何代码(例如,服务于 Selenium 驱动的浏览器请求的服务器进程)都看不到数据库夹具我已经很仔细地组装了。

    更多信息以及我的解决方案,请点击此处:http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-26
      • 2017-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-29
      • 2015-09-26
      • 2018-01-06
      相关资源
      最近更新 更多