How to wait for next page being loaded with Capybara and Selenium?

Viewed 3834

Let's suppose you want to submit a form to create a post, wait for it to be created, fetch the post from database and check if the image from the post is being displayed on the next page:

visit url
fill_in the_form
click_on 'Create'
post = Post.first
img = page.find '.post .image'
assert_equal post.file.thumb.url, URI(img[:src]).path

But this way, post will be nil more often than not. Since when you fetch it from database, it might not have been created yet. How do I make sure next page is loaded?

2 Answers
Related