This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #397 from aldryn/feature/migrate-integration-tests
Migrate integration tests
- Loading branch information
Showing
14 changed files
with
231 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"node": true, | ||
"predef": [ | ||
"casper" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
// ############################################################################# | ||
// CasperJS options | ||
|
||
module.exports = { | ||
init: function () { | ||
this.viewportSize(); | ||
this.timeout(20000); | ||
}, | ||
|
||
viewportSize: function (width, height) { | ||
var viewportWidth = width || 1280; | ||
var viewportHeight = height || 1024; | ||
|
||
casper.echo('Current viewport size is ' + viewportWidth + 'x' + viewportHeight + '.', 'INFO'); | ||
|
||
casper.options.viewportSize = { | ||
width: viewportWidth, | ||
height: viewportHeight | ||
}; | ||
}, | ||
|
||
timeout: function (timeout) { | ||
casper.options.waitTimeout = timeout || 10000; | ||
} | ||
}; |
12 changes: 12 additions & 0 deletions
12
aldryn_newsblog/tests/frontend/integration/handlers/externalMissing.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
// ############################################################################# | ||
// Handles external resources load failures | ||
|
||
module.exports = { | ||
bind: function () { | ||
casper.on('resource.error', function (resource) { | ||
casper.echo('Resource failed to load: ' + resource.url, 'ERROR'); | ||
}); | ||
} | ||
}; |
12 changes: 12 additions & 0 deletions
12
aldryn_newsblog/tests/frontend/integration/handlers/loadFailures.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
// ############################################################################# | ||
// Handles load failure errors | ||
|
||
module.exports = { | ||
bind: function () { | ||
casper.on('load.failed', function (error) { | ||
casper.echo(JSON.stringify(error), 'ERROR'); | ||
}); | ||
} | ||
}; |
16 changes: 16 additions & 0 deletions
16
aldryn_newsblog/tests/frontend/integration/handlers/missingPages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
// ############################################################################# | ||
// Handles 404 and 500 pages | ||
|
||
module.exports = { | ||
bind: function () { | ||
casper.on('http.status.404', function (resource) { | ||
casper.echo('404 page found: ' + resource.url, 'ERROR'); | ||
}); | ||
|
||
casper.on('http.status.500', function (resource) { | ||
casper.echo('500 page found: ' + resource.url, 'ERROR'); | ||
}); | ||
} | ||
}; |
12 changes: 12 additions & 0 deletions
12
aldryn_newsblog/tests/frontend/integration/handlers/pageErrors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
// ############################################################################# | ||
// Handles JavaScript page errors | ||
|
||
module.exports = { | ||
bind: function () { | ||
casper.on('page.error', function (msg) { | ||
casper.echo('Error on page: ' + JSON.stringify(msg), 'ERROR'); | ||
}); | ||
} | ||
}; |
22 changes: 22 additions & 0 deletions
22
aldryn_newsblog/tests/frontend/integration/handlers/suiteFailures.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
// ############################################################################# | ||
// Handles test suite errors (assert and waitFor) | ||
|
||
module.exports = { | ||
bind: function () { | ||
casper.on('step.error', function (error) { | ||
casper.die('assert failed: ' + error.message); | ||
}); | ||
|
||
casper.on('waitFor.timeout', function (timeout, error) { | ||
if (error.selector) { | ||
casper.die('waitFor failed, couldn\'t find ' + error.selector + ' within ' + timeout + 'ms'); | ||
} else if (error.visible) { | ||
casper.die('waitFor failed, couldn\'t find ' + error.visible + ' within ' + timeout + 'ms'); | ||
} else { | ||
casper.die('waitFor failed with error', JSON.stringify(error, null, 4)); | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* globals localStorage, casper */ | ||
'use strict'; | ||
|
||
// ############################################################################# | ||
// User login via the admin panel | ||
|
||
var helpers = require('djangocms-casper-helpers'); | ||
var globals = helpers.settings; | ||
var cms = helpers(); | ||
|
||
casper.test.tearDown(function (done) { | ||
casper.start() | ||
.then(cms.logout()) | ||
.run(done); | ||
}); | ||
|
||
casper.test.begin('User Login (via Admin Panel)', function (test) { | ||
casper | ||
.start(globals.adminUrl, function () { | ||
// we explicitly kill the session id cookie to reset the login state | ||
// and localstorage data to reset the ui state (sideframe, toolbar, etc) | ||
this.page.deleteCookie('sessionid'); | ||
this.evaluate(function () { | ||
localStorage.clear(); | ||
}); | ||
|
||
this.echo('The currently set cookies are: ' + JSON.stringify(this.page.cookies), 'INFO'); | ||
}) | ||
.then(function () { | ||
var titleRegExp = new RegExp(globals.adminTitle, 'g'); | ||
|
||
test.assertTitleMatch(titleRegExp, 'The CMS is available and admin panel title is correct'); | ||
test.assertExists('#login-form', 'Admin login form is available'); | ||
|
||
this.fill('#login-form', { | ||
username: 'fake', | ||
password: 'credentials' | ||
}, true); | ||
}) | ||
.waitForSelector('.errornote', function () { | ||
test.assertExists('.errornote', 'login with wrong credentials failed'); | ||
|
||
this.fill('#login-form', globals.credentials, true); | ||
}) | ||
.waitForResource(/login/) | ||
.thenOpen(globals.baseUrl, function () { | ||
test.assertExists('.cms-toolbar', 'Login via the admin form done'); | ||
}) | ||
.run(function () { | ||
test.done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ############################################################################# | ||
// Init all settings and event handlers on suite start | ||
'use strict'; | ||
|
||
require('./../casperjs.conf').init(); | ||
|
||
require('./handlers/pageErrors').bind(); | ||
require('./handlers/loadFailures').bind(); | ||
require('./handlers/missingPages').bind(); | ||
require('./handlers/externalMissing').bind(); | ||
require('./handlers/suiteFailures').bind(); | ||
|
||
casper.test.done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.