Closed qtpsudhakar closed 3 years ago
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.
invoke and alias should work as given.
apply the same by changing selectors
7.x, 8.x
No response
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")
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