1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Add environment config file for visual regression tests

Wayyyyy better than hard coding diminator everywhere.
This commit is contained in:
Brett Sun 2016-02-01 17:12:49 +01:00
parent a785fbc220
commit f5a341b37e
9 changed files with 127 additions and 88 deletions

View File

@ -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();
}
});

View File

@ -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 actions](https://github.com/gemini-testing/gemini/blob/master/doc/tests.md#available-actions) for what scripted actions
are available. 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: Some useful tips:
* The `find()` method in the callbacks is equivalent to `document.querySelector`; it will only return the first * 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 ```bash
# In root /onion folder # In root /onion folder
phantomjs phantomjs/launch_app_and_login.js phantomjs test/phantomjs/launch_app_and_login.js
``` ```

View File

@ -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
};

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const gemini = require('gemini'); const gemini = require('gemini');
const environment = require('../environment');
/** /**
* Suite of tests against routes that require the user to be authenticated. * 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) => { .capture('logged in', (actions, find) => {
actions.waitForElementToShow('.ascribe-form', 5000); 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=email]'), environment.mainUser.email);
actions.sendKeys(find('.ascribe-login-wrapper input[name=password]'), '0000000000'); actions.sendKeys(find('.ascribe-login-wrapper input[name=password]'), environment.mainUser.password);
actions.click(find('.ascribe-login-wrapper button[type=submit]')); actions.click(find('.ascribe-login-wrapper button[type=submit]'));
actions.waitForElementToShow('.ascribe-accordion-list:not(.ascribe-loading-position)', 5000); actions.waitForElementToShow('.ascribe-accordion-list:not(.ascribe-loading-position)', 5000);

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const gemini = require('gemini'); const gemini = require('gemini');
const environment = require('../environment');
/** /**
* Basic suite of tests against routes that do not require the user to be authenticated. * 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 // Remove hover from sign up link
actions.click(emailInput); actions.click(emailInput);
actions.sendKeys(emailInput, 'dimi@mailinator.com'); actions.sendKeys(emailInput, environment.mainUser.email);
actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password);
}) })
.capture('login form filled', (actions, find) => { .capture('login form filled', (actions, find) => {
actions.click(find('.ascribe-form-header')); actions.click(find('.ascribe-form-header'));
@ -99,9 +100,9 @@ gemini.suite('Basic', (suite) => {
actions.waitForElementToShow('.ascribe-form', 5000); actions.waitForElementToShow('.ascribe-form', 5000);
}) })
.capture('sign up form filled with focus', (actions, find) => { .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=email]'), environment.mainUser.email);
actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password);
actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), '0000000000'); actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), environment.mainUser.password);
}) })
.capture('sign up form filled with check', (actions, find) => { .capture('sign up form filled with check', (actions, find) => {
actions.click(find('.ascribe-form input[type="checkbox"] ~ .checkbox')); actions.click(find('.ascribe-form input[type="checkbox"] ~ .checkbox'));
@ -115,7 +116,7 @@ gemini.suite('Basic', (suite) => {
actions.waitForElementToShow('.ascribe-form', 5000); actions.waitForElementToShow('.ascribe-form', 5000);
}) })
.capture('password reset form filled with focus', (actions, find) => { .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) => { .capture('password reset form filled', (actions, find) => {
actions.click(find('.ascribe-form-header')); actions.click(find('.ascribe-form-header'));

View File

@ -1,8 +1,9 @@
'use strict'; 'use strict';
const gemini = require('gemini'); const gemini = require('gemini');
const pieceUrl = '/pieces/12374'; const environment = require('../environment');
const editionUrl = '/editions/14gw9x3VA9oJaxp4cHaAuK2bvJzvEj4Xvc'; const pieceUrl = `/pieces/${environment.mainPieceId}`;
const editionUrl = `/editions/${environment.mainEditionId}`;
/** /**
* Suite of tests against the piece and edition routes. * Suite of tests against the piece and edition routes.
@ -57,8 +58,8 @@ gemini.suite('Work detail', (suite) => {
actions.waitForElementToShow('.ascribe-default-app', 5000); actions.waitForElementToShow('.ascribe-default-app', 5000);
}) })
.capture('logged in', (actions, find) => { .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=email]'), environment.mainUser.email);
actions.sendKeys(find('.ascribe-login-wrapper input[name=password]'), '0000000000'); actions.sendKeys(find('.ascribe-login-wrapper input[name=password]'), environment.mainUser.password);
actions.click(find('.ascribe-login-wrapper button[type=submit]')); actions.click(find('.ascribe-login-wrapper button[type=submit]'));
actions.waitForElementToShow('.ascribe-accordion-list:not(.ascribe-loading-position)', 5000); actions.waitForElementToShow('.ascribe-accordion-list:not(.ascribe-loading-position)', 5000);

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const gemini = require('gemini'); const gemini = require('gemini');
const environment = require('../environment');
/** /**
* Suite of tests against Cyland specific routes * Suite of tests against Cyland specific routes
@ -68,8 +69,8 @@ gemini.suite('Ikonotv', (suite) => {
// Remove hover from sign up link // Remove hover from sign up link
actions.click(emailInput); actions.click(emailInput);
actions.sendKeys(emailInput, 'dimi@mailinator.com'); actions.sendKeys(emailInput, environment.mainUser.email);
actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password);
}) })
.capture('login form filled', (actions, find) => { .capture('login form filled', (actions, find) => {
actions.click(find('.ascribe-form-header')); actions.click(find('.ascribe-form-header'));
@ -81,9 +82,9 @@ gemini.suite('Ikonotv', (suite) => {
.setUrl('/signup') .setUrl('/signup')
.capture('sign up') .capture('sign up')
.capture('sign up form filled with focus', (actions, find) => { .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=email]'), environment.mainUser.email);
actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password);
actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), '0000000000'); actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), environment.mainUser.password);
}) })
.capture('sign up form filled with check', (actions, find) => { .capture('sign up form filled with check', (actions, find) => {
actions.click(find('.ascribe-form input[type="checkbox"] ~ .checkbox')); actions.click(find('.ascribe-form input[type="checkbox"] ~ .checkbox'));

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const gemini = require('gemini'); const gemini = require('gemini');
const environment = require('../environment');
/** /**
* Basic suite of tests against whitelabel routes that do not require authentication. * 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 // Remove hover from sign up link
actions.click(emailInput); actions.click(emailInput);
actions.sendKeys(emailInput, 'dimi@mailinator.com'); actions.sendKeys(emailInput, environment.mainUser.email);
actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password);
}) })
.capture('login form filled', (actions, find) => { .capture('login form filled', (actions, find) => {
actions.click(find('.ascribe-form-header')); actions.click(find('.ascribe-form-header'));
@ -62,9 +63,9 @@ gemini.suite('Whitelabel basic', (suite) => {
actions.wait(500); actions.wait(500);
}) })
.capture('sign up form filled with focus', (actions, find) => { .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=email]'), environment.mainUser.email);
actions.sendKeys(find('.ascribe-form input[name=password]'), '0000000000'); actions.sendKeys(find('.ascribe-form input[name=password]'), environment.mainUser.password);
actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), '0000000000'); actions.sendKeys(find('.ascribe-form input[name=password_confirm]'), environment.mainUser.password);
}) })
.capture('sign up form filled with check', (actions, find) => { .capture('sign up form filled with check', (actions, find) => {
actions.click(find('.ascribe-form input[type="checkbox"] ~ .checkbox')); actions.click(find('.ascribe-form input[type="checkbox"] ~ .checkbox'));
@ -80,7 +81,7 @@ gemini.suite('Whitelabel basic', (suite) => {
actions.wait(500); actions.wait(500);
}) })
.capture('password reset form filled with focus', (actions, find) => { .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) => { .capture('password reset form filled', (actions, find) => {
actions.click(find('.ascribe-form-header')); actions.click(find('.ascribe-form-header'));

View File

@ -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);