Running nodeJS, selenium and webdriver.io applications in docker container

I am trying to run some webdriver.io tests with my node application, which is a docker image.

So what I have done so far:

1) Get the selenium server by running this on my ubuntu server:

$ docker run -p 4444:4444 selenium/standalone-chrome 

This gives me a running container 'ubuntu_selenium_1' ( $ docker ps )

2) Create a docker node application image by running the node application in the background and running the e2e.js test file

In my gitlab-ci.yml I do

 - docker build -t core:test -f Dockerfile.testing . - docker run --rm core:test 

It does not give me a way out. There is no expected header and error message.

So what am I doing wrong? There is a working selenium server, there is a node application that loads in the background and runs the test file e2e.js.

I am missing the connection nodeJS app, webdriver and selenium ...

Dockerfile.testing

 FROM core:latest # Copy the test files COPY docker-entrypoint.sh / COPY e2e.js / # Get npm packages AND install test framework - mocha and webdriver RUN (cd programs/server && npm install --silent) RUN npm install -g mocha --silent RUN npm install chai webdriverio --silent RUN chmod +x /docker-entrypoint.sh # Run application and then e2e test ENTRYPOINT ["/docker-entrypoint.sh"] 

docker-entrypoint.sh

 #!/bin/bash node main.js & node e2e.js 

Perhaps this script entry point is incorrect ??

e2e.js

 var webdriverio = require('webdriverio'), options = { desiredCapabilities: { browserName: 'firefox' } } webdriverio .remote(options) .init() .url('http://localhost') // Which port do I have to use?? .getTitle().then(function(title) { console.log('Title was: ' + title) }) .end() 
+5
source share
2 answers

I did what you need, but I separated the application from my container.

You can try it yourself with my example here: https://github.com/xbx/webdriverio-docker-example

Here are the changes:

First add catch() to your webdriverio instance:

 webdriverio .remote(options) .init() .url('http://app:3000') .getTitle().then(function(title) { console.log('Title was: ' + title) }) .catch(function(e){ console.log('Error!') console.log(e) }) .end() 

Secondly, use chrome as your browser name (it must be due to the use of selenium chrome):

 desiredCapabilities: { browserName: 'chrome' } 

Thirdly, correctly indicate your application:

 .url('http://app:3000') 

See how the containers are arranged:

 version: "3" services: selenium: image: selenium/standalone-chrome ports: - 4444:4444 links: - app app: build: . ports: - 3000:3000 testing: build: context: . dockerfile: Dockerfile.testing command: /wait-for-it.sh selenium:4444 -- /wait-for-it.sh app:3000 -- node /e2e.js links: - app - selenium volumes: - ./wait-for-it.sh:/wait-for-it.sh 

Launch: docker-compose up --build

 Attaching to question_app_1, question_selenium_1, question_testing_1 app_1 | Started app. selenium_1 | 12:19:45.516 INFO - Selenium build info: version: '3.4.0', revision: 'unknown' ... selenium_1 | 12:19:45.769 INFO - Selenium Server is up and running testing_1 | Starting testing. selenium_1 | 12:19:47.827 INFO - Executing: [get: http://app:3000]) app_1 | Hit! selenium_1 | 12:19:48.210 INFO - Done: [get: http://app:3000] selenium_1 | 12:19:48.220 INFO - Executing: [get title]) selenium_1 | 12:19:48.239 INFO - Done: [get title] testing_1 | Title was: Hi, this is the title 

Edit: simple change for docker version 1:

 testing: build:. dockerfile: Dockerfile.testing ...... ...... 
+8
source

webdriverio cannot find selenium

You call webdriverio as follows:

 var webdriverio = require('webdriverio'), options = { desiredCapabilities: { browserName: 'firefox' } } 

By default, it will try to use the selenium server on localhost:4444 . However, this will not respond, because each container has its own localhost interface. The selenium server is running in a different container.

You indicated in your question that your container name is selenium ubuntu_selenium_1 . So you can specify webdriverio. (Container names can be used in the same way as DNS host names.)

 options = { desiredCapabilities: { browserName: 'firefox' }, host: 'ubuntu_selenium_1', port: 4444 } 

If your selenium container name is something else, replace it as the host parameter.

+1
source

All Articles