创建会话失败 Chrome无法启动:崩溃 CodeceptJs和Dockerfile不存在DevToolsActivePort文件

问题描述

我对来自Selenium / Java背景的Docker和CodeceptJ都是陌生的,并且正在尝试从Docker容器中运行我们的CodeceptJs测试。但是,我们收到此错误,不确定如何绕过它。

enter image description here

我尝试使用java -jar selenium.jar根据here在另一个窗口(不在我的项目文件夹下)下启动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'

}

非常感谢您。

解决方法

我们找到了在ChromeOptions文件中设置codecept.cong.js的位置,并且现在可以使用。

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',