使用 webdriverio 浏览器对象如何检查视频是否正在播放

问题描述:

使用 webdriverio 浏览器对象获取视频对象.

Using webdriverio browser object i am getting the video object.

const videoPlayer = browser.$(selector);

我在 WebdriverIO.Element videoPlayer 中没有看到 currentTime 或 play 属性可用.如何使用 webdriverio api 测试嵌入的视频是否正在播放?

I am not seeing currentTime or playing attribute available in the WebdriverIO.Element videoPlayer . How to test if the embedded video is playing or not using webdriverio apis?

要操作 iframe 中的元素,您应该先切换到 iframe.

To manipulate elements that are in iframes you should switch to iframe first.

describe('video', () => {
  it('manipulate video', () => {
    browser.url('https://www.volvocars.com/ph/why-volvo/human-innovation/future-of-driving/safety/a-million-more')

    // get rid of cookies
    browser.execute(`document.cookie = "OptanonAlertBoxClosed=${new Date().toISOString()};";`)
    browser.refresh()

    // open video
    const video1 = $('.videoWrapperItemList')
    expect(video1).toBeClickable()
    video1.click()

    // Important! Switch to iframe to interact with video player
    const videoIframe = $('#IframeExteriorTwoyoutube.video-active')
    browser.switchToFrame(videoIframe)

    const player = $('#movie_player')

    // video is playing
    expect(player).toHaveElementClass('playing-mode')

    // pause video
    const playPauseButton = $('.ytp-play-button')
    expect(playPauseButton).toBeClickable()
    playPauseButton.click()

    // video is paused
    expect(player).toHaveElementClass('paused-mode')

    // check current time
    expect($('.ytp-time-current')).toHaveTextContaining('0:0')

    browser.pause(2000) // demo purposes
  })
})