Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alias returns undefined when there is a customized get command for the alias and I visit the page again #23652

Closed
haipinggong opened this issue Sep 1, 2022 · 3 comments · Fixed by #23663
Labels
type: bug type: regression A bug that didn't appear until a specific Cy version release

Comments

@haipinggong
Copy link

haipinggong commented Sep 1, 2022

Current behavior

  1. Get an element by using a customized command called cy.get2 chained by a children command, then save it as an alias: 'container'.
  2. Visit the page again.
  3. Call cy.get('@container').

Cypress throws an error saying the cy.get2 returns undefined.

image

Desired behavior

In this situation, cy.get should still get the same element as I get in step 1.
The script worked on 10.4.0.

Test code to reproduce

https://github.com/haipinggong/cypress-test-tiny/tree/alias-bug

describe("page", () => {
  it("works", () => {
    cy.visit("https://example.cypress.io");
    cy.get("body").children(".container").as("container");
    cy.visit("https://example.cypress.io");

    cy.get("@container");
  });

  it("does not work", () => {
    // The test case works in Cypress 10.4.0
    // The test case does not work in Cypress 10.5.0+

    cy.visit("https://example.cypress.io");
    cy.get2("body").children(".container").as("container");
    cy.visit("https://example.cypress.io");

    cy.get("@container");
  });
});

support/command.js file:

Cypress.Commands.add("get2", (selector, ...options) => {
  return cy.get(selector, ...options);
});

Cypress Version

10.5.0+

Node version

16.15.0

Operating System

Windows 11

Debug Logs

No response

Other

No response

@emilyrohrbough
Copy link
Member

@haipinggong Thank you for the reproducible example! I tried it out and it does appear that this is a regression in 10.5.0.

@BlueWinds
Copy link
Contributor

That is a lovely short little test demonstrating the issue, was able to figure it out almost immediately. Opened a PR to fix it.

Was a regression introduced during some of my work related to #7306, that went out in 10.5.0.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 13, 2022

Released in 10.8.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v10.8.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Sep 13, 2022
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug type: regression A bug that didn't appear until a specific Cy version release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants