Load a fake webcam video file

Hi mates,
I’m working with automated tests and I’m trying to stream a video/photo simulating the webcam streaming. Is it possible? I’m searching but I cant find any mention related with robot+browser.

Many thanks in advance

Hi Joāo,

Disclamer: I’ve never tried this
You probably will need to do this at an Operating System level, install something like OBS Studio and set up a virtual video input device that your web browser can pick up this video device.

OBS has some command line launch parameters so you could use the Run Process keyword from the Process library to launch it within your test case with the configuration you need.

As I mentioned earlier i’ve never tried this, but this is what I would probably try if I needed to solve this problem.

Hope that helps,

Dave.

2 Likes

@damies13 many thanks for your help, Sure I’ll search for that.

Hello,
I’m doing exactly the sam. For chrome it is like this:

    def set_chrome_fake_video_capture(self, path: str) -> list:
        """ GENERIC

        Sets default chrome options to emulate video input.
        Output is defined by `path` variable.

        This will return full chrome_options to set to initializer of browser

        Example:
        | ${chrome_options} | Set Chrome Fake Video Capture |
        """
        opt = []

        url = self.builtin.get_variable_value(self.LOGIN_PAGE)
        parsed_url = urllib.parse.urlparse(url)
        url = f"{parsed_url.scheme}://{parsed_url.netloc}"
        opt.append("--use-fake-ui-for-media-stream")
        opt.append("--disable-smooth-scrolling")
        opt.append("--use-fake-device-for-media-stream")
        opt.append("--disable-dev-shm-usage")
        opt.append("--disable-gpu")
        opt.append("--no-sandbox")
        opt.append("--ignore-certificate-errors")
        opt.append("--ignore-urlfetcher-cert-requests")
        opt.append(f"--unsafely-treat-insecure-origin-as-secure={url}")
        opt.append("--log-level=1")
        opt.append(f"--use-file-for-fake-video-capture={path}")
        return opt

(this is snippet from custom library and I’m using it inside the init keyword as:)

Wait Until Page Loads
    ${chrome_options}    Set Chrome Fake Video Capture    ${fake_camera_input_file}
    New Browser    headless=False    channel=chrome    args=${chrome_options}
    ${TOUT}    Evaluate    random.randint(10, 40)    random
    ${original_timeout}    Set Browser Timeout    1 min
    &{har}    Create Dictionary    path=${CURDIR}${/}${SUITE_NAME.replace(' ', '_')}.${TEST_NAME.replace(' ', '_')}.har    omitContent=${TRUE}
    ${default_context}    New Context    viewport={'width': 1920, 'height': 1080}
    ...                                  recordHar=${har}
    Set Test Variable    ${default_context}
    New Page    https://.......
    Set Browser Timeout    25 s

where ${fake_camera_input_file} is path to y4m file that serves as fake camera input. The same can be done with microphone.
If you are running tests locally, the path should be to that file. If you are running tests using selenium grid, than the file have to be on the browser node

Hope this is answer to your question

3 Likes