Angular 中的十六进制颜色的 Cypress 测试失败
Cypress test fails for hexadecimal color in Angular
我有一个十六进制的背景颜色。但是当我在柏树上测试时,它给了我一个错误。并在错误中显示其他颜色。但我提供了正确的颜色。
我的代码如下:
it('color', () => {
cy.get(':nth-child(5) > .example-button-row > :nth-child(1)')
.should('exist')
.should('have.css', 'background-color')
.and('eq', '#0da2ff');
});
eq 与 rgb 等同于 hexdecimal color。有两种解决方法。
1.使用 eq.
的 rgb 颜色
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');
});
我有一个十六进制的背景颜色。但是当我在柏树上测试时,它给了我一个错误。并在错误中显示其他颜色。但我提供了正确的颜色。 我的代码如下:
it('color', () => {
cy.get(':nth-child(5) > .example-button-row > :nth-child(1)')
.should('exist')
.should('have.css', 'background-color')
.and('eq', '#0da2ff');
});
eq 与 rgb 等同于 hexdecimal color。有两种解决方法。
1.使用 eq.
的 rgb 颜色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');
});