【发布时间】:2019-02-24 22:44:58
【问题描述】:
这是我的页面规范,该页面使用按钮触发一些 Javascript 以扩展截断的 description 文本。
it 'gets the description and inventory', js: true do
product = Product.create!(name: "Test Product", inventory: 0, description: "This is a test description with more text than should be there.")
customer = Customer.create(:name => Faker::Name.name)
invoice = Invoice.create
order = Order.create(customer: customer, invoice: invoice)
order.products << product
visit products_path
expect(page).to have_content(product.name, count: 1)
expect(page).not_to have_content product.description
click_button "More Info"
expect(page).to have_content product.description
expect(page).to have_content "Sold Out"
product.inventory = 1
product.save
visit products_path
click_button "More Info"
expect(page).to have_content "Available"
end
当我运行我的 Rails 服务器并在浏览器中访问该页面时,“更多信息”按钮肯定可以正常工作。但是,当我运行规范时,该按钮似乎不起作用:
1) Products products index gets the description and inventory
Failure/Error: expect(page).to have_content product.description
expected to find text "This is a test description with more text than should be there." in "Flatiron Widgets Store Products Test Product This is a test description ... More Info"
# ./spec/features/product_feature_spec.rb:47:in `block (3 levels) in <top (required)>'
现在,我知道完全有可能是某些问题导致按钮实际上无法正常工作,但我想知道问题是否实际上是我们正在检查尚未删除的 page在单击按钮之前。
有谁知道这是否确实是问题所在,如果是,有没有办法“重新抓取”页面?我不打算重新加载或刷新页面,因为这会将 JS 置于其初始按钮前状态。
【问题讨论】:
标签: javascript ruby-on-rails capybara