javascript - "Invalid subject"尝试使用 Cypress 断言 CSS 属性时

标签 javascript jquery cypress

我用柏树创建了一些 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/

相关文章:

javascript - 将变量的值从测试传递到 Cypress 中的下一个

javascript - 如何在 Cypress 中测试提交的数据

javascript - D3 线和路径 - 图形线不显示

javascript - Chrome 不返回哈希值

jquery - 移动选中的 jQuery 上的复选框

javascript - 现金面额计算器

Cypress Auth0 租户设置 - 什么是 "default audience"

Javascript 不包括 jQuery 插件?

javascript - 如何在 angular2 服务调用期间进行过滤

javascript - 将 src 注入(inject) HTML5 的音频标签