【问题标题】:Cypress test fails for hexadecimal color in Angular赛普拉斯测试在 Angular 中的十六进制颜色失败
【发布时间】:2021-10-27 22:34:34
【问题描述】:

我有一个十六进制的背景颜色。但是当我在 cypress 中测试时,它给了我一个错误。并在错误中显示其他颜色。但我提供了正确的颜色。 我的代码如下:

it('color', () => {
  cy.get(':nth-child(5) > .example-button-row > :nth-child(1)')
    .should('exist')
    .should('have.css', 'background-color')
    .and('eq', '#0da2ff');
});

【问题讨论】:

    标签: angular cypress


    【解决方案1】:

    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');
    });
         
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 2019-10-29
      • 2023-02-14
      相关资源
      最近更新 更多