Reputation: 3723
I'm trying to test a page which when it initially comes up the UI is available for a split second, then some async call happens and the screen is blocked for a second. After the async call some options in a dropdown get populated and the UI is refreshed. I think Capybara is inputting some text in the fields in that split second the UI is available before the async call. After which, the fields are cleared or changed (some of my Capybara inputs seem to be missing). I'm trying to avoid a manual wait since I heard Capybara should be able to deal with kind of thing naturally. Is there any way to do it?
Upvotes: 0
Views: 56
Reputation: 49870
To have Capybara wait you need to tell it what to wait for - so if you want to wait until the async call is completed you need to determine what change the async call response makes to the page. If all it does is populate some options in a dropdown then you can do something like
if using RSpec
expect(page).to have_select('select_id_name_or_label_text', with_options: ['option populated by call', 'another option populated by call'])
if not using RSpec
page.assert_selector(:select, 'select_id_name_or_label_text', with_options: ['option populated by call', 'another option populated by call'])
Upvotes: 2