【问题标题】:Hovering on the video doesn't play the video. Clicking on the video opens a new tab悬停在视频上不会播放视频。点击视频会打开一个新标签
【发布时间】:2021-04-30 20:19:36
【问题描述】:

当前行为 悬停在视频磁贴上不会按预期播放视频 点击视频会打开一个新标签(预计会在同一屏幕上打开视频播放器)

期望的行为 将鼠标悬停在视频上应该会播放视频 点击视频应该会打开视频播放器并播放视频

测试代码重现 将鼠标悬停在视频上应该会播放视频

const urls = [`https://cat-press.com/cat-movies/firework`]
  urls.forEach((url) => {
    it(`Should load the videos and autoplay one: ${url}`, () => {
      cy.visit(url)
      // Scroll to feed
      cy.get('.cy-grid').scrollIntoView()
      // Should hover over to the video at index 1
      cy.get(`.cy-thumbnail-link`).eq(1).trigger('mouseover')
     
    })
  })

点击视频会打开一个新标签页(预计会在同一屏幕上打开视频播放器)

const urls = [`https://cat-press.com/cat-movies/firework`]
  urls.forEach((url) => {
    it(`Should load the videos and autoplay one: ${url}`, () => {
      cy.visit(url)
      // Scroll to feed
      cy.get('.cy-grid').scrollIntoView()
      // Should hover over to the video at index 1
      cy.get(`.cy-thumbnail-link`).eq(1).trigger('click')
     
    })
  })

更新了可重现的示例

https://github.com/cypress-io/cypress-test-tiny/tree/opens-new-tab

【问题讨论】:

  • .cy-thumbnail-link 元素的 HTML(或可点击的小部件详细信息)是什么?
  • 如果悬停不起作用,请尝试赛普拉斯真实事件github.com/dmtrKovalenko/cypress-real-events
  • @A J 我也尝试过 realEvents。它没有用。
  • @traktor 附上小部件详细信息的电子邮件
  • @user2237529,我也尝试做同样的事情并修复您的代码,但我也无法通过实施人们发布的替代 hover() 的解决方法来修复它。但是通过添加相同的代码 4 次,看起来视频正在播放。我知道这不是一个好的模式 cy.get('.cy-thumbnail-link').eq(1).trigger('mouseover') cy.get('.cy-thumbnail-link').eq(1) .trigger('mouseover') cy.get('.cy-thumbnail-link').eq(1).trigger('mouseover') cy.get('.cy-thumbnail-link').eq(1) .trigger('鼠标悬停')

标签: javascript cypress ui-automation preact


【解决方案1】:

通过添加显式等待修复了悬停问题:

// Click on first thumbnail
      cy.get(`.cy-thumbnail-link`)
        .eq(1)
        .trigger("mouseover")
        //.trigger("mouseenter")
      cy.wait(3000)

【讨论】:

    猜你喜欢
    • 2019-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-04
    • 2018-10-01
    • 2020-07-22
    相关资源
    最近更新 更多