PhoenixIntegration.Requests.follow_link
follow_link
, go back to PhoenixIntegration.Requests module for more information.
Finds a link in conn.resp_body, requests it as if the user had clicked on it, follows any redirects, and returns the resulting conn.
Parameters
conn
should be a conn returned from a previous request that rendered some html. The functions are designed to pass the conn from one call into the next via pipes.identifier
indicates which link to find in the html. Valid values can be in the following forms:"/some/path"
specify the link's href starting with a"/"
character"http://www.example.com/some/uri"
, specify the href as full uri starting with either"http"
or"https"
"#element-id"
specify the html element id of the link you are looking for. Must start start with the"#"
character (same as css id specifier)."Some Text"
specify text contained within the link you are looking for.
opts
A map of additional options:method
- method to use when requesting the path. Defaults to"get"
;:max_redirects
- Maximum number of redirects to follow. Defaults to5
;
This is similar to click_link
, except that it follows returned redirects. This
is very useful during integration tests as you typically want to emulate what the
user is really doing. You will probably use follow_link
more than click_link
.
If the link is not found in the body, follow_link
raises an error.
Example:
# click through several pages that should point to each other
get( conn, thing_path(conn, :index) )
|> follow_link( "#settings" )
|> follow_link( "Cancel" )
|> assert_response( path: thing_path(conn, :index) )
Links that don't use the :get method
When Phoneix.Html renders a link, it usually generates an <a>
tag. However, if you
specify a method other than :get, then Phoenix generates html looks like a link, but
is really a form using the method. This is why you must specify the method used in opts
if you used anything other than the standard :get in your link.
# follow a non-get link
follow_link( conn, thing_path(conn, :delete), method: :delete )