I want to execute my automated tests, written in Nightwatch-Cucumber
over a 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.
Over GitLab CI I've realized it over a .gitlab-ci.yml
config file and it runs very good:
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 realize the same procedure with Jenkins CI. What is the easiest way to do it and ro run my automated tests in a Docker image which is called by Jenkins? Should I write a Dockerfile or not or or or?
Step 1: Start the Jenkins server. Step 2: Open the browser and navigate to the localhost and the port in which Jenkins is running. Step 3: Click New Item in the dashboard. Step 4: Enter the project name and select the project type as Maven project.
Docker Hub can automatically test changes to your source code repositories using containers. You can enable Autotest on any Docker Hub repository to run tests on each pull request to the source code repository to create a continuous integration testing service.
I'm currently running Selenium Test scripts written in PHP and running them through Jenkins using Docker Compose. You can do the same as well without the hassle of dealing with Xvfb yourself.
To run your Selenium tests using headless browsers inside a docker container and linking it to your application with docker-compose, you can simply use the pre-defined standalone server.
https://github.com/SeleniumHQ/docker-selenium
I'm currently using the Chrome Standalone image.
Here's what your docker-compose 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 running docker-compose, it will spin up your application, the selenium environment that will be interacting with your app, and the standalone server that will provide you with your headless browser. Because they are linked, inside your selenium code, you can make your test requests to the host via your-app:80 for example. Your headless browser will be chrome-server:4444/wd/hub which is the default address.
This can all be done inside of Jenkins using only one command in your Execute Shell inside of your Jenkins Job. docker-compose will also allow you to easily run the tests on your local machine as well, and the results should be identical.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With