我一直在尝试寻找替代使用睡眠一段时间,似乎每一个建议的方法,以避免使用睡眠从来没有工作,我在我的绳索结束。水豚测试 - 替代睡眠
it 'finds the correct product when searching by job type', js: true do
fill_in('filterrific_for_work_type', with: 'Central')
# once again, sleep feels like the only thing that works
#sleep 1 # TODO: find a better way..
expect(find('#work_queue_items_filter_reset')).to have_content('Reset All Filters')
expect(page).to have_link('IP Central Report',
href: work_queue_item_path(@release.id))
end
我也有这个等待AJAX辅助:
module CapybaraHelpers
def wait_for_ajax
Timeout.timeout(Capybara.default_max_wait_time) do
loop until finished_all_ajax_requests?
end
end
def finished_all_ajax_requests?
page.evaluate_script('jQuery.active').zero?
end
end
而且在spec_helper.rb:
RSpec.configure do |config|
config.include CapybaraHelpers, type: :feature
end
这个测试休息,除非我补充睡眠1.我已经尝试了很多迭代,使用“内部”,“查找”,“有效内容”等。这真的让我发疯。
我不明白 - 我有Capybara.default_max_wait_time = 10。我尝试了你提出的那两个have_css选项,但它失败了。当我加入睡眠1时,测试通过! WTF? – user1200990
@ user1200990你在使用什么驱动程序?你究竟得到什么错误?你的页面如何工作?即 - 在填充字段时触发页面执行任何操作。 –
@ user1200990另外你在运行测试的ruby是什么? –