diff --git a/.travis.yml b/.travis.yml index 9f977e2505..7edd7c20b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,10 @@ language: node_js node_js: - '0.10' +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 diff --git a/karma-e2e.conf.js b/karma-e2e.conf.js deleted file mode 100644 index fa01484a0a..0000000000 --- a/karma-e2e.conf.js +++ /dev/null @@ -1,54 +0,0 @@ -// Karma configuration -// http://karma-runner.github.io/0.10/config/configuration-file.html - -module.exports = function(config) { - config.set({ - // base path, that will be used to resolve files and exclude - basePath: '', - - // testing framework to use (jasmine/mocha/qunit/...) - frameworks: ['ng-scenario'], - - // list of files / patterns to load in the browser - files: [ - 'test/e2e/**/*.js' - ], - - // list of files / patterns to exclude - exclude: [], - - // web server port - port: 8080, - - // level of logging - // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG - logLevel: config.LOG_INFO, - - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: false, - - - // Start these browsers, currently available: - // - Chrome - // - ChromeCanary - // - Firefox - // - Opera - // - Safari (only Mac) - // - PhantomJS - // - IE (only Windows) - browsers: ['Chrome'], - - - // Continuous Integration mode - // if true, it capture browsers, run tests and exit - singleRun: false - - // Uncomment the following lines if you are using grunt's server to run the tests - // proxies: { - // '/': 'http://localhost:9000/' - // }, - // URL root prevent conflicts with the site root - // urlRoot: '_karma_' - }); -}; diff --git a/package.json b/package.json index 9e2ac50493..a81bbd57d2 100644 --- a/package.json +++ b/package.json @@ -58,12 +58,12 @@ "npm": "1.2.x" }, "scripts": { - "test": "grunt karma:continuous", + "test": "./test/run_tests.sh", "start": "grunt run:dev", "postinstall": "./node_modules/bower/bin/bower install -f" }, "devDependencies": { - "karma-ng-scenario": "~0.1.0", + "protractor": "~0.14.0", "grunt-karma": "~0.6.2", "karma-script-launcher": "~0.1.0", "karma-chrome-launcher": "~0.1.0", diff --git a/protractor.conf.js b/protractor.conf.js new file mode 100644 index 0000000000..32999a2233 --- /dev/null +++ b/protractor.conf.js @@ -0,0 +1,24 @@ +// An example configuration file. +exports.config = { + // The address of a running selenium server. + seleniumAddress: 'http://localhost:4444/wd/hub', + + // Capabilities to be passed to the webdriver instance. + capabilities: { + 'browserName': 'firefox' + }, + + // Spec patterns are relative to the current working directly when + // protractor is called. + specs: ['test/e2e/e2e.js'], + + // A base URL for your application under test. Calls to protractor.get() + // with relative paths will be prepended with this. + baseUrl: 'http://localhost:3001', + + // Options to be passed to Jasmine-node. + jasmineNodeOpts: { + showColors: true, + defaultTimeoutInterval: 30000 + } +}; diff --git a/test/e2e/e2e.js b/test/e2e/e2e.js new file mode 100644 index 0000000000..8bbdbe8a62 --- /dev/null +++ b/test/e2e/e2e.js @@ -0,0 +1,61 @@ +'use strict'; + +describe('front page', function() { + beforeEach(function(){ + browser.ignoreSynchronization = true; + browser.get('/'); + browser.sleep(1000); + }); + + // based on https://github.com/angular/protractor/issues/114#issuecomment-29046939 + afterEach(function(){ + var currentSpec = jasmine.getEnv().currentSpec; + var passed = currentSpec.results().passed(); + if(!passed){ + var filename = 'exception_' + currentSpec.description + '.png'; + browser.takeScreenshot().then(function(png){ + var fs = require('fs'); + var buffer = new Buffer(png, 'base64'); + var stream = fs.createWriteStream(filename); + stream.write(buffer); + stream.end(); + }); + } + }); + + it('shows the front page', function(){ + var button = element(by.className('btn')); + expect(button.getText()).toEqual('Play'); + }); + + 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']")); + login.click(); + var alertDialog = browser.switchTo().alert(); + expect(alertDialog.getText()).toMatch(/Username 'username' not found/); + alertDialog.accept(); + }); + + it('registers a new user', function(){ + var button = element(by.className('btn')); + button.click(); + browser.sleep(1000); + var registerTab = element(by.linkText('Register')); + registerTab.click(); + element(by.model('registerVals.username')).sendKeys('user'); + element(by.model('registerVals.email')).sendKeys('user@example.com'); + element(by.model('registerVals.password')).sendKeys('pass'); + element(by.model('registerVals.confirmPassword')).sendKeys('pass'); + var register = element(by.css("#register-tab input[value='Register']")); + register.click(); + browser.sleep(1000); + browser.getCurrentUrl().then(function(url){ + expect(url).not.toMatch(/static\/front/); + }); + }); +}); \ No newline at end of file diff --git a/test/run_tests.sh b/test/run_tests.sh new file mode 100755 index 0000000000..d9f588ea06 --- /dev/null +++ b/test/run_tests.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Configuration +TEST_DB=habitrpg_test +TEST_DB_URI="mongodb://localhost/$TEST_DB" +TEST_SERVER_PORT=3001 + +# 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" PORT=$TEST_SERVER_PORT 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