Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: How to use selenium server to do nightwatchJS test?

I don't know how to run a selenium server with my NodeJS application, whose files are located in the ./bundle folder of the custom e2e:latest docker image.

I think I have to add the selenium server and webdriver chrome into the Dockerfile for the e2e:latest image, don't I?

This is what I have done so far:

I've created a java:8-jre based docker image with NodeJS and nightwatchJS:

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

This image is then used for the test:

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

The configuration looks like this:

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
            }
        }
    }
}
like image 582
user3142695 Avatar asked Apr 19 '17 22:04

user3142695


People also ask

What is Docker Selenium Grid?

Selenium Grid made the automation execution job much easier. Using Selenium Grid one can run multiple tests on multiple machines in parallel, which reduces execution time from days to hours. Docker helps a lot in setting up test labs using Grid in very easy and simple steps and helping to remove all complexities.

How do I create a docker file in selenium?

Deploy Selenium Grid by running Selenium Hub and then separate nodes for Chrome/Firefox combinations. These nodes would be connected to Selenium Grid. Create Docker image which would contain everything necessary for running tests (rvm, ruby) Run that image as a docker container and copy over content of our tests.


1 Answers

Not sure whether this is suitable for Gitlab CI but take a look at Selenoid project. This is a small (6 Mb) binary that launches browsers in separate Docker containers or by starting Webdriver process directly. So if container approach is not suitable for your needs try to pack Selenoid + e.g. Chromedriver + Chrome to the same container with Node.js. No need to install Java when using Selenoid.

like image 114
vania-pooh Avatar answered Sep 20 '22 05:09

vania-pooh