我想将数组中存在的数据与在 cypress 中使用 .each 从类中检索到的数据进行比较?
使用下面的代码,我尝试使用下面的代码迭代 FileType 数组。
const Filetype = ['Access', 'Excel', 'Text/CSV','PDF','JSON','dsdsd'];
const te = cy.wrap($bodyFind).find('.data-sourcename').should('have.length',6).each(($li) => { cy.log($li.text()); });
te.each(($text)=> {
cy.log("Te" + $text);
//prints ['Access','Excel','Text/CSV','PDF','JSON','XML'];
});
// Converted FileType Array to Cypress object using cy.wrap command.
const cywrap = cy.wrap(Filetype);
te.each((e1)=>cywrap.each((e2)=> {
if(e1 == e2) {
expect(e1).equals(e2);
}
}));
Run Code Online (Sandbox Code Playgroud)
但是e1和e2的值是一样的。期望应该失败,“dsdsd”等于“XML”,而它通过“dsdsd”等于“dsdsd”
bku*_*era 10
你可以map
在这里使用。
const filetypes = ['Access', 'Excel', 'Text/CSV','PDF','JSON','dsdsd'];
cy.get('.data-sourcename').should(($els) => {
// map jquery elements to array of their innerText
const elsText = $els.toArray().map(el => el.innerText)
expect(elsText).to.deep.eq(filetypes)
})
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9623 次 |
最近记录: |