我有一個十六進制背景顏色。但是當我在 cypress 中測驗時,它給了我一個錯誤。在錯誤中,它顯示了一些其他顏色。但我提供正確的顏色。我的代碼如下:
it('color', () => {
cy.get(':nth-child(5) > .example-button-row > :nth-child(1)')
.should('exist')
.should('have.css', 'background-color')
.and('eq', '#0da2ff');
});
uj5u.com熱心網友回復:
eq與RGB等效的十六進制顏色一起使用。有兩種解決方法。
1. 使用 rgb 顏色與 eq。
2. 使用 be.colored 而不是 eq
下面給出了兩個示例:
通過使用rgb與eq:
it('color', () => {
cy.get(':nth-child(5) > .example-button-row > :nth-child(1)')
.should('exist')
.should('have.css', 'background-color')
.and('eq', 'rgb(13, 162, 255)');
});
通過使用be.colored:
it('color', () => {
cy.get(':nth-child(5) > .example-button-row > :nth-child(1)')
.should('exist')
.should('have.css', 'background-color')
.and('be.colored', '#0da2ff');
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/339575.html
