mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
casper: Improve common.js.
These changes prepare us for the casperjs upgrade:
Extract init_viewport().
Have then_log_out() do more explicit waiting.
Add turn_off_press_enter_to_send().
This commit is contained in:
@@ -24,6 +24,11 @@ function log_in(credentials) {
|
|||||||
}, true /* submit form */);
|
}, true /* submit form */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
exports.init_viewport = function () {
|
||||||
|
casper.options.viewportSize = {width: 1280, height: 1024};
|
||||||
|
};
|
||||||
|
|
||||||
exports.initialize_casper = function (viewport) {
|
exports.initialize_casper = function (viewport) {
|
||||||
if (casper.zulip_initialized !== undefined) {
|
if (casper.zulip_initialized !== undefined) {
|
||||||
return;
|
return;
|
||||||
@@ -32,9 +37,6 @@ exports.initialize_casper = function (viewport) {
|
|||||||
// These initialization steps will fail if they run before
|
// These initialization steps will fail if they run before
|
||||||
// casper.start has been called.
|
// casper.start has been called.
|
||||||
|
|
||||||
// Set default viewport size to something reasonable
|
|
||||||
casper.page.viewportSize = viewport || {width: 1280, height: 1024};
|
|
||||||
|
|
||||||
// Fail if we get a JavaScript error in the page's context.
|
// Fail if we get a JavaScript error in the page's context.
|
||||||
// Based on the example at http://phantomjs.org/release-1.5.html
|
// Based on the example at http://phantomjs.org/release-1.5.html
|
||||||
//
|
//
|
||||||
@@ -90,6 +92,7 @@ exports.start_and_log_in = function (credentials, viewport) {
|
|||||||
} else {
|
} else {
|
||||||
log_in_url = "http://localhost:9981/accounts/login";
|
log_in_url = "http://localhost:9981/accounts/login";
|
||||||
}
|
}
|
||||||
|
exports.init_viewport();
|
||||||
casper.start(log_in_url, function () {
|
casper.start(log_in_url, function () {
|
||||||
exports.initialize_casper(viewport);
|
exports.initialize_casper(viewport);
|
||||||
log_in(credentials);
|
log_in(credentials);
|
||||||
@@ -97,11 +100,22 @@ exports.start_and_log_in = function (credentials, viewport) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.then_log_out = function () {
|
exports.then_log_out = function () {
|
||||||
casper.then(function () {
|
var menu_selector = '#settings-dropdown';
|
||||||
casper.test.info('Logging out');
|
var logout_selector = 'li[title="Log out"] a';
|
||||||
casper.click('li[title="Log out"] a');
|
|
||||||
});
|
|
||||||
|
|
||||||
|
casper.waitUntilVisible(menu_selector, function () {
|
||||||
|
casper.click(menu_selector);
|
||||||
|
|
||||||
|
casper.waitUntilVisible(logout_selector, function () {
|
||||||
|
casper.test.info('Logging out');
|
||||||
|
casper.click(logout_selector);
|
||||||
|
|
||||||
|
casper.then(function () {
|
||||||
|
casper.test.assertUrlMatch(/accounts\/login\/$/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
casper.waitForSelector(".login-page-header", function () {
|
casper.waitForSelector(".login-page-header", function () {
|
||||||
casper.test.info("Logged out");
|
casper.test.info("Logged out");
|
||||||
});
|
});
|
||||||
@@ -166,6 +180,19 @@ exports.wait_for_message_actually_sent = function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.turn_off_press_enter_to_send = function () {
|
||||||
|
var enter_send_selector = '#enter_sends';
|
||||||
|
casper.waitForSelector(enter_send_selector);
|
||||||
|
|
||||||
|
var is_checked = casper.evaluate(function (enter_send_selector) {
|
||||||
|
return document.querySelector(enter_send_selector).checked;
|
||||||
|
}, enter_send_selector);
|
||||||
|
|
||||||
|
if (is_checked) {
|
||||||
|
casper.click(enter_send_selector);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Wait for any previous send to finish, then send a message.
|
// Wait for any previous send to finish, then send a message.
|
||||||
exports.then_send_message = function (type, params) {
|
exports.then_send_message = function (type, params) {
|
||||||
casper.then(function () {
|
casper.then(function () {
|
||||||
@@ -182,7 +209,12 @@ exports.then_send_message = function (type, params) {
|
|||||||
casper.test.assertTrue(false, "send_message got valid message type");
|
casper.test.assertTrue(false, "send_message got valid message type");
|
||||||
}
|
}
|
||||||
casper.fill('form[action^="/json/messages"]', params);
|
casper.fill('form[action^="/json/messages"]', params);
|
||||||
casper.click('#compose-send-button');
|
|
||||||
|
exports.turn_off_press_enter_to_send();
|
||||||
|
|
||||||
|
casper.then(function () {
|
||||||
|
casper.click('#compose-send-button');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
casper.then(function () {
|
casper.then(function () {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ if (REALMS_HAVE_SUBDOMAINS) {
|
|||||||
realm_url = "http://localhost:9981/";
|
realm_url = "http://localhost:9981/";
|
||||||
}
|
}
|
||||||
// Start of test script.
|
// Start of test script.
|
||||||
|
common.init_viewport();
|
||||||
casper.start(realm_url, common.initialize_casper);
|
casper.start(realm_url, common.initialize_casper);
|
||||||
|
|
||||||
casper.then(function () {
|
casper.then(function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user