- go into more detail on trigger vs action commands - explain actionability further - better format notes + examples - consistent no arg / arg examples - es6 all the functions - remove duplicated intractability content - remove simulated events garbage - go into more detail on pseudo action commands - much better cy.contains usage
2.6 KiB
title, comments
| title | comments |
|---|---|
| submit | false |
Submit a form.
{% note warning %}
This element must be an <form>.
{% endnote %}
Syntax
.submit()
.submit(options)
Usage
{% 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
Arguments
{% 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 {% helper_icon yields %}
{% yields same_subject .submit %}
Example
No Args
Submit can only be called on a single form.
<form id="contact">
<input type="text" name="message">
<button type="submit">Send</button>
</form>
cy.get('#contact').submit()
Notes
Actionability
Submit is not an action command
.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 its must 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 %}.
Rules
Requirements {% helper_icon requirements %}
{% requirements submitability .submit %}
Assertions {% helper_icon assertions %}
{% assertions wait .submit %}
Timeouts {% helper_icon timeout %}
{% timeouts assertions .submit %}
Command Log
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:
When clicking on submit within the command log, the console outputs the following:
See also
- {% url
.click()click %} - {% url
.type()type %}

