PhoenixIntegration.Requests.click_button
click_button
, go back to PhoenixIntegration.Requests module for more information.
Finds a button in conn.resp_body and acts as if the user had clicked on it, and returns the resulting conn.
This is very similar to click_link
except that it looks for button tags
as rendered by PhoenixHtml.
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_button
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_button
raises an error.
Examples:
# click a link specified by path or uri
get( conn, thing_path(conn, :index) )
|> click_button( page_path(conn, :index) )
# click a link specified by html id with a non-get method
get( conn, thing_path(conn, :index) )
|> click_button( "#button_id", method: :delete )
# click a link containing the given text
get( conn, thing_path(conn, :index) )
|> click_button( "Settings" )
# test a redirect and continue
get( conn, thing_path(conn, :index) )
|> click_button( "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) )
Returns the transformed conn after submitting the request.
Button request methods that don't use the :get method
Unlike trying to click anchor tags, Phoenix always puts the method in button tags as an attribute.
This means that if you want to match agains tags with a non-get method you can, but you don't really need to.