Cypress · Browser testing end to end

What are aliases and how do you use them?

MediumaliasesaswaitUpdated Oct 2026
Quiz this track

Short answer

An alias names a subject with .as so it can be reused later with cy.get on the alias, or names an intercepted request so cy.wait can wait for that specific response.

Aliases solve two related problems: reusing a value or element across commands, and referring to a network request by name. A DOM alias is created with .as on any chain, including cy.get, cy.fixture or cy.request. A route alias is created on cy.intercept.

ts
cy.get("[data-cy=user-row]").first().as("firstUser");

cy.get("@firstUser").find("[data-cy=email]").click();

cy.get("@firstUser")
  .find("[data-cy=status]")
  .should("have.text", "Active");
The alias re-queries the original selector, so it does not hold a stale element.

Aliases for network

ts
cy.intercept("GET", "/api/cart").as("getCart");

cy.get("[data-cy=cart-link]").click();
cy.wait("@getCart");
cy.get("[data-cy=cart-count]").should("have.text", "2");
Waiting on the alias ties the assertion to the response that actually populates the cart.
  • DOM aliases are re-queried, which avoids stale element references
  • Network aliases must be created before the request is triggered
  • Waiting on an alias waits for the matching interception, not for a fixed duration
  • An alias can be reset between tests; do not rely on it across specs
  • Use .then with the yielded interception to assert on status or body
Do not name an alias and then use cy.wait with an arbitrary number. The value of the alias is that the wait has a precise condition.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why does a DOM alias avoid stale element references?
  2. 2When must an intercept alias be created?
  3. 3How do you assert on an intercepted response body?
  4. 4Do aliases persist between tests?

Say it in the interview

An alias gives a name to a subject or a network request. For DOM elements I use as and then cy.get with the alias, which re-queries rather than holding a stale node. For network calls I alias the intercept and wait for that alias, so the test continues exactly when the response arrives. I always create the intercept before the action that triggers the request.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Cypress mock interview and get scored feedback on depth, clarity and confidence.