本文介绍了使用 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
  })
})

这篇关于使用 webdriverio 浏览器对象如何检查视频是否正在播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 23:53