Testing Webrtc feature – fake camera with Cucumber/Capybara in Chrome

Testing Webrtc feature – fake camera with Cucumber/Capybara in Chrome

How do I allow my camera in a Cucumber scenario in Chrome?
I was looking for a way to test a WebRtc feature and trying to fake the camera in order to do so, it turns out that it was pretty easy when using Chrome as a web browser.

The configuration is as simple as:

### features/support/capybara.rb

Capybara.javascript_driver = :chrome

Capybara.register_driver :chrome_fullscreen_noinfobar do |app|
  args = ["--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream" ]
  
  Capybara::Selenium::Driver.new(app, { browser: :chrome, args: args })
end

or

Capybara.javascript_driver = :chrome
Capybara.register_driver :chrome do |app|
	Capybara::Selenium::Driver.new(app, browser: :chrome,
    desired_capabilities: {
      "chromeOptions" => {
        "args" => %w{ window-size=1280,800 use-fake-ui-for-media-stream use-fake-device-for-media-stream }
      }
    })
end

Now you are able to see something like this fake camera when you run your feature:
capybara fake camera in cucumber ruby

No Comments

Post A Comment