javascriptnode.jstestinge2e-testingnightwatch.js

How to allow a browser permission in NightWatch.js tests?


I'm using NightWatch.js to build e2e tests.

One of my tests requires to grant the Chrome browser's microphone permission. When I run this test, I get a permission notification from the Chrome browser and I have to manually allow it. I would like to automate this.

Is there any way I can use NightWatch.js script to click allow button on this notification or set the microphone permission allowed in nightwatch.conf.js directly?

microphone permission notification


Solution

  • I added --use-fake-device-for-media-stream and --use-fake-ui-for-media-stream to nightwatch.conf.js and it worked.

    This allowed the microphone permission in background during the test.

    this is the modified nightwatch.conf.js.

    module.exports = {
        src_folders: ["tests"], // replace with your test folder
        
        webdriver: {
          start_process: true,
          port: 4444,
          server_path: require('chromedriver').path,
          cli_args: []
        },
        
        test_settings: {
          default: {
            launch_url: 'https://nightwatchjs.org',
            desiredCapabilities : {
              browserName : 'chrome',
              'goog:chromeOptions' : {
                w3c: true,
                args: [
                  ...
                  '--use-fake-device-for-media-stream',
                  '--use-fake-ui-for-media-stream'
                  ...
                ]
              }
            }
          }
        }
      };