【问题标题】:Failed to create session. Chrome failed to start: crashed. DevToolsActivePort file doesn't exist for CodeceptJs and Dockerfile创建会话失败。 Chrome 无法启动:崩溃。 CodeceptJs 和 Dockerfile 不存在 DevToolsActivePort 文件
【发布时间】:2021-02-11 17:33:45
【问题描述】:

我是来自 Selenium/Java 背景的 Docker 和 CodeceptJs 的超级新手,我正在尝试从 docker 容器中运行我们的 CodeceptJs 测试。但是,我们收到此错误,不知道如何绕过它。

我尝试按照here 使用java -jar selenium.jar 在另一个窗口(它不在我的项目文件夹下)下启动 Selenium 驱动程序,但同样的问题仍然存在。

如果我们在 CodeceptJs 之外使用原始 Selenium,这里的大多数答案都是关于为 ChromeDriver 实例设置一些选项,但 ChromeDriver 配置似乎在 CodeceptJs 框架内从我身上抽象出来,所以我想我现在有点卡住了。

这是我们完整的 Dockerfile 和 bash 脚本

FROM docker.br.hmheng.io/base-ubuntu:java_1.8.0_74-b02

ENV DEBIAN_FRONTEND noninteractive

RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - \
    && sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' \
    && apt-get clean \
    && apt-get update \
    && apt-get install curl -y \
    dpkg

RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -

RUN apt-get install -y \
    libgconf-2-4 \
    libexif12 \
    supervisor \
    netcat-traditional \
    google-chrome-stable \
    git \
    chromium-chromedriver \
    nodejs \
    xorg \
    xvfb \
    dbus-x11 \
    xfonts-100dpi \
    xfonts-75dpi \
    xfonts-scalable \
    xfonts-cyrillic \
    dos2unix \
    --no-install-recommends

ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
ENV HOST selenium

RUN export JAVA_HOME=/usr/lib/jvm/java-8-oracle \
    && export HOST=selenium

COPY ./update-catalog-admin/tests/e2e/scripts/start.sh start.sh

RUN chmod 777 start.sh \
    && dos2unix start.sh

#!/bin/bash

echo "[INFO] Starting X server"
Xvfb :0 -screen 0 1600x1200x24 2>&1 >/dev/null &
export DISPLAY=:0

cd /project

node -v
npm -v
ls -lsa
npm install
npm test

通过这个命令运行:

docker run -u 500:500 -v /etc/passwd:/etc/passwd:ro -v $(pwd)/update-catalog-admin/tests/e2e:/project:rw  -v /dev/shm:/dev/shm --shm-size=4g update-catalog-e2e-container sh start.sh

有了这个 codecept.conf.js

exports.config = {
output: './output',
helpers: {
    WebDriver: {
        url: 'https://api.int.br.internal',
        browser: 'chrome'
    },
    AssertWrapper: {
        require: 'codeceptjs-assert',
    },
},
include: {
    I: './steps_file.js',
    createNotificationPage: "./pages/create_notifications.page.js",
},
mocha: {},
bootstrap: null,
teardown: null,
hooks: [],
gherkin: {
    features: './features/*.feature',
    steps: ['./step_definitions/steps.js']
},
plugins: {
    wdio: {
        enabled: true,
        services: ['selenium-standalone']
        // additional config for service can be passed here
    },
    screenshotOnFail: {
        enabled: true
    },
    pauseOnFail: {},
    retryFailedStep: {
        enabled: true
    },
},
tests: './*_test.js',
name: 'codeceptjs_webdriver'

}

非常感谢。

【问题讨论】:

    标签: docker selenium selenium-chromedriver dockerfile codeceptjs


    【解决方案1】:

    我们找到了在codecept.cong.js 文件中设置ChromeOptions 的位置,它现在可以工作了。

    output: './output',
    helpers: {
        WebDriver: {
            url: 'https://api.int.br.internal',
            browser: 'chrome',
            smartWait: 10000,
            waitForTimeout: 10000,
            timeouts: {
                script: 10000,
                pageLoad: 60000,
                implicit: 10000,
            },
            desiredCapabilities: {
                chromeOptions: {
                    args: [
                        '--no-sandbox',
                        '--disable-gpu',
                        '--disable-dev-shm-usage',
                        '--ignore-certificate-errors',
                    ],
                    excludeSwitches: ['enable-automation'],
                },
            },
            restart: false,
            windowSize: '1600x1200',
        },
        AssertWrapper: {
            require: 'codeceptjs-assert',
        },
    },
    

    【讨论】:

      猜你喜欢
      • 2023-02-14
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 1970-01-01
      • 2020-06-23
      • 1970-01-01
      • 2018-06-11
      • 2019-11-06
      相关资源
      最近更新 更多