我试图在Cypress中添加chai-colors插件,从如何安装插件“柴排序”#2441
克里斯·布里丁
import chaiSorted from "chai-sorted"
chai.use(chaiSorted)所以对于chai-colors
import chaiColors from 'chai-colors'
chai.use(chaiColors)
cy.visit(...)
cy.get(selector)
.should('be.colored', '#000000') 但这会产生“4000 is后重试超时: actual.equals不是函数”的错误。
发布于 2022-07-19 00:27:55
要在chai-colors内部使用.should(),需要传递颜色代码本身(而不是元素)
import chaiColors from 'chai-colors'
chai.use(chaiColors)
cy.visit(...)
cy.get(selector)
.then($el => $el.css('color')) // get color value
.should('be.colored', '#000000') ,但请注意,这会使失败
import chaiColors from 'chai-colors'
chai.use(chaiColors)
cy.visit(...)
cy.get(selector)
.then($el => $el.css('backgroundcolor')) // get color value
.should('be.colored', '#000000') 预期#000000与#000000的颜色相同
因为$el.css('backgroundcolor')返回的是rgba()而不是rgb()。
最好导入单色 ( chai-colors内部使用的)。
然后以任何你想要的方式使用转换器(加上文档更好)。
import color from 'onecolor'
cy.visit(...)
cy.get(selector)
.then($el => $el.css('backgroundcolor')) // get color value
.should(colorValue => {
expect(color(colorValue).hex()).to.eq('#000000')
})https://stackoverflow.com/questions/73029856
复制相似问题