playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature]: Support dynamically mocking camera feed

Open BeeMargarida opened this issue 7 months ago • 0 comments

🚀 Feature Request

I have a use case in my company where we want to test a flow that involves scanning QRCodes. Right now the setup is very flaky and only for chromium:

  • We launch a chromium instance with launch arguments --use-fake-device-for-media-stream, --use-fake-ui-for-media-stream and --use-file-for-fake-video-capture. To this last argument we point to a file (per Chrome specifics, it needs to be y4m format).
  • During the tests, we need to change the QRCodes, so we copy the contents of the QRCode video to this file we set as fake video capture. We tried linking instead of copying, but it didn't work most of the times.

Problems: It works, but it's very flaky. I feel like every time we touch the tests something might break in this functionality. I'm not sure how chrome handles this under the hood, it might cache the file and not read it from disk every time.

Example

Something like this would be great

test('should show different messages when scanning different QR Codes', async ({ context, page }) => {
   await context.mockCamera('<path to file>')
   await page.getByText('...').toBeVisible()

   await context.mockCamera('<path to another file>')
   await page.getByText('...').toBeVisible()
})

Motivation

This might be a very specific edge case, but I think it would be a great addition to the playwright functionality. However, I am aware that this might not be possible due to browser limitations, but I just wanted to open the discussion and hear if anyone has more thoughts.

BeeMargarida avatar Jun 12 '25 16:06 BeeMargarida