1

Using webdriverio browser object i am getting the video object.

const videoPlayer = browser.$(selector);

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?

Siva
  • 1,229
  • 2
  • 9
  • 7
  • WebdriverIO can interact with everything available in the DOM. Most likely you are inspecting wrong element. There are tons of video player implementations, can you share address to yours? – Mike G. Dec 08 '20 at 11:57
  • https://www.volvocars.com/ph/why-volvo/human-innovation/future-of-driving/safety/a-million-more I am trying to test the videos over this above page.. sorry for the delayed response. – Siva Dec 28 '20 at 11:43

1 Answers1

1

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
  })
})
Mike G.
  • 3,860
  • 3
  • 17
  • 18