Elixir 如何在Wallaby中处理重定向?
我有一个这样编写的功能测试:Elixir 如何在Wallaby中处理重定向?,elixir,phoenix-framework,wallaby,Elixir,Phoenix Framework,Wallaby,我有一个这样编写的功能测试: confirmation_page = visit(session, "/confirm/#{id}") confirmation_page |> click(link("Decline")) confirmation_page |> assert_text("You have declined.") 但是,测试总是失败,因为在controller中,单击此页面时,我正在执行以
confirmation_page = visit(session, "/confirm/#{id}")
confirmation_page
|> click(link("Decline"))
confirmation_page
|> assert_text("You have declined.")
但是,测试总是失败,因为在controller中,单击此页面时,我正在执行以下操作:
conn
|> put_flash(:info, "You have declined.")
|> redirect(to: Routes.group_path(conn, :show, group.slug))
所以flash出现在重定向页面上,而不是原始页面。如何在新页面上等待重定向和断言
:time.sleep(1000)
assert\u has(会话,css(“元素ID或类”,文本:“您已拒绝”)
断言具有内置重试功能,因此它将等待此元素出现,因此我认为它将解决您的问题。它不起作用。奇怪的是,同样的测试在其他人的机器上成功了,使用了相同的
chrome
和chromedriver
版本。
1 retry = fn -> if Wallaby.current_url == "expected" do
2 ┆ ┆ ┆ assert_text(confirmation_page)
3 ┆ ┆ ┆ else
4 ┆ ┆ ┆ {:error, :url_not_refreshed}
5 ┆ ┆ ┆end
6 ┆ end
7
8 assert {:ok, response} = Wallaby.retry(retry, 5000) ## default timeout option after which it