jeudi 4 mars 2021

how to use value of var inside .then() outside its scope in Cypress

Hi I want to use a value of a var that inside .then() outside its scope

It tried

let numOfDropdownFields = 0;
cy.get('dropdown').find('button').its('length').as('len').then(($len) => 
cy.log('No. of buttons:' + $len);
numOfDropdownFields = $len;
cy.get('@len').should('eq',numOfDropdownFields);
cy.log(numOfDropdownFields);
});
cy.log(numOfDropdownFields);

The first log prints: No. of elements: 14

The second log: 14

And the third log: 0

How can i change the value that outside the scope to 14?

Aucun commentaire:

Enregistrer un commentaire