title |
---|
submit |
Submit a form.
The subject must be a <form>
.
.submit()
.submit(options)
Correct Usage
cy.get('form').submit() // Submit a form
Incorrect Usage
cy.submit() // Errors, cannot be chained off 'cy'
cy.get('input').submit() // Errors, 'input' does not yield a form
options (Object)
Pass in an options object to change the default behavior of .submit()
.
Option | Default | Description |
---|---|---|
log |
true |
Displays the command in the Command log |
timeout |
defaultCommandTimeout |
Time to wait for .submit() to resolve before timing out |
.submit()
yields the same subject it was given from the previous command.<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 waiting for actionability.
.submit()
is a helpful command used as a 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 using .submit()
directly is more concise and conveys what you're trying to test.
If you want the other guarantees of waiting for an element to become actionable, you should use a different command like .click()
or .type()
.
If the form being submitted includes inputs with client-side validation and that validation fails, .submit()
will fail and list the validation failures.
.submit()
requires being chained off a command that yields DOM element(s)..submit()
requires the element to be a form
..submit()
will automatically wait for assertions you have chained to pass.submit()
can time out waiting for assertions you've added to pass.Submit a form
cy.intercept('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:
Version | Changes |
---|---|
< 0.3.3 | .submit() command added |