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

using alias again failed #6064

Closed
Tomas-Tr opened this issue Dec 30, 2019 · 1 comment
Closed

using alias again failed #6064

Tomas-Tr opened this issue Dec 30, 2019 · 1 comment
Labels
type: duplicate This issue or pull request already exists

Comments

@Tomas-Tr
Copy link

Tomas-Tr commented Dec 30, 2019

Hi, I have wierd issue with using alias.
First use of the alias is working, second not.
on first use, I get the element via alias, type something, then blur.
after that on second use, I wanna get the element via alias again, but
alias definition (probably) is failing.

CypressError: cy.find() failed because it requires a DOM element.

The subject received was:

  > undefined

The previous command that ran was:

  > cy.get()
cy.get('[data-cy=partner_groups_table]').then($table => {
        const rowCount = $table.find('tbody').find('tr').length;
        //add row and assert row count
        cy.get('[data-cy=add_partner_group_button]')
          .should('be.enabled')
          .click();

        cy.get('[data-cy=partner_groups_table]')
          .find('tbody')
          //.eq(0)
          .find('tr')
          .should('have.length', rowCount + 1);

        assertInvalidCategoriesPage();

        cy.log('Insert data to newly added row START');
        cy.get('[data-cy=partner_groups_table]')
          .find('tbody')
          //.eq(0)
          .find('tr')
          .last()
          .as('row');
        //test required validator
        cy.get('@row')
          .find('[data-cy=partner_group_name]')
          .click()
          .blur();
        cy.get('@row')
          .find('[data-cy=partner_group_name_form_field]')
          .find('mat-error')
          .should('be.visible');
        assertInvalidCategoriesPage();

        //insert correct data into row
        cy.get('@row')
          .find('[data-cy=partner_group_name]')
          .type('cat' + GuidUtils.newGuid().substring(0, 4));

        cy.get('@row')
          .find('[data-cy=partner_group_working_hour_price]')
          .click();

        ERROR after the click command when try to use the row alias again

        cy.get('@row')
          .find('[data-cy=partner_group_name_form_field]')
          .find('mat-error')
          .should('not.be.visible');

        cy.log('Insert data to newly added row END');
      });

I susspect, that this code if failing and have no clue why:

 cy.get('[data-cy=partner_groups_table]')
          .find('tbody')
          //.eq(0)
          .find('tr')
          .last()
          .as('row');

If I use the whole selector instead of allias, it works:

cy.get('[data-cy=partner_groups_table]')
          .find('tbody')
          //.eq(0)
          .find('tr')
          .last()
          .find('[data-cy=partner_group_name_form_field]')
          .find('mat-error')
          .should('not.be.visible');
@jennifer-shehane
Copy link
Member

The DOM element that was originally found to represent the alias has likely been removed from the DOM. After the click action, maybe the row is rerendered causing it to not be found. We don't requery the DOM element of aliases and instead use the original reference.

I would suggest requerying the DOM element with cy.get() after the click.

Closing as duplicate of #2971

@jennifer-shehane jennifer-shehane added the type: duplicate This issue or pull request already exists label Dec 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants