mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-18 22:28:38 -05:00
1.9 KiB
1.9 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| as | true |
{% note info New to Cypress? %} Read about Using Aliases first. {% endnote %}
Assign an alias to a route or DOM element for use later. Reference the alias later within the cy.get or cy.wait command with the prefix @.
| Returns | the DOM element or route being aliased |
| Timeout | the alias will retry the chain of commands before the alias assignment for the duration of the defaultCommandTimeout |
cy.as( text )
Create an alias to be used later, passing the name of the alias as a parameter.
Usage
Alias a route, then wait for that route using @alias
cy
.route("PUT", /^\/users\/\d+/, "fixture:user").as("userPut")
.get("form").submit()
.wait("@userPut")
.its("url").should("contain", "users")
Command Log
Alias several routes
cy
.route(/company/, "fixture:company").as("companyGet")
.route(/roles/, "fixture:roles").as("rolesGet")
.route(/teams/, "fixture:teams").as("teamsGet")
.route(/users\/\d+/, "fixture:user").as("userGet")
.route("PUT", /^\/users\/\d+/, "fixture:user").as("userPut")
Aliases of routes display in the routes instrument panel:
Errors
cy.as() cannot be aliased as: 'str'. This word is reserved.
Some strings are not allowed as aliases since they are reserved words in Cypress. These words include: test, runnable, timeout, slow, skip, and inspect.