mirror of https://github.com/zulip/zulip.git
tests: Move log int and log out functions into a common.js
(imported from commit d6c2f45af775dea9c99426aa46b08ed45eb76d17)
This commit is contained in:
parent
d5493ed580
commit
e588323f5d
|
@ -0,0 +1,47 @@
|
||||||
|
var common = (function () {
|
||||||
|
|
||||||
|
var exports = {};
|
||||||
|
|
||||||
|
exports.log_in = function () {
|
||||||
|
casper.start('http://localhost:9981/accounts/login', function () {
|
||||||
|
// Fail if we get a JavaScript error in the page's context.
|
||||||
|
// Based on the example at http://phantomjs.org/release-1.5.html
|
||||||
|
//
|
||||||
|
// casper.on('error') doesn't work (it never gets called) so we
|
||||||
|
// set this at the PhantomJS level. We do it inside 'start' so
|
||||||
|
// that we know we have a page object.
|
||||||
|
casper.page.onError = function (msg, trace) {
|
||||||
|
casper.test.error(msg);
|
||||||
|
casper.echo('Traceback:');
|
||||||
|
trace.forEach(function (item) {
|
||||||
|
casper.echo(' ' + item.file + ':' + item.line);
|
||||||
|
});
|
||||||
|
casper.exit(1);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
casper.then(function () {
|
||||||
|
casper.test.info('Logging in');
|
||||||
|
casper.fill('form[action^="/accounts/login"]', {
|
||||||
|
username: 'iago@humbughq.com',
|
||||||
|
password: 'FlokrWdZefyEWkfI'
|
||||||
|
}, true /* submit form */);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.log_out = function () {
|
||||||
|
casper.then(function () {
|
||||||
|
casper.test.info('Logging out');
|
||||||
|
casper.click('li[title="Log out"] a');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return exports;
|
||||||
|
|
||||||
|
}());
|
||||||
|
|
||||||
|
// For inclusion with CasperJS
|
||||||
|
try {
|
||||||
|
exports.common = common;
|
||||||
|
} catch (e) {
|
||||||
|
}
|
|
@ -29,6 +29,16 @@ casper.then(function () {
|
||||||
}, true /* submit form */);
|
}, true /* submit form */);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
casper.then(function () {
|
||||||
|
casper.test.info('Logging out');
|
||||||
|
casper.click('li[title="Log out"] a');
|
||||||
|
});
|
||||||
|
|
||||||
|
casper.then(function () {
|
||||||
|
casper.test.assertHttpStatus(200);
|
||||||
|
casper.test.assertUrlMatch(/accounts\/login\/$/);
|
||||||
|
});
|
||||||
|
|
||||||
// Run the above queued actions.
|
// Run the above queued actions.
|
||||||
casper.run(function () {
|
casper.run(function () {
|
||||||
casper.test.done();
|
casper.test.done();
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
// For example, utils.dump() prints an Object with nice formatting.
|
// For example, utils.dump() prints an Object with nice formatting.
|
||||||
var utils = require('utils');
|
var utils = require('utils');
|
||||||
|
|
||||||
|
var common = require('../common.js').common;
|
||||||
|
|
||||||
// Uncomment this to get page-context console.log in the CasperJS output
|
// Uncomment this to get page-context console.log in the CasperJS output
|
||||||
// (plus some CasperJS-specific messages)
|
// (plus some CasperJS-specific messages)
|
||||||
/*
|
/*
|
||||||
|
@ -119,10 +121,7 @@ function un_narrow() {
|
||||||
keypress(27); // Esc
|
keypress(27); // Esc
|
||||||
}
|
}
|
||||||
|
|
||||||
casper.start('http://localhost:9981/', function () {
|
common.log_in();
|
||||||
// URL like http://localhost:9981/ or http://localhost:9981/#
|
|
||||||
casper.test.assertUrlMatch(/^http:\/\/[^\/]+\/#?$/, 'On home page');
|
|
||||||
});
|
|
||||||
|
|
||||||
casper.then(function () {
|
casper.then(function () {
|
||||||
casper.test.info('Sanity-checking existing messages');
|
casper.test.info('Sanity-checking existing messages');
|
||||||
|
@ -322,6 +321,8 @@ casper.then(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
common.log_out();
|
||||||
|
|
||||||
// Run the above queued actions.
|
// Run the above queued actions.
|
||||||
casper.run(function () {
|
casper.run(function () {
|
||||||
casper.test.done();
|
casper.test.done();
|
||||||
|
|
Loading…
Reference in New Issue