Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
b63c00d
Express requires 'doctype html' instead of '\!\!\!' as the first line.
leutloff Jan 7, 2014
9b8d51c
Added Makefile for make test and moved mocha test cases to default lo…
leutloff Jan 8, 2014
1092705
Make the tests work with webdriver v0.7.13. Added TDD tests in additi…
leutloff Jan 11, 2014
8d45888
Added Travis file with locally running tests.
leutloff Jan 11, 2014
a1babb8
Makefile: Automatically launch app.js. The program is only started wh…
leutloff Jan 11, 2014
c64e249
Travis: npm seems not available, but is automatically invoked.
leutloff Jan 11, 2014
6be0f50
Travis: npm is only automatically invoked when install step is missing.
leutloff Jan 11, 2014
5d65697
Travis: start example web app in the background.
leutloff Jan 11, 2014
e87997f
Updated the example web app to use latest express version.
leutloff Jan 11, 2014
7ec1788
Travis: use saucelabs for the tests.
leutloff Jan 11, 2014
8fe6e70
Travis: add saucelab user and key.
leutloff Jan 11, 2014
3f385cb
Add test script to package.json so that npm test calls mocha to run t…
leutloff Jan 11, 2014
1c6cae9
On Travis connect to saucelabs for running the tests.
leutloff Jan 11, 2014
6b2c444
Change port to 4445 which is provided by sauce connect.
leutloff Jan 11, 2014
362fd8d
Makefile: Launch selenium server when needed, too.
leutloff Jan 11, 2014
00a32a2
Add log output of env variables. Launch first the simple_test and the…
leutloff Jan 11, 2014
6fd99dd
Corrected the way to access environment variables in javascript.
leutloff Jan 11, 2014
cb5385a
Added user name to desiredCapabilities as requested by sauce connect …
leutloff Jan 11, 2014
dcaebf6
Added more infos to desiredCapabilities.
leutloff Jan 11, 2014
2477333
Added more infos to desiredCapabilities.
leutloff Jan 11, 2014
36c1671
Corrected infos to desiredCapabilities.
leutloff Jan 11, 2014
eab3f6e
Increased time out in before.
leutloff Jan 11, 2014
593dd3d
Moved starting the app.js to the npm install step so that is started …
leutloff Jan 11, 2014
f0543df
Start selenium-server-standalone in before_install step.
leutloff Jan 12, 2014
23a1b22
Execute the tests locally, too.
leutloff Jan 12, 2014
dda86e8
Added some information to README.
leutloff Jan 12, 2014
b87c88f
Enable verbose logging in webdriverjs.
leutloff Jan 12, 2014
8b74c5b
Travis: Add the path to the chromedrvier when starting the selenium s…
leutloff Jan 18, 2014
f72790e
Travis/Saucelabs: Disable local test run. Try to execute the test on …
leutloff Jan 18, 2014
b09439f
Change condition to use SauceLabs options.
leutloff Jan 19, 2014
191d05a
Change condition to use SauceLabs options.
leutloff Jan 19, 2014
a476a24
Change condition to use SauceLabs options.
leutloff Jan 19, 2014
ceb908c
Change test app to port 80.
leutloff Jan 19, 2014
2b05071
Change test app to port 80.
leutloff Jan 19, 2014
a89ed85
Change test app to port 3000, again.
leutloff Jan 19, 2014
e513ccf
Added a test case accessing a page on the internet.
leutloff Jan 19, 2014
d8ace4b
Added build id and tunnel-identifier.
leutloff Jan 19, 2014
c507431
Corrected the tunnel-identifier.
leutloff Jan 19, 2014
4038ea9
Locate the whole test of internet test in a single function. Add Wind…
leutloff Jan 19, 2014
e2f2d17
Increased time outs.
leutloff Jan 19, 2014
160e2c4
Select a selenium version that is the same as the one used for local …
leutloff Jan 19, 2014
88f4bb9
Start selenium server again and add saucelabs to the devDependencies.
leutloff Jan 19, 2014
4815bb0
Copied example from webdriverjs.
leutloff Jan 19, 2014
c195624
Added test from webdriverjs using phantomjs.
leutloff Jan 19, 2014
25f1d8c
Added test from webdriverjs using phantomjs.
leutloff Jan 19, 2014
c7655d5
Added version numbers and to a new branch of webdriverjs.
leutloff Jan 24, 2014
079b081
Add badges for build status and dependencies.
leutloff Jan 24, 2014
ab52985
Changed dependency to webdriverjs to the released version, again. Min…
leutloff Jan 25, 2014
a406b19
Some cleanup: Change browser tests. Removed phantomjs example from we…
leutloff Jan 25, 2014
9572205
Windosw 8.1 seams not work. Add firefox on Win7 to the test matrix.
leutloff Jan 27, 2014
4ac6f34
Platforms must be using underscore instead of a blank.
leutloff Jan 27, 2014
fc93524
Replace underscores with spaces inside javascript, again.
leutloff Jan 27, 2014
bbec61f
Corrected name for ie in matrix of Travis for SauceLabs.
leutloff Jan 27, 2014
0c3b6f4
Increment version of mocha. Bump version.
leutloff Mar 17, 2014
dff2a38
Just update the version dependencies.
leutloff Mar 30, 2014
9e973d5
Update version numbers of tested browsers.
leutloff Mar 30, 2014
c9a1f09
Increase allowed start up time of browsers. Uses Selenium server from…
leutloff Mar 30, 2014
8d7feda
Update to chromedriver 2.9.
leutloff Mar 30, 2014
037625b
use a supported version of the selenium version for running on saucel…
leutloff Mar 30, 2014
dbb07e1
Updated references to 2.41 selenium server in Makefile, too.
leutloff Apr 18, 2014
64651f6
version 1.1.0: updated express to version 4.x including a rework main…
leutloff Apr 18, 2014
7b75100
Updated versions of express, static-serve and webdriverjs.
leutloff Apr 28, 2014
fc6707b
Updated the version dependencies.
leutloff May 12, 2014
46f5e53
Updated the browser versions to test.
leutloff May 12, 2014
80eb992
Try to workaround failing IE11.
leutloff May 12, 2014
de68033
Bumped version of mocha.
leutloff May 19, 2014
67aebf8
bumped version numbers.
leutloff May 29, 2014
2ac23f7
Weekly version bump.
leutloff Jun 2, 2014
6bf4cf6
Weekly version bump - overlooked a package.
leutloff Jun 2, 2014
414f14c
Updated all the javascript packages and used tools to latest versions.
leutloff Jun 3, 2015
1cd2f94
Fix chromedriver download path.
leutloff Jun 3, 2015
ce743a2
Remove deprecated body-parser call. Target dev fails, so try beta ins…
leutloff Jun 3, 2015
4cae70c
Updated chai version.
leutloff Jun 3, 2015
2a95d30
Fix deprecated warning for body-parser.
leutloff Jun 4, 2015
0222ae9
Try a slightly different URL to avoid different page title on dev cha…
leutloff Jun 4, 2015
fe602d1
Remove firefox dev from Matrix - fails to connect to internet page.
leutloff Jun 5, 2015
1cc0c96
Updated the browser/platform matrix.
Sep 2, 2015
ed6dce6
Updated the selenium server and chrome driver.
Sep 2, 2015
76a8d17
Adds some more time to wait for saucelabs connection comming up.
Sep 2, 2015
1492ef4
Saucelabs: be more specific with the used browser versions.
Sep 2, 2015
1cdb772
Updating the selenium version in the test files, too. Latest browser/…
Sep 2, 2015
69c6f13
Add pause to wait for edge to load the page.
Sep 2, 2015
363c376
Reduce time to wait for edge loading the page.
Sep 2, 2015
b44ab02
Restore working pause.
Sep 2, 2015
ec8f30a
Updated dependencies in package.json to latest versions.
leutloff Oct 18, 2015
cc1b8fb
Merge branch 'master' of github.com:leutloff/selenium-example
leutloff Oct 18, 2015
82d431b
Updated the versions of dependencies and tools. Updated from webdrive…
leutloff Oct 18, 2015
a11ce3b
Added local copies of the chrome driver to .gitignore.
leutloff Oct 18, 2015
5ce0026
Increase time out for the page test - windows systems are requiring m…
leutloff Oct 18, 2015
2c007a9
Updated the firefox and chrome versions.
leutloff Oct 18, 2015
ed5f7b6
Increase time out for the simple internet - windows systems are requi…
leutloff Oct 18, 2015
f21a052
Added some wait for on page navigation. This may made it work on MS E…
leutloff Oct 18, 2015
6f3a8c1
Disabled the MS Edge because page navigation is not working as exepec…
leutloff Oct 18, 2015
f231334
Updated the seleniumDriver version to 2.48.2 as suggested by Sauce La…
leutloff Oct 25, 2015
15a8afe
Try Edge on Win10, once more.
leutloff Oct 25, 2015
bfb02d0
The 'page test' still doesn't work with Edge on Win10. Disabled the p…
leutloff Oct 25, 2015
bfc3688
Updated used javascript modules in package.json. Update to use the se…
leutloff Feb 2, 2016
8088902
travis: removed installation of phantomjs.
leutloff Feb 2, 2016
30a7e12
Saucelabs: Edge still doesn't work as the other browsers.
leutloff Feb 2, 2016
3710201
Updated the used browsers and the used javascript libraries.
leutloff Feb 23, 2016
f19a28c
Try newer node versions
leutloff Mar 2, 2016
3fb211e
Add some more waiting time and increase time out to make more test ca…
leutloff Mar 2, 2016
a181f91
Set timeouts to 5 min to ensure that these are not the problems for t…
leutloff Mar 2, 2016
8b42000
Set the timeouts on another location.
leutloff Mar 2, 2016
d20157d
Updated webdriverio.
leutloff Mar 23, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.DS_STORE
node_modules
node_modules
*.jar
chromedriver
chromedriver_linux64.zip
70 changes: 70 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
language: node_js

