我用cypress创建了一些end-2-end。本地测试可以正常工作,但是当这些测试在CircleCI上运行时,它会显示来自赛普拉斯的错误
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')
})
我尝试在first()
之后添加get()
,但没有帮助。我在不同的设备上本地尝试过,并且没有问题。
对于CircleCi泊坞窗映像,我使用自己的映像,该映像基于circleci/php:7.3.2-apache
。这是链接https://github.com/wpbakery/ci-wordpress/blob/master/circleci/Dockerfile。
答案 0 :(得分:1)
通常,cy.should()
产生被链接的值。但是,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?