Nightwatch can be configured to run on remote Selenium grids or cloud providers such as BrowserStack and Sauce Labs.

Running on BrowserStack

If you are installing Nightwatch using the CLI utility and you select to run on BrowserStack remote machine, it will auto-generate the BrowserStack settings block in the nightwatch.conf.js under the test_settings property.

If you are trying to run Nightwatch on BrowserStack for an existing project, you will have to add a browserstack block in the nightwatch.conf.js file as a child property to test_settings.

nightwatch.conf.js
module.exports = {
    ...,
    test_settings: {
        ...,
        browserstack: {
            selenium: {
                host: 'hub.browserstack.com',
                port: 443
            },
            // More info on configuring capabilities can be found on:
            // https://www.browserstack.com/automate/capabilities?tag=selenium-4
            desiredCapabilities: {
                'bstack:options': {
                    userName: '${BROWSERSTACK_USERNAME}',
                    accessKey: '${BROWSERSTACK_ACCESS_KEY}'
                }
            },
            
disable_error_log: true, webdriver: { timeout_options: { timeout: 15000, retry_attempts: 3 }, keep_alive: true, start_process: false } },
'browserstack.local': { extends: 'browserstack', desiredCapabilities: { 'browserstack.local': true } },
'browserstack.firefox': { extends: 'browserstack', desiredCapabilities: { browserName: 'firefox' } },
'browserstack.local_firefox': { extends: 'browserstack.local', desiredCapabilities: { browserName: 'firefox' } }, ... } }

Once the BrowerStack block is present in the Nightwatch configuration file, replace the BrowserStack username and access key with your credentials and you are ready to run your tests on the BrowserStack infrastructure.

Running on LambdaTest

If you are trying to run Nightwatch on LambdaTest for an existing project, you will have to add a lambdatest block in the nightwatch.conf.js file as a child property to test_settings.

nightwatch.conf.js
module.exports = {
    ...,
    test_settings: {
        ...,
        lambdatest: {
            selenium: {
                host: 'hub.lambdatest.com',
                port: 443
            },
            'username': '${LAMBDATEST_USERNAME}',
            'access_key': '${LAMBDATEST_ACCESS_KEY}',
        },
        // More info on configuring capabilities can be found on:
        // https://www.lambdatest.com/capabilities-generator/
        'lambdatest.chrome': {
            extends: 'lambdatest',
            desiredCapabilities: {
                browserName: 'chrome',
                'LT:Options': {
                    'platformName': 'Windows 10',
                    'browserVersion': '108.0',
                    'project': 'Project',
                }
            }
        },
        
'lambdatest.firefox': { extends: 'lambdatest', desiredCapabilities: { browserName: 'firefox', 'LT:Options': { 'platformName': 'Windows 10', 'browserVersion': '108.0', 'project': 'Untitled', } } }, ... } }

Once you have added LambdaTest configurations in the nightwatch.conf.js replace the LambdaTest username and access_key with your credentials and you are ready to run your tests on the LambdaTest Cloud grid.

You can also configure and add your desired capabilities with the help of automation capabilty generator.

Running on Sauce Labs

If you select Sauce Labs as the cloud provider while setting up Nightwatch via the CLI utility, the test settings will be automatically added.

If you are trying to run Nightwatch on Sauce Labs for an existing project, you will have to add the following block in the nightwatch.conf.js file as shown below.

nightwatch.conf.js
module.exports = {
    ...,
    test_settings: {
        ...,
        saucelabs: {
            selenium: {
                host: 'ondemand.saucelabs.com',
                port: 443
            },
            // More info on configuring capabilities can be found on:
            // https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options
            desiredCapabilities: {
                'sauce:options': {
                username: '${SAUCE_USERNAME}',
                accessKey: '${SAUCE_ACCESS_KEY}',
                screenResolution: '1280x1024'
                // https://docs.saucelabs.com/dev/cli/sauce-connect-proxy/#--region
                // region: 'us-west-1'
                // https://docs.saucelabs.com/dev/test-configuration-options/#tunnelidentifier
                // parentTunnel: '',
                // tunnelIdentifier: '',
                },
                javascriptEnabled: true,
                acceptSslCerts: true,
                // https://docs.saucelabs.com/dev/test-configuration-options/#timezone
                timeZone: 'London'
            },
            disable_error_log: false,
            webdriver: {
                start_process: false
            }
        },
        
'saucelabs.firefox': { extends: 'saucelabs', desiredCapabilities: { browserName: 'firefox', browserVersion: 'latest', platformName: 'Windows 10' } }, ... } }

Once the Sauce Labs block is present in the Nightwatch configuration file, replace the Sauce Labs username and access key with your credentials.

Running on remote Selenium server

If you are installing Nightwatch using the create-nightwatch utility and you select to run against a remote selenium server or other cloud providers, the remote host settings will be automatically added to test_settings with place holder values.

If you are trying to set this up for an existing project, you will have to add the following block in the nightwatch.conf.js file under the test_settings property as shown below.

nightwatch.conf.js
module.exports = {
    ...,
    test_settings : {
        ...,
        remote: {
            // Info on all the available options with "selenium":
            // /guide/configuration/settings.html#selenium-server-settings
            selenium: {
                start_process: false,
                server_path: '',
                host: '<remote-hostname>',
                port: 4444
            },
            
username: '${REMOTE_USERNAME}', access_key: '${REMOTE_ACCESS_KEY}',
webdriver: { keep_alive: true, start_process: false } },
'remote.firefox': { extends: 'remote', desiredCapabilities: { browserName: 'firefox', 'moz:firefoxOptions': { args: [ // '-headless', // '-verbose' ] } } }, ... } }

Once the configuration block is added, replace the remote host, port & credentials with yours and get started!

For additional help you can jump on to our Discord Server.