【问题标题】:Cypress - Check if video is paused or not赛普拉斯 - 检查视频是否暂停
【发布时间】:2020-11-01 17:09:19
【问题描述】:

我使用赛普拉斯。我的网址中有一个视频,我想检查视频是否处于暂停状态。

我有以下html代码:

<video id="mainVideo" controls="" loop="" autoplay="autoplay" playsinline="playsinline" preload="metadata" data-aos="fade-up">
    <source src="/video.mp4" type="video/mp4">Your navigator doesnt support videos.
</video>

我在调试测试中使用了以下代码:

cy.get('#mainVideo').debug();

我看到有以下属性“暂停”: Property Paused

但是当我尝试使用此代码检查作为属性是否为真时,它没有找到它:

cy.get('#mainVideo').should('have.attr', 'paused', true):

结果,超时: Result test

如何访问该“暂停”视频的“属性”?

更新: 我是这样做的:

cy.get('#mainVideo').should($video => { expect($video.get(0)).to.have.property('paused', true); });

【问题讨论】:

  • cy.get('#mainVideo').its('paused').should('eq', true) - 有关访问属性,请参阅 docs - its
  • 此:cy.get('#mainVideo').its('paused') 未定义且不正确:ibb.co/7WJj0th
  • cy.get('#mainVideo').should($video => { expect($video.get(0)).to.have.property('paused', true); } );为我工作,谢谢

标签: javascript unit-testing cypress


【解决方案1】:

访问底层 &lt;video&gt; 元素对我有用:

cy.get('video').then(([videoEl]) => {
  expect(videoEl.paused).to.equal(true);
});

它的简写版本(没有.then(() =&gt; {}):

cy.get('video').its('0.paused').should('equal', true);

因为cy.get()返回的是jQuery对象,你必须先访问它的0属性,然后才能访问任何内置的DOM属性。

【讨论】:

    猜你喜欢
    • 2021-10-30
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多