{
  "doc": {
    "id": "api/commands/as",
    "title": "as | Cypress Documentation",
    "description": "Assign an alias for later use in Cypress. Reference the alias later within a `cy.get()` query or `cy.wait()` command with an `@` prefix.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/as.md",
    "version": "24a73f8a97175663aaffd3b016289fb2a523a4ea",
    "updated_at": "2026-05-14T20:17:33.301Z",
    "headings": [
      {
        "id": "api/commands/as#as",
        "text": "as",
        "level": 1
      },
      {
        "id": "api/commands/as#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/as#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/as#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/as#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/as#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/as#dom-element",
        "text": "DOM element",
        "level": 3
      },
      {
        "id": "api/commands/as#intercept",
        "text": "Intercept",
        "level": 3
      },
      {
        "id": "api/commands/as#fixture",
        "text": "Fixture",
        "level": 3
      },
      {
        "id": "api/commands/as#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/as#aliases-are-reset",
        "text": "Aliases are reset",
        "level": 3
      },
      {
        "id": "api/commands/as#reserved-words",
        "text": "Reserved words",
        "level": 3
      },
      {
        "id": "api/commands/as#alias-names-cannot-match-some-reserved-words",
        "text": "Alias names cannot match some reserved words.",
        "level": 4
      },
      {
        "id": "api/commands/as#as-is-asynchronous",
        "text": "as is asynchronous",
        "level": 3
      },
      {
        "id": "api/commands/as#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/as#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/as#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/as#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/as#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/as#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/as#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/as#syntax",
      "doc_id": "api/commands/as",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.as(aliasName).as(aliasName, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('.main-nav').find('li').first().as('firstNav') // Alias element as @firstNavcy.get('input.username').invoke('val').as('username', { type: 'static' }) // Alias that references the value at the time the alias was createdcy.intercept('PUT', '/users').as('putUser') // Alias route as @putUsercy.stub(api, 'onUnauth').as('unauth') // Alias stub as @unauthcy.spy(win, 'fetch').as('winFetch') // Alias spy as @winFetch\n```\n\n**Incorrect Usage**\n\n```\ncy.as('foo') // Errors, cannot be chained off 'cy'\n```\n\n### Arguments\n\n**aliasName _(String)_**\n\nThe name of the alias to be referenced later within a [`cy.get()`](/llm/markdown/api/commands/get.md) or [`cy.wait()`](/llm/markdown/api/commands/wait.md) command using an `@` prefix.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.as()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `type` | `query` | The type of alias to store, which impacts how the value is retrieved later in the test. Valid values are `query` and `static`. A `query` alias re-runs all queries leading up to the resulting value each time the alias is requested. A `static` alias is retrieved once when the alias is stored, and will never change. `type` has no effect when aliasing intercepts, spies, and stubs. |\n\n### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n*   `.as()` yields the same subject it was given.\n*   It is _safe_ to chain further commands after `.as()`.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 284
    },
    {
      "id": "api/commands/as#usage",
      "doc_id": "api/commands/as",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.get('.main-nav').find('li').first().as('firstNav') // Alias element as @firstNavcy.get('input.username').invoke('val').as('username', { type: 'static' }) // Alias that references the value at the time the alias was createdcy.intercept('PUT', '/users').as('putUser') // Alias route as @putUsercy.stub(api, 'onUnauth').as('unauth') // Alias stub as @unauthcy.spy(win, 'fetch').as('winFetch') // Alias spy as @winFetch\n```\n\n**Incorrect Usage**\n\n```\ncy.as('foo') // Errors, cannot be chained off 'cy'\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 79
    },
    {
      "id": "api/commands/as#arguments",
      "doc_id": "api/commands/as",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**aliasName _(String)_**\n\nThe name of the alias to be referenced later within a [`cy.get()`](/llm/markdown/api/commands/get.md) or [`cy.wait()`](/llm/markdown/api/commands/wait.md) command using an `@` prefix.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.as()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `type` | `query` | The type of alias to store, which impacts how the value is retrieved later in the test. Valid values are `query` and `static`. A `query` alias re-runs all queries leading up to the resulting value each time the alias is requested. A `static` alias is retrieved once when the alias is stored, and will never change. `type` has no effect when aliasing intercepts, spies, and stubs. |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 164
    },
    {
      "id": "api/commands/as#examples",
      "doc_id": "api/commands/as",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### DOM element\n\nAliasing a DOM element and then using [`cy.get()`](/llm/markdown/api/commands/get.md) to access the aliased element.\n\n```\nit('disables on click', () => {  cy.get('button[type=submit]').as('submitBtn')  cy.get('@submitBtn').click().should('be.disabled')})\n```\n\n### Intercept\n\nAliasing an intercepted route defined with [`cy.intercept()`](/llm/markdown/api/commands/intercept.md) and then using [`cy.wait()`](/llm/markdown/api/commands/wait.md) to wait for the aliased route.\n\n```\n// `PUT` requests on the `/users` endpoint will be stubbed with// the `user` fixture and be aliased as `editUser`cy.intercept('PUT', '/users', { fixture: 'user' }).as('editUser')// we'll assume submitting `form` triggers a matching requestcy.get('form').submit()// once a response comes back from the `editUser`// this `wait` will resolve with the subject containing `url`cy.wait('@editUser').its('url').should('contain', 'users')\n```\n\nMore examples of aliasing routes can be found [here](/llm/markdown/api/commands/intercept.md#Aliasing-an-intercepted-route).\n\n### Fixture\n\nAliasing [`cy.fixture()`](/llm/markdown/api/commands/fixture.md) data and then using `this` to access it via the alias.\n\n```\nbeforeEach(() => {  cy.fixture('users-admins.json').as('admins')})it('the users fixture is bound to this.admins', function () {  cy.log(`There are ${this.admins.length} administrators.`)})\n```\n\nNote the use of the standard function syntax. Using [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) to access aliases via `this` won't work because of [the lexical binding](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#No_separate_this) of `this`.\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 223
    },
    {
      "id": "api/commands/as#intercept",
      "doc_id": "api/commands/as",
      "heading": "Intercept",
      "heading_level": 3,
      "content_markdown": "### Intercept\n\nAliasing an intercepted route defined with [`cy.intercept()`](/llm/markdown/api/commands/intercept.md) and then using [`cy.wait()`](/llm/markdown/api/commands/wait.md) to wait for the aliased route.\n\n```\n// `PUT` requests on the `/users` endpoint will be stubbed with// the `user` fixture and be aliased as `editUser`cy.intercept('PUT', '/users', { fixture: 'user' }).as('editUser')// we'll assume submitting `form` triggers a matching requestcy.get('form').submit()// once a response comes back from the `editUser`// this `wait` will resolve with the subject containing `url`cy.wait('@editUser').its('url').should('contain', 'users')\n```\n\nMore examples of aliasing routes can be found [here](/llm/markdown/api/commands/intercept.md#Aliasing-an-intercepted-route).\n",
      "section": "api",
      "anchors": [
        "intercept"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 107
    },
    {
      "id": "api/commands/as#fixture",
      "doc_id": "api/commands/as",
      "heading": "Fixture",
      "heading_level": 3,
      "content_markdown": "### Fixture\n\nAliasing [`cy.fixture()`](/llm/markdown/api/commands/fixture.md) data and then using `this` to access it via the alias.\n\n```\nbeforeEach(() => {  cy.fixture('users-admins.json').as('admins')})it('the users fixture is bound to this.admins', function () {  cy.log(`There are ${this.admins.length} administrators.`)})\n```\n\nNote the use of the standard function syntax. Using [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) to access aliases via `this` won't work because of [the lexical binding](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#No_separate_this) of `this`.\n",
      "section": "api",
      "anchors": [
        "fixture"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 79
    },
    {
      "id": "api/commands/as#notes",
      "doc_id": "api/commands/as",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### Aliases are reset\n\n**Note:** all aliases are reset before each test. See the [aliases guide](/llm/markdown/app/core-concepts/variables-and-aliases.md) for details.\n\n### Reserved words\n\n#### Alias names cannot match some reserved words.\n\nSome strings are not allowed as alias names since they are reserved words in Cypress. These words include: `test`, `runnable`, `timeout`, `slow`, `skip`, and `inspect`.\n\n### `as` is asynchronous\n\nRemember that **Cypress commands are async**, including `.as()`.\n\nBecause of this you cannot _synchronously_ access anything you have aliased. You must use other asynchronous commands such as [`.then()`](/llm/markdown/api/commands/then.md) to access what you've aliased.\n\nHere are some further examples of using `.as()` that illustrate the asynchronous behavior.\n\n```\ndescribe('A fixture', () => {  describe('alias can be accessed', () => {    it('via get().', () => {      cy.fixture('admin-users.json').as('admins')      cy.get('@admins').then((users) => {        cy.log(`There are ${users.length} admins.`)      })    })    it('via then().', function () {      cy.fixture('admin-users.json').as('admins')      cy.visit('/').then(() => {        cy.log(`There are ${this.admins.length} admins.`)      })    })  })  describe('aliased in beforeEach()', () => {    beforeEach(() => {      cy.fixture('admin-users.json').as('admins')    })    it('is bound to this.', function () {      cy.log(`There are ${this.admins.length} admins.`)    })  })})\n```\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 233
    },
    {
      "id": "api/commands/as#reserved-words",
      "doc_id": "api/commands/as",
      "heading": "Reserved words",
      "heading_level": 3,
      "content_markdown": "### Reserved words\n\n#### Alias names cannot match some reserved words.\n\nSome strings are not allowed as alias names since they are reserved words in Cypress. These words include: `test`, `runnable`, `timeout`, `slow`, `skip`, and `inspect`.\n",
      "section": "api",
      "anchors": [
        "reserved-words"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 48
    },
    {
      "id": "api/commands/as#alias-names-cannot-match-some-reserved-words",
      "doc_id": "api/commands/as",
      "heading": "Alias names cannot match some reserved words.",
      "heading_level": 4,
      "content_markdown": "#### Alias names cannot match some reserved words.\n\nSome strings are not allowed as alias names since they are reserved words in Cypress. These words include: `test`, `runnable`, `timeout`, `slow`, `skip`, and `inspect`.\n",
      "section": "api",
      "anchors": [
        "alias-names-cannot-match-some-reserved-words"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 44
    },
    {
      "id": "api/commands/as#as-is-asynchronous",
      "doc_id": "api/commands/as",
      "heading": "as is asynchronous",
      "heading_level": 3,
      "content_markdown": "### `as` is asynchronous\n\nRemember that **Cypress commands are async**, including `.as()`.\n\nBecause of this you cannot _synchronously_ access anything you have aliased. You must use other asynchronous commands such as [`.then()`](/llm/markdown/api/commands/then.md) to access what you've aliased.\n\nHere are some further examples of using `.as()` that illustrate the asynchronous behavior.\n\n```\ndescribe('A fixture', () => {  describe('alias can be accessed', () => {    it('via get().', () => {      cy.fixture('admin-users.json').as('admins')      cy.get('@admins').then((users) => {        cy.log(`There are ${users.length} admins.`)      })    })    it('via then().', function () {      cy.fixture('admin-users.json').as('admins')      cy.visit('/').then(() => {        cy.log(`There are ${this.admins.length} admins.`)      })    })  })  describe('aliased in beforeEach()', () => {    beforeEach(() => {      cy.fixture('admin-users.json').as('admins')    })    it('is bound to this.', function () {      cy.log(`There are ${this.admins.length} admins.`)    })  })})\n```\n",
      "section": "api",
      "anchors": [
        "as-is-asynchronous"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 159
    },
    {
      "id": "api/commands/as#rules",
      "doc_id": "api/commands/as",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `.as()` requires being chained off a previous command.\n\n### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)\n\n*   `.as()` is a utility command.\n*   `.as()` will not run assertions. Assertions will pass through as if this command did not exist.\n\n### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `.as()` cannot time out.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 73
    },
    {
      "id": "api/commands/as#history",
      "doc_id": "api/commands/as",
      "heading": "History",
      "heading_level": 2,
      "content_markdown": "## History\n\n| Version | Changes |\n| --- | --- |\n| [12.3.0](/llm/markdown/app/references/changelog.md#12-3-0) | Added option `type` to opt into the pre-12.0.0 behavior. |\n| [12.0.0](/llm/markdown/app/references/changelog.md#12-0-0) | All aliases now re-run queries leading up to them by default. |\n",
      "section": "api",
      "anchors": [
        "history"
      ],
      "path": "/llm/json/chunked/api/commands/as.json",
      "token_estimate": 53
    }
  ]
}