【问题标题】:cypress Timed out retrying: cy.its() errored because the property: clientHeight does not exist on your subjectcypress 重试超时:cy.its() 出错,因为属性:clientHeight 在您的主题上不存在
【发布时间】:2020-04-16 09:59:53
【问题描述】:

以下内容:

cy.get( '@bar' ).
  its( 'clientHeight' ).
    should( 'eq', '300px' );

出现此 CypressError 失败:

Timed out retrying: cy.its() errored because the property: clientHeight does not exist on your subject.

cy.its() waited for the specified property clientHeight to exist, but it never did.

浏览器支持Element.clientHeight,因为我在代码中使用了它,并且同一别名上的其他断言正确通过。

提前感谢您的任何建议!

【问题讨论】:

    标签: cypress


    【解决方案1】:

    Cypress 命令cy.get() 生成一个引用 DOM 元素或 DOM 元素集合的 jquery 对象。您可以在以下位置找到对差异的很好解释:jQuery object and DOM element

    获取 clientHeight 属性的方法是使用 get(index) 方法从生成的 jquery 对象访问 DOM 元素:

    cy.get('@bar').should($bar => {
        expect($bar.get(0)).to.have.property('clientHeight', '300px');
    });
    

    【讨论】:

    • 谢谢!
    猜你喜欢
    • 1970-01-01
    • 2014-04-06
    • 1970-01-01
    • 2017-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 2015-09-11
    相关资源
    最近更新 更多