Jas*_*ker -2 typescript cypress
在我们的应用程序中,我们的屏幕具有多个标题标题(.tasktable__header.tasktable__header--title),我想验证这些标题。我的代码没有完成这项工作,因为它总是查看第一个可用的项目。
verifySubIncidentTitleMatch(incident: string): void {
cy.get(this.#subDossierTitle).each(ele => {
expect(ele.text()).to.equal(incident);
})
}
Run Code Online (Sandbox Code Playgroud)
但我想将标题标题存储在数组中,然后比较它们,但我不知道如何。
这是 HTML。表类位于 div 'top20' 中(第一个屏幕截图),并且 'tasktable__header--title 位于该类的标题内。
如果要将标题文本存储在数组中,请使用.then()回调进行转换并include在结果数组上使用。
verifySubIncidentTitleMatch(incident: string): void {
cy.get(this.#subDossierTitle)
.then(elements => Array.from(elements).map(element => element.innerText))
.should('include', incident)
}
Run Code Online (Sandbox Code Playgroud)
您还可以申请Array.some()
verifySubIncidentTitleMatch(incident: string): void {
cy.get(this.#subDossierTitle)
.then(elements => Array.from(elements).map(element => element.innerText))
.should(titles => {
expect(titles.some(title => title === incident)).to.eq(true)
})
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
603 次 |
| 最近记录: |