node_js:
- "node"
- "4.1"
- "5.7"
# last working:
- "0.10"

before_install:
# download and start selenium server - thought that it is not necessary, but without the website is not available within SauceLabs.
# download selenium server - when updating the jar: adapt the SELENIUMVERSION in the test files, too.
# Latest version: http://www.seleniumhq.org/download/
- curl -O https://selenium-release.storage.googleapis.com/2.50/selenium-server-standalone-2.50.1.jar
# Download and install the chromedriver to be able to execute the browser tests locally
# Latest version: https://sites.google.com/a/chromium.org/chromedriver/downloads
- curl https://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip > chromedriver_linux64.zip && unzip chromedriver_linux64.zip && sudo cp chromedriver /usr/local/bin && sudo chmod +rx chromedriver /usr/local/bin/chromedriver
# start this before installation to let the server be up and ready without extra waiting time.
- java -jar selenium-server-standalone-2.50.1.jar -Dwebdriver.chrome.driver=./chromedriver &
#- sleep 15 works only on Win7/chrome44 and Win7/ie11
- sleep 15
- echo "$(date +%H:%M:%S.%N) - before_install end"


before_script:
#- sudo npm install - is automatically executed when install is missing
# node app.js is started in postinstall of npm install
# - node app.js &
# check that the web app is running:
- wget http://localhost:3000/authors || true
# show the beginning of the file - the whole file is not displayed within TRAVIS (because line is too long?)
- cat authors | cut -d'/' -f1

