title |
---|
submit |
Submit a form.
{% note warning %}
The {% url subject introduction-to-cypress#Subject-Management %} must be a <form>
.
{% endnote %}
.submit()
.submit(options)
{% fa fa-check-circle green %} Correct Usage
cy.get('form').submit() // Submit a form
{% fa fa-exclamation-triangle red %} Incorrect Usage
cy.submit() // Errors, cannot be chained off 'cy'
cy.get('input').submit() // Errors, 'input' does not yield a form
{% fa fa-angle-right %} options (Object)
Pass in an options object to change the default behavior of .submit()
.
Option | Default | Description |
---|---|---|
log |
true |
{% usage_options log %} |
timeout |
{% url defaultCommandTimeout configuration#Timeouts %} |
{% usage_options timeout .submit %} |
{% yields same_subject .submit %}
<form id="contact">
<input type="text" name="message">
<button type="submit">Send</button>
</form>
cy.get('#contact').submit()
.submit()
is not implemented like other action commands, and does not follow the same rules of {% url 'waiting for actionability' interacting-with-elements %}.
.submit()
is just a helpful command which is a simple shortcut. Normally a user has to perform a different "action" to submit a form. It could be clicking a submit <button>
, or pressing enter
on a keyboard.
Oftentimes it's much simpler and conveys what you're trying to test by just using .submit()
directly.
If you want the other guarantees of waiting for an element to become actionable, you should use a different command like {% url .click()
click %} or {% url .type()
type %}.
{% requirements submitability .submit %}
{% assertions wait .submit %}
{% timeouts assertions .submit %}
Submit a form
cy.route('POST', '/users', 'fixture:user').as('userSuccess')
cy.get('form').submit()
The commands above will display in the Command Log as:
{% imgTag /img/api/submit/form-submit-shows-in-command-log-of-cypress.png "Command Log submit" %}
When clicking on submit
within the command log, the console outputs the following:
{% imgTag /img/api/submit/console-shows-what-form-was-submitted.png "Console Log submit" %}
{% history %}
{% url "< 0.3.3" changelog#0-3-3 %} | .submit()
command added
{% endhistory %}
- {% url
.click()
click %} - {% url
.type()
type %}