0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Further grunt validate / casperjs test improvements

- Test environment runs on a different port
- Removed wait() and replaced with waitFor() where possible
- Added more timeout functions / handlers
- General consistency improvements
This commit is contained in:
Hannah Wolfe 2013-08-29 18:55:39 +01:00
parent 68704db01a
commit fe713c1042
9 changed files with 75 additions and 80 deletions

View file

@ -361,7 +361,7 @@ var path = require('path'),
grunt.registerTask('spawn-casperjs', function () {
var done = this.async(),
options = ['host', 'noPort', 'port', 'email', 'password'],
args = ['test', 'admin/', '--includes=base.js', '--direct', '--log-level=debug', '--fail-fast'];
args = ['test', 'admin/', '--includes=base.js', '--direct', '--log-level=debug', '--port=2369', '--fail-fast'];
// Forward parameters from grunt to casperjs
_.each(options, function processOption(option) {

View file

@ -45,7 +45,7 @@ config.env = {
},
url: {
host: '127.0.0.1',
port: '2368'
port: '2369'
}
},

View file

@ -1,10 +1,10 @@
/*globals casper, __utils__, url, user, falseUser */
casper.test.begin('Ensure Session is Killed', 1, function suite(test) {
casper.test.filename = 'login_logout_test.png';
test.filename = 'login_logout_test.png';
casper.start(url + 'logout/', function (response) {
test.assert(/\/ghost\//.test(response.url), response.url);
test.assertUrlMatch(/ghost\/signin/, 'We got redirected to signin page');
});
casper.run(function () {
@ -13,7 +13,7 @@ casper.test.begin('Ensure Session is Killed', 1, function suite(test) {
});
casper.test.begin('Ensure a User is Registered', 2, function suite(test) {
casper.test.filename = 'login_user_registered_test.png';
test.filename = 'login_user_registered_test.png';
casper.start(url + 'ghost/signup/');
@ -27,11 +27,11 @@ casper.test.begin('Ensure a User is Registered', 2, function suite(test) {
this.fill("#register", user, true);
});
casper.waitForSelectorTextChange('.notification-error', function (text) {
casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
test.assertSelectorHasText('.notification-error', 'already registered');
// If the previous assert succeeds, then we should skip the next check and just pass.
test.pass('Already registered!');
}, function () {
}, function onTimeout() {
test.assertUrlMatch(/\/ghost\/$/, 'If we\'re not already registered, we should be logged in.');
test.pass('Successfully registered.');
}, 2000);
@ -42,10 +42,10 @@ casper.test.begin('Ensure a User is Registered', 2, function suite(test) {
});
casper.test.begin('Ensure Session is Killed after Registration', 1, function suite(test) {
casper.test.filename = 'login_logout2_test.png';
test.filename = 'login_logout2_test.png';
casper.start(url + 'logout/', function (response) {
test.assert(/\/ghost\//.test(response.url), response.url);
casper.start(url + 'logout/', function then() {
test.assertUrlMatch(/ghost\/signin/, 'We got redirected to signin page');
});
casper.run(function () {
@ -54,12 +54,11 @@ casper.test.begin('Ensure Session is Killed after Registration', 1, function sui
});
casper.test.begin("Ghost admin will load login page", 2, function suite(test) {
casper.test.filename = "admin_test.png";
test.filename = "admin_test.png";
casper.start(url + "ghost", function testTitleAndUrl() {
test.assertTitle("", "Ghost admin has no title");
test.assertEquals(this.getCurrentUrl(), url + "ghost/signin/", "Ghost requires login");
test.assertUrlMatch(/ghost\/signin\/$/, 'If we\'re not already registered, we should be logged in.');
}).viewport(1280, 1024);
casper.run(function () {
@ -68,11 +67,11 @@ casper.test.begin("Ghost admin will load login page", 2, function suite(test) {
});
casper.test.begin('Redirects to signin', 2, function suite(test) {
casper.test.filename = 'login_redirect_test.png';
test.filename = 'login_redirect_test.png';
casper.start(url + 'ghost/login/', function testRedirect(response) {
test.assertEqual(response.status, 200, 'Response status should be 200.');
test.assert(/\/signin\/$/.test(response.url), 'Should be redirected to /signin/. Actual response url: ' + response.url + '.');
test.assertUrlMatch(/ghost\/signin\/$/, 'Should be redirected to /signin/.');
});
casper.run(function () {
@ -80,9 +79,8 @@ casper.test.begin('Redirects to signin', 2, function suite(test) {
});
});
casper.test.begin("Can't spam it", 2, function suite(test) {
casper.test.filename = "login_spam_test.png";
casper.test.begin("Can't spam it", 4, function suite(test) {
test.filename = "login_spam_test.png";
casper.start(url + "ghost/signin/", function testTitle() {
test.assertTitle("", "Ghost admin has no title");
@ -97,16 +95,18 @@ casper.test.begin("Can't spam it", 2, function suite(test) {
});
}, function then() {
this.fill("#login", falseUser, true);
casper.wait(200, function doneWait() {
this.fill("#login", falseUser, true);
});
});
casper.wait(1000, function doneWait() {
this.echo("I've waited for 1 seconds.");
});
casper.then(function testForErrorMessage() {
casper.wait(200, function doneWait() {
this.fill("#login", falseUser, true);
});
casper.waitForSelector('.notification-error', function onSuccess() {
test.assert(true, 'Save without title results in error notification as expected');
test.assertSelectorDoesntHaveText('.notification-error', '[object Object]');
test.assertSelectorHasText('.notification-error', 'Slow down, there are way too many login attempts!');
}, function onTimeout() {
test.assert(false, 'Spamming the login did not result in an error notification');
});
casper.run(function () {
@ -114,16 +114,15 @@ casper.test.begin("Can't spam it", 2, function suite(test) {
});
});
casper.test.begin("Can login to Ghost", 3, function suite(test) {
casper.test.filename = "login_test.png";
casper.test.begin("Can login to Ghost", 4, function suite(test) {
test.filename = "login_test.png";
casper.start(url + "ghost/login/", function testTitle() {
test.assertTitle("", "Ghost admin has no title");
}).viewport(1280, 1024);
casper.waitFor(function checkOpaque() {
return this.evaluate(function () {
return casper.evaluate(function () {
var loginBox = document.querySelector('.login-box');
return window.getComputedStyle(loginBox).getPropertyValue('display') === "block"
&& window.getComputedStyle(loginBox).getPropertyValue('opacity') === "1";
@ -132,13 +131,12 @@ casper.test.begin("Can login to Ghost", 3, function suite(test) {
this.fill("#login", user, true);
});
casper.wait(1000, function doneWait() {
this.echo("I've waited for 1 seconds.");
});
casper.then(function testForDashboard() {
this.test.assertExists("#global-header", "Global admin header is present");
this.test.assertExists(".dashboard", "We're now on the dashboard");
casper.waitForResource(/ghost\/$/, function testForDashboard() {
test.assertUrlMatch(/ghost\/$/, 'We got redirected to the Ghost page');
test.assertExists("#global-header", "Global admin header is present");
test.assertExists(".dashboard", "We're now on the dashboard");
}, function onTimeOut() {
test.fail('Failed to load ghost/ resource');
});
casper.run(function () {

View file

@ -1,12 +1,11 @@
/*globals casper, __utils__, url */
casper.test.begin("Ghost dashboard is correct", 13, function suite(test) {
casper.test.filename = "dashboard_test.png";
test.filename = "dashboard_test.png";
casper.start(url + "ghost", function testTitleAndUrl() {
test.assertTitle("", "Ghost admin has no title");
test.assertEquals(this.getCurrentUrl(), url + "ghost/", "Ghost doesn't require login this time");
test.assertUrlMatch(/ghost\/$/, "Ghost doesn't require login this time");
test.assertExists(".ghost-logo", "Ghost is present");
}).viewport(1280, 1024);
@ -30,8 +29,7 @@ casper.test.begin("Ghost dashboard is correct", 13, function suite(test) {
});
casper.test.begin("Ghost dashboard interactions are correct", 2, function suite(test) {
casper.test.filename = "dashboard_interactions_test.png";
test.filename = "dashboard_interactions_test.png";
casper.start(url + "ghost", function testTitleAndUrl() {
test.assertExists(".widget-time", "Time widget is present");

View file

@ -1,12 +1,11 @@
/*globals casper, __utils__, url, testPost */
casper.test.begin("Ghost editor is correct", 10, function suite(test) {
casper.test.filename = "editor_test.png";
test.filename = "editor_test.png";
casper.start(url + "ghost/editor", function testTitleAndUrl() {
test.assertTitle("", "Ghost admin has no title");
test.assertEquals(casper.getCurrentUrl(), url + "ghost/editor", "Ghost doesn't require login this time");
test.assertUrlMatch(/ghost\/editor$/, "Ghost doesn't require login this time");
test.assertExists(".entry-markdown", "Ghost editor is present");
test.assertExists(".entry-preview", "Ghost preview is present");
}).viewport(1280, 1024);
@ -19,9 +18,13 @@ casper.test.begin("Ghost editor is correct", 10, function suite(test) {
}
// test saving with no data
casper.thenClick('.button-save').wait(500, function doneWait() {
test.assertExists('.notification-error', 'got error notification');
casper.thenClick('.button-save');
casper.waitForSelector('.notification-error', function onSuccess() {
test.assert(true, 'Save without title results in error notification as expected');
test.assertSelectorDoesntHaveText('.notification-error', '[object Object]');
}, function onTimeout() {
test.assert(false, 'Save without title did not result in an error notification');
});
casper.then(function createTestPost() {
@ -36,7 +39,9 @@ casper.test.begin("Ghost editor is correct", 10, function suite(test) {
casper.on('resource.received', handleResource);
});
casper.thenClick('.button-save').waitForResource(/posts/, function checkPostWasCreated() {
casper.thenClick('.button-save');
casper.waitForResource(/posts/, function checkPostWasCreated() {
var urlRegExp = new RegExp("^" + url + "ghost\/editor\/[0-9]*");
test.assertUrlMatch(urlRegExp, 'got an id on our URL');
test.assertExists('.notification-success', 'got success notification');
@ -56,8 +61,7 @@ casper.test.begin("Ghost editor is correct", 10, function suite(test) {
casper.test.begin("Haunted markdown in editor works", 3, function suite(test) {
casper.test.filename = "markdown_test.png";
test.filename = "markdown_test.png";
casper.start(url + "ghost/editor", function testTitleAndUrl() {
test.assertTitle("", "Ghost admin has no title");
@ -88,8 +92,7 @@ casper.test.begin("Haunted markdown in editor works", 3, function suite(test) {
});
casper.test.begin("Word count and plurality", 4, function suite(test) {
casper.test.filename = "editor_plurality_test.png";
test.filename = "editor_plurality_test.png";
casper.start(url + "ghost/editor", function testTitleAndUrl() {
test.assertTitle("", "Ghost admin has no title");

View file

@ -1,12 +1,11 @@
/*globals casper, __utils__, url, testPost */
casper.test.begin("Content screen is correct", 9, function suite(test) {
casper.test.filename = "content_test.png";
test.filename = "content_test.png";
casper.start(url + "ghost/content/", function testTitleAndUrl() {
test.assertTitle("", "Ghost admin has no title");
test.assertEquals(this.getCurrentUrl(), url + "ghost/content/", "Ghost doesn't require login this time");
test.assertUrlMatch(/ghost\/content\/$/, "Ghost doesn't require login this time");
}).viewport(1280, 1024);
casper.then(function testViews() {

View file

@ -1,12 +1,11 @@
/*globals casper, __utils__, url */
casper.test.begin("Settings screen is correct", 19, function suite(test) {
casper.test.filename = "settings_test.png";
test.filename = "settings_test.png";
casper.start(url + "ghost/settings", function testTitleAndUrl() {
test.assertTitle("", "Ghost admin has no title");
test.assertEquals(this.getCurrentUrl(), url + "ghost/settings/general", "Ghost doesn't require login this time");
test.assertUrlMatch(/ghost\/settings\/general$/, "Ghost doesn't require login this time");
}).viewport(1280, 1024);
casper.then(function testViews() {
@ -24,7 +23,8 @@ casper.test.begin("Settings screen is correct", 19, function suite(test) {
});
// test the publishing / content tab
casper.thenClick('.settings-menu .publishing', function then() {
casper.thenClick('.settings-menu .publishing');
casper.waitForSelector('#content', function then() {
test.assertEval(function testGeneralIsNotActive() {
return !document.querySelector('.settings-menu .general').classList.contains('active');
}, "general tab is not marked active");
@ -34,10 +34,13 @@ casper.test.begin("Settings screen is correct", 19, function suite(test) {
test.assertEval(function testContentIsContent() {
return document.querySelector('.settings-content').id === 'content';
}, "loaded content is content screen");
}, function onTimeOut() {
test.fail('Content screen failed to load');
});
// test the user tab
casper.thenClick('.settings-menu .users', function then() {
casper.thenClick('.settings-menu .users');
casper.waitForSelector('#user', function then() {
test.assertEval(function testGeneralIsNotActive() {
return !document.querySelector('.settings-menu .general').classList.contains('active');
}, "general tab is not marked active");
@ -50,6 +53,8 @@ casper.test.begin("Settings screen is correct", 19, function suite(test) {
test.assertEval(function testContentIsUser() {
return document.querySelector('.settings-content').id === 'user';
}, "loaded content is user screen");
}, function onTimeOut() {
test.fail('User screen failed to load');
});
function handleUserRequest(requestData, request) {
@ -70,7 +75,8 @@ casper.test.begin("Settings screen is correct", 19, function suite(test) {
casper.on('resource.requested', handleUserRequest);
});
casper.thenClick('#user .button-save').waitFor(function successNotification() {
casper.thenClick('#user .button-save');
casper.waitFor(function successNotification() {
return this.evaluate(function () {
return document.querySelectorAll('.js-bb-notification section').length > 0;
});
@ -128,11 +134,11 @@ casper.test.begin("Settings screen is correct", 19, function suite(test) {
casper.test.begin("User settings screen validates email", 6, function suite(test) {
var email, brokenEmail;
casper.test.filename = "user_settings_test.png";
test.filename = "user_settings_test.png";
casper.start(url + "ghost/settings/user", function testTitleAndUrl() {
test.assertTitle("", "Ghost admin has no title");
test.assertEquals(this.getCurrentUrl(), url + "ghost/settings/user", "Ghost doesn't require login this time");
test.assertUrlMatch(/ghost\/settings\/user$/, "Ghost doesn't require login this time");
}).viewport(1280, 1024);
casper.then(function setEmailToInvalid() {
@ -163,7 +169,7 @@ casper.test.begin("User settings screen validates email", 6, function suite(test
casper.thenClick('#user .button-save');
casper.waitForResource('/users/');
casper.waitForResource(/users/);
casper.waitForSelector('.notification-success', function onSuccess() {
test.assert(true, 'Got success notification');

View file

@ -4,11 +4,10 @@
/*globals casper, __utils__, url, testPost */
casper.test.begin("Ghost edit draft flow works correctly", 7, function suite(test) {
casper.test.filename = "flow_test.png";
test.filename = "flow_test.png";
casper.start(url + "ghost/editor", function then() {
test.assertEquals(casper.getCurrentUrl(), url + "ghost/editor", "Ghost doesn't require login this time");
test.assertUrlMatch(/ghost\/editor$/, "Ghost doesn't require login this time");
}).viewport(1280, 1024);
// First, create a new draft post
@ -23,7 +22,6 @@ casper.test.begin("Ghost edit draft flow works correctly", 7, function suite(tes
});
casper.thenClick('.button-save');
casper.waitForResource(/posts/);
casper.waitForSelector('.notification-success', function onSuccess() {
@ -33,7 +31,7 @@ casper.test.begin("Ghost edit draft flow works correctly", 7, function suite(tes
});
casper.thenOpen(url + 'ghost/content/', function then() {
test.assertEquals(casper.getCurrentUrl(), url + "ghost/content/", "Ghost doesn't require login this time");
test.assertUrlMatch(/ghost\/content\//, "Ghost successfully loaded the content page");
});
casper.then(function then() {
@ -45,11 +43,10 @@ casper.test.begin("Ghost edit draft flow works correctly", 7, function suite(tes
});
casper.thenClick('.post-edit').waitForResource(/editor/, function then() {
test.assertUrlMatch(/editor/, "Ghost doesn't require login this time");
test.assertUrlMatch(/editor/, "Ghost sucessfully loaded the editor page again");
});
casper.thenClick('.button-save');
casper.waitForResource(/posts/);
casper.waitForSelector('.notification-success', function onSuccess() {
@ -66,7 +63,7 @@ casper.test.begin("Ghost edit draft flow works correctly", 7, function suite(tes
// TODO: test publishing, editing, republishing, unpublishing etc
//casper.test.begin("Ghost edit published flow works correctly", 6, function suite(test) {
//
// casper.test.filename = "flow_test.png";
// test.filename = "flow_test.png";
//
//
//});

View file

@ -4,8 +4,7 @@
/*globals casper, __utils__, url, testPost, falseUser, email */
casper.test.begin("Ghost logout works correctly", 2, function suite(test) {
casper.test.filename = "logout_test.png";
test.filename = "logout_test.png";
casper.start(url + "ghost/", function then() {
test.assertEquals(casper.getCurrentUrl(), url + "ghost/", "Ghost doesn't require login this time");
@ -20,7 +19,6 @@ casper.test.begin("Ghost logout works correctly", 2, function suite(test) {
});
casper.thenClick('.usermenu-signout a');
casper.waitForResource(/signin/);
casper.waitForSelector('.notification-success', function onSuccess() {
@ -36,8 +34,7 @@ casper.test.begin("Ghost logout works correctly", 2, function suite(test) {
// has to be done after signing out
casper.test.begin("Can't spam signin", 3, function suite(test) {
casper.test.filename = "spam_test.png";
test.filename = "spam_test.png";
casper.start(url + "ghost/signin/", function testTitle() {
test.assertTitle("", "Ghost admin has no title");
@ -70,8 +67,7 @@ casper.test.begin("Can't spam signin", 3, function suite(test) {
});
casper.test.begin("Ghost signup fails properly", 5, function suite(test) {
casper.test.filename = "signup_test.png";
test.filename = "signup_test.png";
casper.start(url + "ghost/signup/", function then() {
test.assertEquals(casper.getCurrentUrl(), url + "ghost/signup/", "Reached signup page");
@ -83,7 +79,6 @@ casper.test.begin("Ghost signup fails properly", 5, function suite(test) {
// should now throw a short password error
casper.waitForResource(/signup/);
casper.waitForSelector('.notification-error', function onSuccess() {
test.assert(true, 'Got error notification');
test.assertSelectorDoesntHaveText('.notification-error', '[object Object]');
@ -97,7 +92,6 @@ casper.test.begin("Ghost signup fails properly", 5, function suite(test) {
// should now throw a 1 user only error
casper.waitForResource(/signup/);
casper.waitForSelector('.notification-error', function onSuccess() {
test.assert(true, 'Got error notification');
test.assertSelectorDoesntHaveText('.notification-error', '[object Object]');