Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Docker:如何使用selenium服务器进行nightwatchJS测试?_Node.js_Selenium_Docker_Selenium Webdriver_Gitlab - Fatal编程技术网

Node.js Docker:如何使用selenium服务器进行nightwatchJS测试?

Node.js Docker:如何使用selenium服务器进行nightwatchJS测试?,node.js,selenium,docker,selenium-webdriver,gitlab,Node.js,Selenium,Docker,Selenium Webdriver,Gitlab,我不知道如何使用我的NodeJS应用程序运行selenium服务器,它的文件位于自定义e2e:latestdocker映像的/bundle文件夹中 我想我必须为e2e:latest图像将selenium服务器和webdriver chrome添加到Dockerfile中,不是吗 这就是我到目前为止所做的: 我已经用NodeJS和nightwatchJS创建了一个基于java:8-jre的docker映像: Dockerfile FROM java:8-jre ## Node.js setup

我不知道如何使用我的NodeJS应用程序运行selenium服务器,它的文件位于自定义
e2e:latest
docker映像的
/bundle
文件夹中

我想我必须为
e2e:latest
图像将selenium服务器和webdriver chrome添加到Dockerfile中,不是吗

这就是我到目前为止所做的:

我已经用NodeJS和nightwatchJS创建了一个基于java:8-jre的docker映像:

Dockerfile

FROM java:8-jre

## Node.js setup
RUN curl -sL https://deb.nodesource.com/setup_4.x | bash -
RUN apt-get install -y nodejs

## Nightwatch
RUN npm install -g nightwatch
然后将此图像用于测试:

gitlab ci.yml

build:
  stage: build
  tags:
    - deploy
  script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - meteor npm install --production
    - meteor build $PACKAGE_PATH --directory
    # Maybe something like...? - docker build -t $CI_REGISTRY_IMAGE:e2e .

nightwatch:
  image: e2e:latest
  stage: e2e
  tags:
    - e2e
  before_script:
    - cd ./bundle
  script:
    - nightwatch
配置如下所示:

nightwatch.conf.js

module.exports = {
    'src_folders'           : ['test/e2e'],
    'output_folder'         : 'reports',
    'custom_commands_path'  : '',
    'custom_assertions_path': '',
    'page_objects_path'     : '',
    'globals_path'          : '',
    'test_runner'           : {
        'type'   : 'mocha',
        'options': {
            'ui'      : 'bdd',
            'reporter': 'list'
        }
    },

    'selenium': {
        'start_process': false,
        'server_path'  : '',
        'log_path'     : '',
        'host'         : '127.0.0.1',
        'port'         : 4444,
        'cli_args'     : {
            'webdriver.chrome.driver': './bin/chromedriver'
        }
    },

    'test_settings': {
        'default': {
            'launch_url'   : 'http://localhost',
            'selenium_port': 4444,
            'selenium_host': 'localhost',
            'silent'       : true,
            'screenshots'  : {
                'enabled': true,
                'path'   : 'reports/error-screenshots'
            },
            'desiredCapabilities': {
                'browserName'      : 'chrome',
                'javascriptEnabled': true,
                'acceptSslCerts'   : true
            }
        },

        'chrome': {
            'desiredCapabilities': {
                'browserName'      : 'chrome',
                'javascriptEnabled': true,
                'acceptSslCerts'   : true
            }
        }
    }
}

不确定这是否适合Gitlab CI,但看看这个项目。这是一个小的(6MB)二进制文件,可以在单独的Docker容器中启动浏览器,或者直接启动Webdriver进程。因此,如果容器方法不适合您的需要,请尝试使用Node.js将硒酸盐+例如+Chrome包装到同一容器中使用Selenoid时无需安装Java。

什么不起作用?您从Gitlab CI中的作业中获得了什么样的输出?目前没有正在运行的selenium服务器。我不知道如何在这个地方设置case@Jawad现在我想用梦魇。据我所知,我不需要一个selenium服务器,就像nightwatch一样。你需要一个像selenium一样的web驱动程序,然后是一个web浏览器,而噩梦看起来更独立。但是我如何在Dockerfile和yml文件中实现这一点?我认为噩梦会更简单,对吗?我喜欢容器方法。但是如何使用selenium容器的节点应用程序映像?这就是我的问题。我的意思是,我已经有了一个docker映像,其中包含了我的节点应用程序(我们称之为
app:latest
),现在我有了一个Selenoid docker容器。selenoid docker映像/容器随后在localhost:4444上运行(如果我正确理解文档的话)。但是如何将节点应用程序连接到此设置?还是我必须复制这些文件?如果是,在哪里…?我建议使用任意Node.js基本容器+在那里添加硒酸二元+ChromeDriver二元+Chrome本身。不需要Java、Selenium服务器等。@user3142695只需使用应用程序容器作为基础并添加Selenoid即可。然后在测试中,只需转到localhost。这可能是一个愚蠢的问题,但我如何将selenoid添加到我现有的docker映像(其中包含节点应用程序文件)中?