Reputation: 455
The values on my array getting cleared after exit .then scope
in below code tableValues1.length gives me correct length until it is inside each loop the moment it exit .then scope -array length is zero.
Please can any one help me on this -Thanks
describe('Test setting basic Alert-Data update option', () => {
it('Test SetAlert-Data update', () => {
var tableValues1=[];
cy.contains('browse',{timeout: 60000}).should('be.visible',{ timeout: 60000 });
cy.contains('browse',{timeout: 60000}).click().then(()=>
{
cy.LoadProject();
})
//create analysis using smart search function and save to story
cy.mthode1(downAxis,acrossAxis,filterAxis);
cy.get('.gradContainer').find('table').as('Table');
cy.get('.gradContainer').find('table').each(($table, index, $list) => {
var headerLength=$table.find('thead').length;
var headers=$table.find('thead');
if ($table.find('thead').length>0)
{
cy.log('inside if');
cy.log($table.find('th').length);
cy.wrap($table).find('th').each(($header)=>{
cy.wrap($header).invoke('text').then(($elementvalue)=>{
//Add values to array
**tableValues1.push($elementvalue);**
**cy.log('length INSIDE .then '+tableValues1.length);//---GIVES ME correct count
})
cy.log('length AFTER .then '+tableValues1.length);//--GIVES me zero**
else
{
// add some other set of values
}
})
})
Upvotes: 1
Views: 605
Reputation: 18053
cy.log
is an enqueued command; it's not synchronous like a console.log
Try using Cypress.log
instead:
Cypress.log({ name: 'debug', message: length })
Upvotes: 1