Cypress:动态测试:验证表中的行 [英] Cypress: Dynamic Tests: Validate rows in table
本文介绍了Cypress:动态测试:验证表中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目标是迭代表,并为每一行动态创建一个测试以验证其状态。表示例:
了解Cypress Examples: Dynamic tests,但提供了迭代基类型(string
,number
)的静态列表且未收集JQuery<HTMLElement>
的子级的地址的示例。
it()
的伪注入不起作用,我也不希望它会起作用,但这是我试图完成的,用特定的GUID测试每一行的状态:
it('TEST Iterate rows matching GUID', () => {
cy.fixture('esign').then($esignStore => {
expect($esignStore).to.have.property('requestUUID').to.be.a('string').not.empty;
cy.get('table[data-qa="act_ops_log_table"]').within(() => {
cy.log('Ops Logs table found');
cy.get('tbody[data-qa="act_ops_log_table_body"]').then(() => {
cy.get('tr');
cy.get('td');
cy.get('td:nth-child(1)').each(($tableCell, $index, $list) => {
const textEnvelope = $tableCell.text();
if (textEnvelope.includes($esignStore.requestUUID)) {
// pseudo-example of dynamically added test: start
// it(`TEST ${$index}`, () => {
cy.get('td:nth-child(3)')
.eq($index)
.then($field => {
const textStatus = $field.text();
expect(textStatus, 'succeeded');
});
// });
// pseudo-example of dynamically added test: end
}
});
});
});
});
});
方法值得赞赏。谢谢您
推荐答案
您不能动态创建测试。
在Cypress命令开始运行之前,Cypress会分析SPEC文件以找出存在哪些测试。
您最多只能添加额外的日志记录来标记每个测试行。
cy.get('tbody tr', {log:false}).each(($tr, index) => {
// Log beginning of row test
cy.then(() => Cypress.log({
displayName: 'Row test',
message: `TEST ${index}`,
}))
cy.wrap($tr, {log:false}).find('td:nth-child(1)', {log:false}).then($firstCol => {
const textEnvelope = $firstCol.text();
if (textEnvelope.includes(esignStore.requestUUID)) {
cy.wrap($firstCol, {log:false}).siblings({log:false}).eq(1, {log:false})
.should('have.text', 'succeed')
} else {
cy.log(`Row ${index} - not required requestUUID`)
}
})
})
或预筛选所需行,以便只测试匹配requestUUID
的行
cy.get('tbody tr', {log:false}).each(($tr, index) => {
.filter(`:has(td:nth-child(1):contains(${esignStore.requestUUID}))`, {log:false})
.each(($tr, index) => {
// Log beginning of row test
cy.then(() => Cypress.log({
displayName: 'Row test',
message: `TEST ${index}`,
}))
cy.wrap($tr, {log:false})
.find('td:nth-child(3)', {log:false})
.should('have.text', 'succeed')
})
这篇关于Cypress:动态测试:验证表中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文