我用柏树创建了一些 end-2-end。本地测试工作正常,但是当这些测试在 CircleCI 上运行时,它显示来自 cypress 的错误
CypressError: Timed out retrying: You attempted to make a chai-jQuery assertion on an object that is neither a DOM object or a jQuery object.
The chai-jQuery assertion you used was:
> css
The invalid subject you asserted on was:
> 250px
To use chai-jQuery assertions your subject must be valid.
This can sometimes happen if a previous assertion changed the subject.
这是导致此错误的代码。
cy.get('.vce-single-image')
.should('have.css', 'width')
.and('have.css', 'height')
同样的错误。
cy.window()
.then((win) => {
cy.get('.vce-row')
.should('have.css', 'width')
.and('have.css', 'height')
})
我尝试在 get()
之后添加 first()
但它没有帮助。我在不同的设备上本地尝试过,没有任何问题。
对于 CircleCi docker 镜像,我使用自己的镜像,它基于 circleci/php:7.3.2-apache
。这是链接 https://github.com/wpbakery/ci-wordpress/blob/master/circleci/Dockerfile .
最佳答案
通常,cy.should()
产生它被链接的值(value)。然而,some assertions, including have.css
, change the subject yielded by cy.should()
. (这里是相关的chai-jquery
documentation)
所以,这应该可行:
cy.get('.vce-single-image').should('have.css', 'width', '250px')
cy.get('.vce-single-image').should('have.css', 'height', '250px')
相关阅读:How do I know which assertions change the subject and which keep it the same?
关于javascript - "Invalid subject"尝试使用 Cypress 断言 CSS 属性时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56430289/