赛普拉斯断言颜色

时间:2020-10-16 09:24:39

标签: wordpress testing cypress

我具有以下html结构:

   <path d="M16,1 C7.7146,1 1,7.65636364 1,15.8648485 C1,24.0760606 16,51 16,51 C16,51 31,24.0760606 31,15.8648485 C31,7.65636364 24.2815,1 16,1 L16,1 Z" fill="#0fb500"></path>

我应该声明填充内部的颜色是#0fb500。我试过像这样,但是不起作用:

cy.get('path').should('have.css', 'fill', '#0fb500')

给出以下错误: enter image description here

他只是说他找不到它

如果我放:

cy.get('path').eq(0).invoke('attr', 'fill').should('contain', '#0fb500')

给出以下错误: enter image description here

如果我放

cy.log(cy.get('path'))

获取:对象(5)

1 个答案:

答案 0 :(得分:2)

您可以尝试使用cypress中的invoke属性功能代替css来查找填充并检查其值吗?

cy.get('path').eq(4).should('have.attr', 'fill', '#0fb500')