当前位置: 代码迷 >> JavaScript >> 从.then范围退出后,数组值消失
  详细解决方案

从.then范围退出后,数组值消失

热度:56   发布时间:2023-06-05 09:25:24.0

退出.then范围后,我数组上的值将被清除

在下面的代码中tableValues1.length给我正确的长度,直到它退出时在每个循环内。然后范围-数组长度为零。

请有人可以帮我吗-谢谢

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

}

})
})

cy.log是排队的命令; 它不像console.log那样同步

尝试使用Cypress.log代替:

Cypress.log({ name: 'debug', message: length })

尝试以下方法:

cy.wrap(null).then(()=>{cy.log(array.length)})
  相关解决方案