Skip to content

Commit

Permalink
E2e tests: launch Selenium and node server and kill them after finish…
Browse files Browse the repository at this point in the history
…ing the tests, using a test database
  • Loading branch information
djuretic committed Jan 1, 2014
1 parent 69c4977 commit 431622c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ node_js:
services:
- mongodb
before_script:
- 'npm install -g bower grunt-cli'
- 'bower install'
- 'npm install -g grunt-cli'
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- cp config.json.example config.json
- ./node_modules/protractor/bin/webdriver-manager update
- ./node_modules/protractor/bin/webdriver-manager start > /dev/null &
- grunt run:dev > /dev/null &
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"npm": "1.2.x"
},
"scripts": {
"test": "grunt karma:continuous && ./node_modules/protractor/bin/protractor protractor.conf.js",
"test": "./test/run_tests.sh",
"start": "grunt run:dev",
"postinstall": "./node_modules/bower/bin/bower install -f"
},
Expand Down
2 changes: 1 addition & 1 deletion protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ exports.config = {
showColors: true,
defaultTimeoutInterval: 30000
}
};
};
1 change: 1 addition & 0 deletions test/e2e/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('front page', function() {
it("don't login when using wrong credentials", function(){
var button = element(by.className('btn'));
button.click();
browser.sleep(1000);
element(by.model('loginUsername')).sendKeys('username');
element(by.model('loginPassword')).sendKeys('pass');
var login = element(by.css("#login-tab input[value='Login']"));
Expand Down
19 changes: 19 additions & 0 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Configuration
TEST_DB=habitrpg_test
TEST_DB_URI="mongodb://localhost/$TEST_DB"

# Build assets
grunt build:dev

# Launch Node server and Selenium
echo "Recreating test database"
mongo "$TEST_DB" --eval "db.dropDatabase()"
./node_modules/protractor/bin/webdriver-manager update
./node_modules/protractor/bin/webdriver-manager start > /dev/null &
NODE_DB_URI="$TEST_DB_URI" node ./src/server.js > /dev/null &
NODE_PID=$!
trap "kill $NODE_PID && curl http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer" EXIT

sleep 3 # Wait for Selenium
grunt karma:continuous && ./node_modules/protractor/bin/protractor protractor.conf.js

0 comments on commit 431622c

Please sign in to comment.