退出 .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.wrap(null).then(()=>{cy.log(array.length)})
关于javascript - 退出 .then 范围后数组值消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54799276/