From e4bb82309017176617514d65dd430338b9a6f3ee Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Tue, 18 Nov 2014 12:15:11 -0700 Subject: [PATCH] Add smoke tests for Hub/Chrome/Firefox images Use a container to run tests in a simple NodeJs project. The test environment loads http://google.com and verifies the page title in both Chrome and Firefox. Closes #8 --- .gitignore | 1 + Makefile | 8 ++++---- Test/.dockerignore | 1 + Test/Dockerfile | 4 ++++ Test/package.json | 15 +++++++++++++++ Test/smoke-chrome.js | 1 + Test/smoke-firefox.js | 1 + Test/smoke-test.js | 38 ++++++++++++++++++++++++++++++++++++++ test.sh | 24 ++++++++++++++++++++++++ 9 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 Test/.dockerignore create mode 100644 Test/Dockerfile create mode 100644 Test/package.json create mode 100644 Test/smoke-chrome.js create mode 100644 Test/smoke-firefox.js create mode 100644 Test/smoke-test.js create mode 100755 test.sh diff --git a/.gitignore b/.gitignore index a3a8675f18..6b36e80489 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ tmp/ *_image/ +node_modules/ diff --git a/Makefile b/Makefile index a68ddf3cd4..5a4ebd467a 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ else COPYARGS := -rT endif -all: hub chrome firefox full +all: hub chrome firefox test build: all clean @@ -48,8 +48,8 @@ release: tag_latest @echo "*** Don't forget to create a tag. git tag rel-$(VERSION) && git push origin rel-$(VERSION)" clean: - rm -rf chrome_image - rm -rf firefox_image - rm -rf full_image + +test: + ./test.sh .PHONY: all base hub nodebase chrome firefox full tag_latest release clean diff --git a/Test/.dockerignore b/Test/.dockerignore new file mode 100644 index 0000000000..3c3629e647 --- /dev/null +++ b/Test/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/Test/Dockerfile b/Test/Dockerfile new file mode 100644 index 0000000000..2957dab421 --- /dev/null +++ b/Test/Dockerfile @@ -0,0 +1,4 @@ +FROM node:0.10-onbuild +MAINTAINER Selenium + +# The remainder of this build will be completed by the upstream image's ONBUILD commands diff --git a/Test/package.json b/Test/package.json new file mode 100644 index 0000000000..954b1abaad --- /dev/null +++ b/Test/package.json @@ -0,0 +1,15 @@ +{ + "name": "docker-selenium-tests", + "version": "0.0.0", + "description": "Tests for docker selenium configuration", + "main": "index.js", + "scripts": { + "start": "node smoke-chrome.js && node smoke-firefox.js" + }, + "license": "Apache 2", + "dependencies": { + "chai": "^1.10.0", + "colors": "^1.0.3", + "wd": "^0.3.11" + } +} diff --git a/Test/smoke-chrome.js b/Test/smoke-chrome.js new file mode 100644 index 0000000000..4d7b930480 --- /dev/null +++ b/Test/smoke-chrome.js @@ -0,0 +1 @@ +require('./smoke-test')('chrome'); diff --git a/Test/smoke-firefox.js b/Test/smoke-firefox.js new file mode 100644 index 0000000000..610dd6a4b4 --- /dev/null +++ b/Test/smoke-firefox.js @@ -0,0 +1 @@ +require('./smoke-test')('firefox'); diff --git a/Test/smoke-test.js b/Test/smoke-test.js new file mode 100644 index 0000000000..38eac548aa --- /dev/null +++ b/Test/smoke-test.js @@ -0,0 +1,38 @@ +require('colors'); +var chai = require('chai'); +chai.should(); + +var wd = require('wd'); + +module.exports = function(browserName) { + var logPrefix = ('[' + browserName + '] ').grey; + var browser = wd.remote({ + hostname: process.env.HUB_PORT_4444_TCP_ADDR, + port: process.env.HUB_PORT_4444_TCP_PORT + }); + + // optional extra logging + browser.on('status', function(info) { + console.log(logPrefix + info.cyan); + }); + browser.on('command', function(eventType, command, response) { + console.log(logPrefix + ' > ' + eventType.cyan, command, (response || '').grey); + }); + browser.on('http', function(meth, path, data) { + console.log(logPrefix + ' > ' + meth.magenta, path, (data || '').grey); + }); + + browser.init({ + browserName: browserName + }, function() { + browser.get("http://google.com", function() { + browser.title(function(err, title) { + if (err) { + console.error(err); + } + title.should.include('Google'); + browser.quit(); + }); + }); + }); +}; diff --git a/test.sh b/test.sh new file mode 100755 index 0000000000..1f939b5989 --- /dev/null +++ b/test.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +echo Building test container image +docker build -t selenium/test:local ./Test + +echo Starting Selenium Container +HUB=$(docker run -d selenium/hub:2.44.0) +HUB_NAME=$(docker inspect -f '{{ .Name }}' $HUB | sed s:/::) +sleep 2 + +echo Hub Name $HUB_NAME + +NODE_CHROME=$(docker run -d --link $HUB_NAME:hub selenium/node-chrome:2.44.0) +NODE_FIREFOX=$(docker run -d --link $HUB_NAME:hub selenium/node-firefox:2.44.0) + +trap "echo Tearing down Selenium Chrome Node container; docker stop $NODE_CHROME; docker rm $NODE_CHROME; echo Tearing down Selenium Firefox Node container; docker stop $NODE_FIREFOX; docker rm $NODE_FIREFOX; echo Tearing down Selenium Hub container; docker stop $HUB; docker rm $HUB; echo Done" EXIT + +docker logs -f $HUB & +docker logs -f $NODE_CHROME & +docker logs -f $NODE_FIREFOX & +sleep 2 + +echo Running test container... +docker run --rm -it --link $HUB_NAME:hub selenium/test:local