原答案:
let arrayOfColumnOne = [];
let arrayOfColumnTwo = [];
cy.get('#hometable > tbody > tr > td:nth-child(6)').each(($e, index, $list) => {
if (index == 0) {
time_prev = 0
}
time = Math.round(new Date($e.text()).getTime() / 1000)
assert.isBelow(time_prev, time, 'previous date is below actual')
time_prev = time
arrayOfColumnTwo.push(time)
})
//so I take the value status
cy.get('#hometable > tbody > tr > td:nth-child(5)').each(($e, index, $list) => {
const text = $e.text()
arrayOfColumnOne.push(text)
})
.then(() => {
for (let i = 1; i < arrayOfColumnOne; i++) {
if (!arrayOfColumnTwo[i]) {
throw new Error('Something is wrong with the array selectors')
}
if (arrayOfColumnOne[i].includes('new')) {
expect(arrayOfColumnOne[i).to.eq('\n new\n ')
assert.isBelow(arrayOfColumnTwo[i - 1], arrayOfColumntwo[i], 'previous date is below actual')
} else if (text.includes('processing')) {
expect(text).to.eq('\n processing\n ')
//the assertion you need here
} else {
//some other code
}
}
})
编辑建议使用moment 和cypress moment,因为js round 可能不稳定
let arrayOfColumnTwo = [];
cy.get('#hometable > tbody > tr > td:nth-child(6)').each(($e, index, $list) => {
cy.get($e)
.parent()
.find('td:nth-child(5)')
.then($statusElement =>{
if($statusElement.text().includes('new')) {
expect($e.text()).to.eq('\n new\n ')
assert.isBelow(arrayOfColumnTwo[i - 1], arrayOfColumnTwo[i], 'previous date is below actual')
} else if($statusElement.text().includes('processing')){
expect($e.text()).to.eq('\n processing\n ')
assert.isAbove(arrayOfColumnTwo[i - 1], arrayOfColumntwo[i], 'previous date is below actual')
}
})
time = Math.round(new Date($e.text()).getTime() / 1000)
arrayOfColumnTwo.push(time)
})
编辑 2:
let arrayOfColumnTwo = [];
cy.get('#hometable > tbody > tr > td:nth-child(6)').each(($e, index, $list) => {
time = Math.round(new Date($e.text()).getTime() / 1000)
arrayOfColumnTwo.push(time)
cy.get($e)
.parent()
.find('td:nth-child(5)')
.then($statusElement =>{
if($statusElement.text().includes('new')) {
expect($e.text()).to.eq('\n new\n ')
assert.isBelow(arrayOfColumnTwo[i - 1], arrayOfColumnTwo[i], 'previous date is below actual')
} else if($statusElement.text().includes('processing')){
expect($e.text()).to.eq('\n processing\n ')
assert.isAbove(arrayOfColumnTwo[i - 1], arrayOfColumntwo[i], 'previous date is below actual')
}
})
})