script:
- echo "$(date +%H:%M:%S.%N) - script begin"
- sleep 15
- which node && node -v && npm version || true
# automatically runs `npm test` - therefore the call to mocha is located in package.json
#- mocha --reporter spec
#- export TEST_RUN_LOCAL=true && npm test
#- echo "Run the same tests as above, but using the remote browser."
- export TEST_RUN_LOCAL=false && npm test

addons:
sauce_connect: true

env:
global:
- secure: "EvQvxbIQRYDF2NvRDlC8tLeoKabuhi9D+d9y89jsVniyAkMd6HXzU6N+/rsKWnLSYg4fDzadHvXUN+ge9BP1JwMFsH1OOCifBCQQLfnrZQ1phnQEhwl8LDQHVZbRv9Wsk474+NcGkGiDOrjUjbadR6YCrisPt3CHAB1XQw4zIzE="
- secure: "sAGCSM9rCbANjWeeLnF8i2y450c4EPGUuhlOeFCxnlisduDkiQ6sZgusOlL2NiPQwmHTCcVNn7reBcuUGg1NZJfRt4NMju9OtqzS/JLk2RW9+J3zUkDrx5tQhaivWlThakRAIpNeHpCBEL9tWk68pDZw+Bfc1e1Jh4H3ji91KtI="
# Use platform configurator https://docs.saucelabs.com/reference/platforms-configurator
# Get the names and versions from the node.js tab in the section "COPY CODE".
# Use underscore for spaces in platform and browser names - they are replaced inside js.
matrix:
- _BROWSER: "firefox"
_PLATFORM: "Linux"
_VERSION: "44.0"
- _BROWSER: "firefox"
_PLATFORM: "Windows_7"
_VERSION: "44.0"
- _BROWSER: "chrome"
_PLATFORM: "Windows_7"
_VERSION: "48.0"
- _BROWSER: "internet_explorer"
_PLATFORM: "Windows_7"
_VERSION: "11.0"
# navigation on the 'page test' does not work - no idea why 8-(
- _BROWSER: "microsoftedge"
_PLATFORM: "Windows_10"
_VERSION: "20.10240"
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

SELENIUMVERSION=2.50
SELENIUMJAR=selenium-server-standalone-$(SELENIUMVERSION).1.jar
SELENIUMPID=$(shell ps -ef | grep 'selenium-server-standalone-$(SELENIUMVERSION).1.jar$$' | cut -d ' ' -f 2-3)
APPPID=$(shell ps -ef | grep 'node app.js$$' | cut -d ' ' -f 2-3)

all: test

$(SELENIUMJAR):
@echo "Getting selenium server $(SELENIUMJAR) ..."
curl -O https://selenium-release.storage.googleapis.com/$(SELENIUMVERSION)/$(SELENIUMJAR)

