【发布时间】:2020-07-23 16:10:18
【问题描述】:
我正在学习 cypress,我有这样一个测试用例:我在网站上有 12 个按钮,我想检查每个按钮是否都被禁用。所以我就这样做了:
按钮:<button id="add-product-5f188b5e68f9e" class="btn btn-sm" role="button" data-add-to-basket="" data-product-price="15.54" data-product-name="Okulary" disabled="">Dodaj</button>
这是我的代码:
it.only('T.C.1. - 添加按钮 - 如果所有按钮都被禁用,则在没有添加任何内容时添加按钮验证', () => {
cy.visit('https://buggy-testingcup.pgs-soft.com/task_1')
cy.get('.caption').find('[role="button"]').should('have.length', '12').then( listOfAdds => {
cy.wrap(listOfAdds)
.first()
.should('have.attr', 'disabled')
cy.wrap(listOfAdds)
.eq(1)
.should('have.attr', 'disabled')
cy.wrap(listOfAdds)
.eq(2)
.should('have.attr', 'disabled')
cy.wrap(listOfAdds)
.eq(3)
.should('have.attr', 'disabled')
cy.wrap(listOfAdds)
.eq(4)
.should('have.attr', 'disabled')
cy.wrap(listOfAdds)
.eq(5)
.should('have.attr', 'disabled')
cy.wrap(listOfAdds)
.eq(6)
.should('have.attr', 'disabled')
cy.wrap(listOfAdds)
.eq(7)
.should('have.attr', 'disabled')
cy.wrap(listOfAdds)
.eq(8)
.should('have.attr', 'disabled')
cy.wrap(listOfAdds)
.eq(9)
.should('have.attr', 'disabled')
cy.wrap(listOfAdds)
.eq(10)
.should('have.attr', 'disabled')
cy.wrap(listOfAdds)
.eq(11)
.should('have.attr', 'disabled')
})
})
我想知道是否可以通过使用某种迭代来做同样的事情。你有什么想法吗?
【问题讨论】:
标签: cypress