The easiest way to run Selenium tests in a Docker container over Jenkins CI

I want to run my automated tests written in Nightwatch-Cucumber on Jenkins CI in a Docker container. I have a Docker image that I want to use for it.

This is what I want to do in more detail.

  • Start tests on Jenkins CI
  • On the same computer, the Docker image is loaded and the corresponding Docker container is launched. This container is based on the Unix operating system. In addition, some configuration will be done in the Docker container.
  • Tests will be executed (from local or remote) in silent mode via xvfb, and the report will be saved on the Jenkins machine.

Over GitLab CI I figured this out in the .gitlab-ci.yml configuration file, and it works very well:

 image: "my-docker-image" stages: - "chrome-tests" before_script: - "apt-get update" - "apt-get install -y wget bzip2" - "npm install" cache: paths: - node_modules/ run-tests-on-chrome: stage: "chrome-tests" script: - "whereis xvfb-run" - "xvfb-run --server-args='-screen 0 1600x1200x24' npm run test-chrome" 

But I want to implement the same procedure with Jenkins CI. What is the easiest way to do this, and ro runs my automated tests in a Docker image called Jenkins? Should I write a Docker file or not or or?

+5
source share
2 answers

Currently, I am running Selenium Test scripts written in PHP and running them through Jenkins using Docker Compose. You can do the same as without problems with Xvfb itself.

To run Selenium tests using browsers without a browser inside the docker container and bind it to your application using docker, you can simply use a predefined stand-alone server.

https://github.com/SeleniumHQ/docker-selenium

I am currently using a standalone Chrome image.

Here is what your docker essay should look like:

 version: '3' services: your-app: build: context: . dockerfile: Dockerfile your_selenium_application: build: context: . dockerfile: Dockerfile.selenium.test depends_on: - chrome-server - your-app chrome-server: image: selenium/standalone-chrome:3.4.0-einsteinium 

When docker-compose starts, it will deploy your application, a selenium environment that will interact with your application, and a stand-alone server that will provide you with your dumb browser. Since they are interconnected, inside the selenium code, you can make your test requests to the host through your application: for example, 80. Your browser without a browser will be chrome-server: 4444 / wd / hub, which is the default address.

All this can be done inside Jenkins using only one command on your command line inside your Jenkins Job. docker-compose will also allow you to easily run tests on your local machine, and the results should be identical.

0
source

Browse supported Selenium Docker images , in particular node fragrances. This is a good place to start, whether you decide to use containers as is or roll your own.

0
source

Source: https://habr.com/ru/post/1269672/


All Articles