Skip to content

Commit

Permalink
Add smoke tests for Hub/Chrome/Firefox images
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mtscout6 committed Nov 18, 2014
1 parent d93ff04 commit e4bb823
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tmp/
*_image/
node_modules/
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ else
COPYARGS := -rT
endif

all: hub chrome firefox full
all: hub chrome firefox test

build: all clean

Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions Test/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 4 additions & 0 deletions Test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM node:0.10-onbuild
MAINTAINER Selenium <[email protected]>

# The remainder of this build will be completed by the upstream image's ONBUILD commands
15 changes: 15 additions & 0 deletions Test/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 1 addition & 0 deletions Test/smoke-chrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./smoke-test')('chrome');
1 change: 1 addition & 0 deletions Test/smoke-firefox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./smoke-test')('firefox');
38 changes: 38 additions & 0 deletions Test/smoke-test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
};
24 changes: 24 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e4bb823

Please sign in to comment.