当试图在Docker上没有发射沙箱和无头时,Nightwatchjs忽略了镀铬选项

发布于 2025-01-21 02:07:07 字数 2294 浏览 1 评论 0原文

我在使用 chrome 在 docker 容器上运行 nightwatch 时遇到问题,nightwatch 似乎完全忽略了我告诉它使用 --no-sandbox 和 --headless 的事实

我的 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
                }
            }
        }
    };

TWSTAGING 配置我已经设置了 chromeOptions 参数,但它在容器上运行的命令是:

/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

哪个产生了此错误:

不支持在没有 --no-sandbox 的情况下以 root 身份运行。

我不确定为什么它忽略这些论点?这只是正在运行:nightwatch --env twstaging

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

時窥 2025-01-28 02:07:07

您是否尝试过将 goog 前缀添加到 chromeOptions 中,我已经复制了您的整个配置,但唯一的更改是在 twstaging 中。请注意冒号引起的引号的乐趣:

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
            }
        }
    }
};

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
            }
        }
    }
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文