PhoenixIntegration.Requests.click_link
You're seeing just the function
click_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, 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"
;
click_link
does not follow any redirects returned by the request. This allows
you to explicitly check that the redirect is correct. Use follow_redirect
to request
the location redirected to, or just use follow_link
to do it in one call.
If the link is not found in the body, click_link
raises an error.
Examples:
# click a link specified by path or uri
get( conn, thing_path(conn, :index) )
|> click_link( page_path(conn, :index) )
# click a link specified by html id with a non-get method
get( conn, thing_path(conn, :index) )
|> click_link( "#link-id", method: :delete )
# click a link containing the given text
get( conn, thing_path(conn, :index) )
|> click_link( "Settings" )
# test a redirect and continue
get( conn, thing_path(conn, :index) )
|> click_link( "something that redirects to new" )
|> assert_response( status: 302, to: think_path(conn, :new) )
|> follow_redirect()
|> assert_response( status: 200, path: think_path(conn, :new) )
Links that don't use the :get method
When Phoenix.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
click_link( conn, thing_path(conn, :delete), method: :delete )