I have a feature test written like this:
confirmation_page = visit(session, "/confirm/#{id}")
confirmation_page
|> click(link("Decline"))
confirmation_page
|> assert_text("You have declined.")
However the test always fails, because in controller, on click of this page, I am doing this:
conn
|> put_flash(:info, "You have declined.")
|> redirect(to: Routes.group_path(conn, :show, group.slug))
So the flash is coming on the redirected page, and not the original page. How can I wait for the redirect and assert on the new page?
You can simply provide a sleep timer like
:time.sleep(1000)
before asserting over element.You can retry like waiting for page to be refreshed. You can use
Wallaby.retry/2
to retry until window is refreshed on specific url. We can get current url of window usingWallaby.current_url/1
. Code would look something like this.