1

I'm trying to mock static video with cy.intercept

cy.intercept('/video.webm', { fixture: 'videos/video.webm' });

And that doesn't seems to work, it still return actual video instead of fixture one. I Also tried specify encoding binary and null like that

cy.intercept('/video.webm', { fixture: 'videos/video.webm,null' });
cy.intercept('/video.webm', { fixture: 'videos/video.webm,binary' });

But null gives me an error - The value "null" is invalid for option "encoding"

And with binary it seems that it returns an empty black video

So what am I doing wrong?

TesterDick
  • 3,830
  • 5
  • 18
Gerpea
  • 309
  • 1
  • 3
  • 13

2 Answers2

1

I can't fault it, this example works - plays the bunny vid which I have in cypress/fixtures.

Best guess is you have the wrong fixture path.

cy.visit('https://www.webmfiles.org/demo-files/');

cy.intercept('/elephants-dream.webm', { fixture: 'big-buck-bunny_trailer.webm,null' })
cy.get('a[href="https://dl8.webmfiles.org/elephants-dream.webm"]')
  .click()
TesterDick
  • 3,830
  • 5
  • 18
  • But I have a json intercept alongside cy.intercept('/adminData.json', { fixture: 'adminData.json' }); which works just fine. Tried wildcard - still not works( – Gerpea Sep 28 '22 at 21:53
  • Sorry, my mistake - I see examples with no wildcard in the docs. Will test and see if I can figure it out. – TesterDick Sep 28 '22 at 22:07
0

So I figured it out, do not know why but this works for me.

cy.intercept('/video.webm', (req) => {
    req.continue((res) => {
        res.send({ fixture:'videos/video.webm' });
    });
});

PS: Also this answer from @TesterDick actually works https://stackoverflow.com/a/73887996/12937539. But when I use video as source in the video tag and not in the link this not working. Maybe video tag with source the case

Gerpea
  • 309
  • 1
  • 3
  • 13
  • 2
    `req.continue()` sends the request to the server. Since you are unconditionally stubbing it's somewhat better to use `req.reply({ fixture:'videos/video.webm' })`. – Gerhard Funk Sep 29 '22 at 07:31