Files
cypress/docs/source/api/commands/as.md
T
2017-05-19 12:01:36 -04:00

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:

screen shot 2015-11-29 at 2 25 47 pm

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.

Related