From f5a341b37e054de3b4ab3096c8a7630d4ba9ccad Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Mon, 1 Feb 2016 17:12:49 +0100 Subject: [PATCH] Add environment config file for visual regression tests Wayyyyy better than hard coding diminator everywhere. --- phantomjs/launch_app_and_login.js | 62 ---------------- test/gemini/README.md | 9 ++- test/gemini/tests/environment.js | 22 ++++++ test/gemini/tests/main/authenticated.js | 5 +- test/gemini/tests/main/basic.js | 13 ++-- test/gemini/tests/main/detail.js | 9 +-- .../tests/whitelabel/ikonotv/ikonotv.js | 11 +-- .../whitelabel/shared/whitelabel_basic.js | 13 ++-- test/phantomjs/launch_app_and_login.js | 71 +++++++++++++++++++ 9 files changed, 127 insertions(+), 88 deletions(-) delete mode 100644 phantomjs/launch_app_and_login.js create mode 100644 test/gemini/tests/environment.js create mode 100644 test/phantomjs/launch_app_and_login.js diff --git a/phantomjs/launch_app_and_login.js b/phantomjs/launch_app_and_login.js deleted file mode 100644 index e5418519..00000000 --- a/phantomjs/launch_app_and_login.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -var liveEnv = 'https://www.ascribe.io/app/login'; -// Note that if you are trying to access staging, you will need to use -// the --ignore-ssl-errors=true flag on phantomjs -var stagingEnv = 'https://www.ascribe.ninja/app/login'; -var localEnv = 'http://localhost.com:3000/login'; - -var page = require('webpage').create(); -page.open(localEnv, function(status) { - var attemptedToLogIn; - var loginCheckInterval; - - console.log('Status: ' + status); - - if (status === 'success') { - console.log('Attempting to log in...'); - - attemptedToLogIn = page.evaluate(function () { - try { - var inputForm = document.querySelector('.ascribe-login-wrapper'); - var email = inputForm.querySelector('input[type=email]'); - var password = inputForm.querySelector('input[type=password]'); - var submitBtn = inputForm.querySelector('button[type=submit]'); - - email.value = 'dimi@mailinator.com'; - password.value = '0000000000'; - submitBtn.click(); - - return true; - } catch (ex) { - console.log('Error while trying to find login elements, not logging in.'); - return false; - } - }); - - if (attemptedToLogIn) { - loginCheckInterval = setInterval(function () { - var loggedIn = page.evaluate(function () { - // When they log in, they are taken to the collections page. - // When the piece list is loaded, the accordion list is either available or - // shows a placeholder, so let's check for these elements to determine - // when login is finished - return !!(document.querySelector('.ascribe-accordion-list:not(.ascribe-loading-position)') || - document.querySelector('.ascribe-accordion-list-placeholder')); - }); - - if (loggedIn) { - clearInterval(loginCheckInterval); - console.log('Successfully logged in.'); - } - }, 1000); - } else { - console.log('Something happened while trying to log in, aborting...'); - phantom.exit(); - } - - } else { - console.log('Failed to load page, exiing...'); - phantom.exit(); - } -}); diff --git a/test/gemini/README.md b/test/gemini/README.md index da1712d9..bc029041 100644 --- a/test/gemini/README.md +++ b/test/gemini/README.md @@ -122,9 +122,12 @@ See [the docs](https://github.com/gemini-testing/gemini/blob/master/doc/tests.md actions](https://github.com/gemini-testing/gemini/blob/master/doc/tests.md#available-actions) for what scripted actions are available. -Our tests are located in `onion/test/gemini/tests/`. +Our tests are located in `onion/test/gemini/tests/`. For now, the tests use the environment defined in +`onion/test/gemini/tests/environment.js` for which user, piece, and edition to run tests against. In the future, it'd be +nice if we had some db scripts that we could use to populate a test db for these regression tests. -**It would be nice if we kept the whitelabels up to date.** +**It would also be nice if we kept the whitelabels up to date, so if you add one, please also test (at least) its landing +page.** Some useful tips: * The `find()` method in the callbacks is equivalent to `document.querySelector`; it will only return the first @@ -193,7 +196,7 @@ change the environment to run against. ```bash # In root /onion folder -phantomjs phantomjs/launch_app_and_login.js +phantomjs test/phantomjs/launch_app_and_login.js ``` diff --git a/test/gemini/tests/environment.js b/test/gemini/tests/environment.js new file mode 100644 index 00000000..4cb1dacf --- /dev/null +++ b/test/gemini/tests/environment.js @@ -0,0 +1,22 @@ +'use strict'; + +const mainUser = { + email: 'dimi@mailinator.com', + password: '0000000000' +}; +const mainPieceId = '12374'; +const mainEditionId = '14gw9x3VA9oJaxp4cHaAuK2bvJzvEj4Xvc'; + +console.log('================== Test environment ==================\n'); +console.log('Main user:'); +console.log(` Email: ${mainUser.email}`); +console.log(` Password: ${mainUser.password}\n`); +console.log(`Main piece: ${mainPieceId}`); +console.log(`Main edition: ${mainEditionId}\n`); +console.log('========================================================\n'); + +module.exports = { + mainUser, + mainPieceId, + mainEditionId +}; diff --git a/test/gemini/tests/main/authenticated.js b/test/gemini/tests/main/authenticated.js index bf579bff..52730d4c 100644 --- a/test/gemini/tests/main/authenticated.js +++ b/test/gemini/tests/main/authenticated.js @@ -1,6 +1,7 @@ 'use strict'; const gemini = require('gemini'); +const environment = require('../environment'); /** * Suite of tests against routes that require the user to be authenticated. @@ -25,8 +26,8 @@ gemini.suite('Authenticated', (suite) => { .capture('logged in', (actions, find) => { actions.waitForElementToShow('.ascribe-form', 5000); - actions.sendKeys(find('.ascribe-login-wrapper input[name=email]'), 'dimi@mailinator.com'); - actions.sendKeys(find('.ascribe-login-wrapper input[name=password]'), '0000000000'); + actions.sendKeys(find('.ascribe-login-wrapper input[name=email]'), environment.mainUser.email); + actions.sendKeys(find('.ascribe-login-wrapper input[name=password]'), environment.mainUser.password); actions.click(find('.ascribe-login-wrapper button[type=submit]')); actions.waitForElementToShow('.ascribe-accordion-list:not(.ascribe-loading-position)', 5000); diff --git a/test/gemini/tests/main/basic.js b/test/gemini/tests/main/basic.js index 317c5d84..2e3dcb3a 100644 --- a/test/gemini/tests/main/basic.js +++ b/test/gemini/tests/main/basic.js @@ -1,6 +1,7 @@ 'use strict'; const gemini = require('gemini'); +const environment = require('../environment'); /** * Basic suite of tests against routes that do not require the user to be authenticated. @@ -84,8 +85,8 @@ gemini.suite('Basic', (suite) => { // Remove hover from sign up link actions.click(emailInput); - actions.sendKeys(emailInput, 'dimi@mailinator.com'); - actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); + actions.sendKeys(emailInput, environment.mainUser.email); + actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password); }) .capture('login form filled', (actions, find) => { actions.click(find('.ascribe-form-header')); @@ -99,9 +100,9 @@ gemini.suite('Basic', (suite) => { actions.waitForElementToShow('.ascribe-form', 5000); }) .capture('sign up form filled with focus', (actions, find) => { - actions.sendKeys(find('.ascribe-form input[name=email]'), 'dimi@mailinator.com'); - actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); - actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), '0000000000'); + actions.sendKeys(find('.ascribe-form input[name=email]'), environment.mainUser.email); + actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password); + actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), environment.mainUser.password); }) .capture('sign up form filled with check', (actions, find) => { actions.click(find('.ascribe-form input[type="checkbox"] ~ .checkbox')); @@ -115,7 +116,7 @@ gemini.suite('Basic', (suite) => { actions.waitForElementToShow('.ascribe-form', 5000); }) .capture('password reset form filled with focus', (actions, find) => { - actions.sendKeys(find('.ascribe-form input[name="email"]'), 'dimi@mailinator.com'); + actions.sendKeys(find('.ascribe-form input[name="email"]'), environment.mainUser.email); }) .capture('password reset form filled', (actions, find) => { actions.click(find('.ascribe-form-header')); diff --git a/test/gemini/tests/main/detail.js b/test/gemini/tests/main/detail.js index 7adad5d4..fd07af6a 100644 --- a/test/gemini/tests/main/detail.js +++ b/test/gemini/tests/main/detail.js @@ -1,8 +1,9 @@ 'use strict'; const gemini = require('gemini'); -const pieceUrl = '/pieces/12374'; -const editionUrl = '/editions/14gw9x3VA9oJaxp4cHaAuK2bvJzvEj4Xvc'; +const environment = require('../environment'); +const pieceUrl = `/pieces/${environment.mainPieceId}`; +const editionUrl = `/editions/${environment.mainEditionId}`; /** * Suite of tests against the piece and edition routes. @@ -57,8 +58,8 @@ gemini.suite('Work detail', (suite) => { actions.waitForElementToShow('.ascribe-default-app', 5000); }) .capture('logged in', (actions, find) => { - actions.sendKeys(find('.ascribe-login-wrapper input[name=email]'), 'dimi@mailinator.com'); - actions.sendKeys(find('.ascribe-login-wrapper input[name=password]'), '0000000000'); + actions.sendKeys(find('.ascribe-login-wrapper input[name=email]'), environment.mainUser.email); + actions.sendKeys(find('.ascribe-login-wrapper input[name=password]'), environment.mainUser.password); actions.click(find('.ascribe-login-wrapper button[type=submit]')); actions.waitForElementToShow('.ascribe-accordion-list:not(.ascribe-loading-position)', 5000); diff --git a/test/gemini/tests/whitelabel/ikonotv/ikonotv.js b/test/gemini/tests/whitelabel/ikonotv/ikonotv.js index 1741aaa0..05c36405 100644 --- a/test/gemini/tests/whitelabel/ikonotv/ikonotv.js +++ b/test/gemini/tests/whitelabel/ikonotv/ikonotv.js @@ -1,6 +1,7 @@ 'use strict'; const gemini = require('gemini'); +const environment = require('../environment'); /** * Suite of tests against Cyland specific routes @@ -68,8 +69,8 @@ gemini.suite('Ikonotv', (suite) => { // Remove hover from sign up link actions.click(emailInput); - actions.sendKeys(emailInput, 'dimi@mailinator.com'); - actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); + actions.sendKeys(emailInput, environment.mainUser.email); + actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password); }) .capture('login form filled', (actions, find) => { actions.click(find('.ascribe-form-header')); @@ -81,9 +82,9 @@ gemini.suite('Ikonotv', (suite) => { .setUrl('/signup') .capture('sign up') .capture('sign up form filled with focus', (actions, find) => { - actions.sendKeys(find('.ascribe-form input[name=email]'), 'dimi@mailinator.com'); - actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); - actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), '0000000000'); + actions.sendKeys(find('.ascribe-form input[name=email]'), environment.mainUser.email); + actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password); + actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), environment.mainUser.password); }) .capture('sign up form filled with check', (actions, find) => { actions.click(find('.ascribe-form input[type="checkbox"] ~ .checkbox')); diff --git a/test/gemini/tests/whitelabel/shared/whitelabel_basic.js b/test/gemini/tests/whitelabel/shared/whitelabel_basic.js index 7fe5c256..24aa432b 100644 --- a/test/gemini/tests/whitelabel/shared/whitelabel_basic.js +++ b/test/gemini/tests/whitelabel/shared/whitelabel_basic.js @@ -1,6 +1,7 @@ 'use strict'; const gemini = require('gemini'); +const environment = require('../environment'); /** * Basic suite of tests against whitelabel routes that do not require authentication. @@ -43,8 +44,8 @@ gemini.suite('Whitelabel basic', (suite) => { // Remove hover from sign up link actions.click(emailInput); - actions.sendKeys(emailInput, 'dimi@mailinator.com'); - actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); + actions.sendKeys(emailInput, environment.mainUser.email); + actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password); }) .capture('login form filled', (actions, find) => { actions.click(find('.ascribe-form-header')); @@ -62,9 +63,9 @@ gemini.suite('Whitelabel basic', (suite) => { actions.wait(500); }) .capture('sign up form filled with focus', (actions, find) => { - actions.sendKeys(find('.ascribe-form input[name=email]'), 'dimi@mailinator.com'); - actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); - actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), '0000000000'); + actions.sendKeys(find('.ascribe-form input[name=email]'), environment.mainUser.email); + actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password); + actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), environment.mainUser.password); }) .capture('sign up form filled with check', (actions, find) => { actions.click(find('.ascribe-form input[type="checkbox"] ~ .checkbox')); @@ -80,7 +81,7 @@ gemini.suite('Whitelabel basic', (suite) => { actions.wait(500); }) .capture('password reset form filled with focus', (actions, find) => { - actions.sendKeys(find('.ascribe-form input[name="email"]'), 'dimi@mailinator.com'); + actions.sendKeys(find('.ascribe-form input[name="email"]'), environment.mainUser.email); }) .capture('password reset form filled', (actions, find) => { actions.click(find('.ascribe-form-header')); diff --git a/test/phantomjs/launch_app_and_login.js b/test/phantomjs/launch_app_and_login.js new file mode 100644 index 00000000..afc76f9e --- /dev/null +++ b/test/phantomjs/launch_app_and_login.js @@ -0,0 +1,71 @@ +'use strict'; + +var liveEnv = 'https://www.ascribe.io/app/login'; +// Note that if you are trying to access staging, you will need to use +// the --ignore-ssl-errors=true flag on phantomjs +var stagingEnv = 'https://www.ascribe.ninja/app/login'; +var localEnv = 'http://localhost.com:3000/login'; + +function launchAppAndLogin(env) { + console.log('Running test to launch ' + env + ' and log into the app'); + + var page = require('webpage').create(); + page.open(localEnv, function(status) { + var attemptedToLogIn; + var loginCheckInterval; + + console.log('Load ' + env + ': ' + status); + + if (status === 'success') { + console.log('Attempting to log in...'); + + attemptedToLogIn = page.evaluate(function () { + try { + var inputForm = document.querySelector('.ascribe-login-wrapper'); + var email = inputForm.querySelector('input[name=email]'); + var password = inputForm.querySelector('input[name=password]'); + var submitBtn = inputForm.querySelector('button[type=submit]'); + + email.value = 'dimi@mailinator.com'; + password.value = '0000000000'; + submitBtn.click(); + + return true; + } catch (ex) { + console.log('Error while trying to find login elements, not logging in.'); + return false; + } + }); + + if (attemptedToLogIn) { + loginCheckInterval = setInterval(function () { + var loggedIn = page.evaluate(function () { + // When they log in, they are taken to the collections page. + // When the piece list is loaded, the accordion list is either available or + // shows a placeholder, so let's check for these elements to determine + // when login is finished + return !!(document.querySelector('.ascribe-accordion-list:not(.ascribe-loading-position)') || + document.querySelector('.ascribe-accordion-list-placeholder')); + }); + + if (loggedIn) { + clearInterval(loginCheckInterval); + console.log('Successfully logged in.'); + console.log('Edit the onion/test/phantomjs/launch_app_and_login.js file to do further actions after logging in.'); + console.log('Stopping phantomJS...'); + phantom.exit(); + } + }, 1000); + } else { + console.log('Something happened while trying to log in, aborting...'); + phantom.exit(); + } + + } else { + console.log('Failed to load page, exiing...'); + phantom.exit(); + } + }); +} + +launchAppAndLogin(localEnv);