问题描述
退出.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
}
})
})
1楼
bkucera
1
2019-02-21 13:59:31
cy.log
是排队的命令;
它不像console.log
那样同步
尝试使用Cypress.log
代替:
Cypress.log({ name: 'debug', message: length })
2楼
bkucera
0
已采纳
2019-02-21 12:59:16
尝试以下方法:
cy.wrap(null).then(()=>{cy.log(array.length)})