launchselenium: $(SELENIUMJAR)
ifneq (,$(SELENIUMPID))
@echo "Selenium server $(SELENIUMJAR) is already running. Process id: $(SELENIUMPID)"
else
@echo "Starting selenium server $(SELENIUMJAR) ..."
java -jar $(SELENIUMJAR) &
sleep 5
endif

launchapp:
ifneq (,$(APPPID))
@echo "node app.js is already running. Process id: $(APPPID)"
else
@echo "Starting node app.js ..."
node app.js &
endif

test: launchselenium launchapp
npm test


.PHONY: all test launchapp launchselenium
Empty file removed README
Empty file.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Selenium example
================

[![Build Status](https://travis-ci.org/leutloff/selenium-example.png?branch=master)](https://travis-ci.org/leutloff/selenium-example)
[![Dependencies](https://gemnasium.com/leutloff/selenium-example.png)](https://gemnasium.com/leutloff/selenium-example)


This project provides two complete simple examples written in JavaScript ([node.js](http://nodejs.org/))
using the Web Application Test Framework [Selenium](http://docs.seleniumhq.org/projects/webdriver/).
A complete description is provided from the initial author [Nathan Oehlman](https://github.com/nathanoehlman) at
[http://unexpectedliteral.com/2012/05/09/automated-functional-testing-with-javascript-using-mocha-and-selenium-part-2/](http://unexpectedliteral.com/2012/05/09/automated-functional-testing-with-javascript-using-mocha-and-selenium-part-2/).

The used test runner is [Mocha](http://visionmedia.github.io/mocha/).
Two styles of result checking TDD and BDD are shown. Both styles are provided by the [Chai](http://chaijs.com/) Library.


Install the prerequisites
========================

For locally running tests:

- Check that node.js and npm are installed, e.g. execute `node --version` and `npm --version`.
If this is not the case install them, e.g.
sudo apt-get install nodejs -y
curl https://npmjs.org/install.sh > install-npm.sh && sudo sh install-npm.sh
- Install the chromedriver for your system, e.g. for Linux
curl https://chromedriver.storage.googleapis.com/2.21/chromedriver_linux64.zip > chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/local/bin
sudo chmod +rx /usr/local/bin/chromedriver
- Install Mocha globally:
sudo npm install -g mocha
- To install the other Javascript related parts just execute
sudo npm install
- Then exceute
make
or install and launch selenium server, e.g.
curl -O https://selenium-release.storage.googleapis.com/2.50/selenium-server-standalone-2.50.1.jar
java -jar selenium-server-standalone-2.50.1.jar &
and start the tests with npm
npm test


Executing the examples
======================

Just call `mocha`. Mocha will then execute all the scripts in the directory named test.


Troubleshooting
===============

1) The test 'simple internet' fails and there is this message shown:
Only local connections are allowed.

Ensure that the chromedriver is matching the selenium-server, e.g. try
upgrade both to the latest releases.
46 changes: 24 additions & 22 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,36 @@
*/

var express = require('express')
, routes = require('./routes');
, routes = require('./routes')
, http = require('http')
, path = require('path');
var bodyParser = require('body-parser');
var serveStatic = require('serve-static');

var app = module.exports = express.createServer();
var app = express();

// Configuration

app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
app.use(express.errorHandler());
});
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
//app.use(favicon(__dirname + '/public/favicon.ico')); - add static-favicon to dependencies, too
//app.use(express.logger('dev')); replaced by morgan
//deprecated: app.use(require('body-parser')());
app.use(bodyParser.json())
app.use(require('method-override')());

// Routes

app.get('/', routes.index);
app.get('/authors', routes.authors);
app.get('/books', routes.books);

app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
app.use(serveStatic(path.join(__dirname, 'public')));

// development only
if ('development' === app.get('env')) {
app.use(require('errorhandler')());
}

http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port %d in %s mode...", app.get('port'), app.get('env'));
});
26 changes: 19 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
{
"name": "selenium-example",
"version": "0.0.1",
"version": "1.3.4",
"license": "MIT",
"private": true,
"dependencies": {
"express": "2.5.8",
"jade": ">= 0.0.1"
"body-parser": "~1.15.0",
"errorhandler": "~1.4.3",
"express": "~4.13.4",
"jade": "~1.11.0",
"method-override": "~2.3.5",
"serve-static": "~1.10.2"
},
"devDependencies": {
"mocha": "*",
"chai": "*",
"webdriverjs": "*"
"chai": "~3.5.0",
"mocha": "~2.4.5",
"saucelabs": "~1.2.0",
"util": "~0.10.3",
"webdriverio": "~4.0.5"
},
"scripts": {
"postinstall" : "node app.js &",
"start" : "node app.js &",
"test": "mocha --reporter spec --timeout 300000 test/simple_internet.js test/simple_test.js test/page_test.js"
}
}
}
Loading