ajax - Why doesn't Capybara raise exception when block is passed to find() but raises one when block is passed to within -
we having troubles our ajax specs , within
/ find
.
i'd following:
it 'allows load more search results if there any', focus: true, js: true fill_in 'search_term', with: '*' click_button 'search projects' # sends post request within 'table.projects' page.should have_content '1 of 2' click_link 'load more' # sends ajax request end within 'table.projects' page.should have_content '2 of 2' page.should have_link('load more', visible: false) end end
sadly, doesn't work, because 2nd within
doesn't seem wait ajax call complete, while 1st 1 seems wait "normal" post request (non ajax).
using find
instead of 2nd within
seems solve problem:
it 'allows load more search results if there any', focus: true, js: true fill_in 'search_term', with: '*' click_button 'search projects' # sends post request within 'table.projects' page.should have_content '1 of 2' click_link 'load more' # sends ajax request end find 'table.projects' # find instead of within here! page.should have_content '2 of 2' page.should have_link('load more', visible: false) end end
is bad idea use within
when testing stuff involves ajax requests? , why should ever use within
instead of find
then, find
seems same within
and waits ajax?!
thanks lot opinions.
code inside block of find
not invoked find
doesn't support passing block it. exception isn't thrown find
method accepts *args
doesn't perform thorough enough parameter parsing throw exceptions if pass invalid parameters.
to make second example working can try update capybara 2.1 automatic waiting improved in capybara 2.0 , 2.1.
also should know capybara methods such have_content
wait capybara.default_wait_time
2 seconds default.
if want wait more can modify capybara.default_wait_time
or use using_wait_time
method:
using_wait_time 5 page.should have_content '1 of 2' end
Comments
Post a Comment