'NightwatchJs is ignoring chrome options when trying to launch no sandbox and headless on docker

I am having an issue running nightwatch on a docker container using chrome, nightwatch seems to be completely ignoring the fact that i have told it to use --no-sandbox and --headless

My config for nightwatch.conf.js:

let localConfig = require('./nightwatch.local.conf');

    module.exports = {
        src_folders: ["tests"],
        screenshots: {
            enabled: true,
            path: "screenshots"
        },
        webdriver: {
            start_process: true,
            server_path: 'node_modules/.bin/chromedriver',
            port: 9195
        },
    
        test_settings: {
            twlocal: localConfig,
            twint:{
                launch_url: "https://int.ecample.co.uk",
                desiredCapabilities: {
                    browserName: "chrome",
                    acceptSslCerts: true,
                    acceptInsecureCerts: true
                }
            },
            twstaging:{
                launch_url: "https://staging.example.co.uk",
                desiredCapabilities: {
                    browserName: "chrome",
                    acceptSslCerts: true,
                    acceptInsecureCerts: true,
                    chromeOptions:{
                        args:['no-sandbox','headless','disable-gpu']
                    }
                }
            },
            twlive:{
                launch_url: "https://example.co.uk",
                desiredCapabilities: {
                    browserName: "chrome",
                    acceptSslCerts: true
                }
            }
        }
    };

The TWSTAGING config i have set the chromeOptions arguments but the command it's running on the container is:

/usr/bin/google-chrome --allow-pre-commit-input --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging=stderr --ignore-certificate-errors --log-level=0 --no-first-run --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.com.google.Chrome.Zkxwkv

Which is producing this error:

Running as root without --no-sandbox is not supported.

I'm not sure why it's ignoring the arguments? This is just running: nightwatch --env twstaging



Solution 1:[1]

Have you tried adding the goog prefix to chromeOptions, I've copied your whole config but the only changes are in twstaging. Please note the fun with quotations due to the colon:

let localConfig = require('./nightwatch.local.conf');

module.exports = {
    src_folders: ["tests"],
    screenshots: {
        enabled: true,
        path: "screenshots"
    },
    webdriver: {
        start_process: true,
        server_path: 'node_modules/.bin/chromedriver',
        port: 9195
    },

    test_settings: {
        twlocal: localConfig,
        twint:{
            launch_url: "https://int.ecample.co.uk",
            desiredCapabilities: {
                browserName: "chrome",
                acceptSslCerts: true,
                acceptInsecureCerts: true
            }
        },
        twstaging:{
            launch_url: "https://staging.example.co.uk",
            desiredCapabilities: {
                browserName: "chrome",
                acceptSslCerts: true,
                acceptInsecureCerts: true,
                "goog:chromeOptions":{
                    args:['no-sandbox','headless','disable-gpu']
                }
            }
        },
        twlive:{
            launch_url: "https://example.co.uk",
            desiredCapabilities: {
                browserName: "chrome",
                acceptSslCerts: true
            }
        }
    }
};

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shicky