Can Cypress record audio from tests to also play it in the produced video?

Viewed 23

As stated in the title, is it possible to record audio from a website under test using cypress. For example from an audio tag or a youtube video. Such that it is audible in the video recorded by cypress.

1 Answers

Yes, you can use this if you want to ensure audio is playing for the client....if you're using audio or video elements.

const expectPlayingAudio = () => {
  cy.get('audio,video').should((els)=>{
    let audible = false
    els.each((i, el)=>{
      console.log(el)
      console.log(el.duration, el.paused, el.muted)
      if (el.duration > 0 && !el.paused && !el.muted) {
        audible = true
      }

      // expect(el.duration > 0 && !el.paused && !el.muted).to.eq(false)
    })
    expect(audible).to.eq(true)
  })
}

describe('page', () => {
  it('works', () => {
    cy.visit('/')
    expectPlayingAudio()
  })
})
Related