Skip to content

Latest commit

 

History

History
117 lines (73 loc) · 2.73 KB

File metadata and controls

117 lines (73 loc) · 2.73 KB
title
submit

Submit a form.

{% note warning %} The {% url subject introduction-to-cypress#Subject-Management %} must be a <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 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 %}.

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:

{% 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 %}

See also

  • {% url .click() click %}
  • {% url .type() type %}