cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.02k stars 3.19k forks source link

Text invoke, alias and reuse in should #17763

Closed qtpsudhakar closed 3 years ago

qtpsudhakar commented 3 years ago

Current behavior

I am not using arrow function and below is my code

cy.get('#fwTotalServicesId').invoke('text').as('acServices'); cy.log(this.acServices) cy.get('.srvceNO:visible').should("have.length",Number(this.acServices));

It gives undefined in log. But When I debug it gives correct result in chrome debugger console on using this.acServices.

Why are we not able to alias and use it.

The code below is working.

cy.get("#fwTotalServicesId").then(($total)=>{ cy.log($total.text()); cy.get('.srvceNO:visible').should("have.length",Number($total.text())); });

I have to capture value and access it in multiple places for verification. The second increases lines of code. What's the correct way.

Desired behavior

invoke and alias should work as given.

Test code to reproduce

cy.get('#fwTotalServicesId').invoke('text').as('acServices'); cy.log(this.acServices) cy.get('.srvceNO:visible').should("have.length",Number(this.acServices));

apply the same by changing selectors

Cypress Version

7.x, 8.x

Other

No response

qtpsudhakar commented 3 years ago

I wrote custom command like below as of now. But above asked feature is useful if provided.

cy.get('.srvceNO:visible').compareLengthWithAlias("@acServices").should("be.true")