Running nodeJS app, selenium and webdriver.io tests in docker container
docker, node.js, selenium, selenium-webdriver
Solution
I did what you need but I've separated the application to its own container.
You can try it yourself with my example here: https://github.com/xbx/webdriverio-docker-example
Here the changes:
First, add a `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()
Second, use `chrome` as browserName (must be, due to you're using selenium-chromium):
desiredCapabilities: {
browserName: 'chrome'
}
Third, point correctly to your app:
.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
Running it: `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-compose version 1:
testing:
build:.
dockerfile: Dockerfile.testing
......
......
Problem
I am trying to do some webdriver.io tests with my node application, which is a docker image. So what I did so far is: 1) Get selenium server by running this on my ubuntu server: ``` $ docker run -p 4444:4444 selenium/standalone-chrome ``` This gives me the running container 'ubuntu_selenium_1' (`$ docker ps`) 2) Build node application docker image, running node application in background and running e2e.js test file In my gitlab-ci.yml I am doing ``` - docker build -t core:test -f Dockerfile.testing . - docker run --rm core:test ``` That doesn't give me any output. No expected title and no error message. So what am I doing wrong? There is a running selenium server, there is the node application which is loaded in background and the e2e.js test file is started. I'm missing the connection of 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 ``` Maybe this entrypoint script is wrong?? 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() ```