首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >尝试使用Cypress断言CSS属性时出现"Invalid subject“

尝试使用Cypress断言CSS属性时出现"Invalid subject“
EN

Stack Overflow用户
提问于 2019-06-03 23:20:59
回答 1查看 473关注 0票数 1

我用柏树做了一些end-2-end。本地测试运行良好,但是当这些测试在CircleCI上运行时,它会显示来自cypress的错误

代码语言:javascript
复制
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.

这就是导致这个错误的代码。

代码语言:javascript
复制
    cy.get('.vce-single-image')
      .should('have.css', 'width')
      .and('have.css', 'height')

这个也有同样的错误。

代码语言:javascript
复制
    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的own镜像。这里是链接https://github.com/wpbakery/ci-wordpress/blob/master/circleci/Dockerfile

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-04 02:36:42

通常,cy.should()会产生它所链接的值。然而,some assertions, including have.css, change the subject yielded by cy.should()。(这里是相关的chai-jquery documentation)

因此,这应该是可行的:

代码语言:javascript
复制
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?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56430289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档