From 891c75aeda5d511dd72538f2b42ababea8db7b1c Mon Sep 17 00:00:00 2001 From: MusikAnimal Date: Mon, 7 Mar 2016 22:14:07 -0500 Subject: [PATCH] Acceptance tests!! Runs automatically with pushes/pull requests Uses Sauce Labs integration within Travis. Next we will use the npm module so that we can run the tests via Grunt. Documentation to come. --- .gitignore | 4 +++- .travis.yml | 16 +++++++++++-- nightwatch | 2 ++ nightwatch.json | 54 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + tests/initialize.js | 35 ++++++++++++++++++++++++++++ tests/validations.js | 13 +++++++++++ 7 files changed, 122 insertions(+), 3 deletions(-) create mode 100755 nightwatch create mode 100644 nightwatch.json create mode 100644 tests/initialize.js create mode 100644 tests/validations.js diff --git a/.gitignore b/.gitignore index 284d9d76b..2ddfc51f9 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ config.php composer.lock vendor/composer vendor/krinkle -vendor/autoload.php \ No newline at end of file +vendor/autoload.php +reports/ +*.jar diff --git a/.travis.yml b/.travis.yml index 2711be984..19472c29f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,22 @@ language: php php: - 5.5 -node_js: - - 4.3.0 before_script: + - nvm install 5.6.0 + - nvm use 5.6.0 - npm install -g grunt-cli - npm install + - sudo apt-get install apache2 + - sudo a2enmod actions + - sudo a2enmod rewrite + - echo "export PATH=/home/vagrant/.phpenv/bin:$PATH" | sudo tee -a /etc/apache2/envvars > /dev/null + - echo "$(curl -fsSL https://gist.github.com/roderik/16d751c979fdeb5a14e3/raw/gistfile1.txt)" | sudo tee /etc/apache2/conf.d/phpconfig > /dev/null + - echo "$(curl -fsSL https://gist.github.com/roderik/2eb301570ed4a1f4c33d/raw/gistfile1.txt)" | sed -e "s,PATH,`pwd`/public_html,g" | sudo tee /etc/apache2/sites-available/default > /dev/null + - sudo service apache2 restart script: - eslint -c .eslintrc javascripts/ + - ./nightwatch --env saucelabs +addons: + sauce_connect: + username: "MusikAnimal" + access_key: "71bb4995-3679-4b53-89d3-9d1516da1089" diff --git a/nightwatch b/nightwatch new file mode 100755 index 000000000..42c1d96f2 --- /dev/null +++ b/nightwatch @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require('nightwatch/bin/runner.js'); diff --git a/nightwatch.json b/nightwatch.json new file mode 100644 index 000000000..0b8a402f5 --- /dev/null +++ b/nightwatch.json @@ -0,0 +1,54 @@ +{ + "src_folders" : ["tests"], + "output_folder" : "reports", + "custom_commands_path" : "", + "custom_assertions_path" : "", + "page_objects_path" : "", + "globals_path" : "", + + "selenium" : { + "start_process" : false, + "server_path" : "", + "log_path" : "", + "host" : "127.0.0.1", + "port" : 4444, + "cli_args" : { + "webdriver.chrome.driver" : "" + } + }, + + "test_settings" : { + "default" : { + "launch_url" : "http://localhost/pageviews", + "selenium_port" : 4444, + "selenium_host" : "localhost", + "silent": true, + "screenshots" : { + "enabled" : false, + "path" : "" + }, + "desiredCapabilities": { + "browserName": "firefox", + "javascriptEnabled": true, + "acceptSslCerts": true + } + }, + "saucelabs" : { + "launch_url" : "http://127.0.0.1/pageviews", + "selenium_host": "ondemand.saucelabs.com", + "selenium_port": 80, + "username": "MusikAnimal", + "access_key": "71bb4995-3679-4b53-89d3-9d1516da1089", + "use_ssl" : false, + "silent": true, + "output" : true, + "desiredCapabilities": { + "name": "test-example", + "browserName": "firefox" + }, + "selenium" : { + "start_process" : false + } + } + } +} diff --git a/package.json b/package.json index 825de60ca..6d91d7998 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "gruntify-eslint": "*", "jquery": "2.1.1", "moment": "2.11.2", + "nightwatch": "*", "underscore": "*" }, "scripts": { diff --git a/tests/initialize.js b/tests/initialize.js new file mode 100644 index 000000000..1e5b742cd --- /dev/null +++ b/tests/initialize.js @@ -0,0 +1,35 @@ +const moment = require('moment'); +const _ = require('underscore'); + +module.exports = { + 'Page loads with defaults when given no params' : function (client) { + client + .url('http://localhost/pageviews') + .waitForElementPresent('canvas', 10000); + + const startDate = moment().subtract(20, 'days').format('M/D/YYYY'), + endDate = moment().subtract(1, 'days').format('M/D/YYYY'), + dateStr = `${startDate} - ${endDate}`; + + client.expect.element('#range-input').to.have.value.that.equals(dateStr); + client.expect.element('.aqs-project-input').to.have.value.that.equals('en.wikipedia.org'); + client.expect.element('#platform-select').to.have.value.that.equals('all-access'); + client.expect.element('#agent-select').to.have.value.that.equals('user'); + client.expect.element('.select2-selection__rendered').to.have.text.that.matches(/×Cat\n.*×Dog/m); + client.expect.element('#chart-legend').to.have.text.that.matches(/\bCat\b.*\bDog\b/); + client.end(); + }, + 'Page loads with values and text matching given params' : function(client) { + client + .url('http://localhost/pageviews#start=2016-01-01&end=2016-01-10&project=en.wikivoyage.org&pages=Europe|Asia&platform=desktop&agent=spider') + .waitForElementPresent('canvas', 10000); + + client.expect.element('#range-input').to.have.value.that.equals('1/1/2016 - 1/10/2016'); + client.expect.element('.aqs-project-input').to.have.value.that.equals('en.wikivoyage.org'); + client.expect.element('#platform-select').to.have.value.that.equals('desktop'); + client.expect.element('#agent-select').to.have.value.that.equals('spider'); + client.expect.element('.select2-selection__rendered').to.have.text.that.matches(/Europe\n.*Asia/m); + client.expect.element('#chart-legend').to.have.text.that.matches(/\bEurope\b.*\bAsia\b/); + client.end(); + } +}; diff --git a/tests/validations.js b/tests/validations.js new file mode 100644 index 000000000..0605f9e18 --- /dev/null +++ b/tests/validations.js @@ -0,0 +1,13 @@ +module.exports = { + 'Invalid project shows error and disables form' : function (browser) { + browser + .url('http://localhost/pageviews') + .waitForElementVisible('body', 1000) + .setValue('.aqs-project-input', ['en.nonexistent.org', browser.Keys.TAB]) + .pause(1000) + .assert.containsText('.error-message', 'en.nonexistent.org') + .assert.cssClassPresent('.select2-selection--multiple', 'disabled') + .assert.elementNotPresent('canvas') + .end(); + } +};