Remove race condition while sending messages in casper.

Fixes: #1455
This commit is contained in:
Umair Khan 2016-09-30 16:08:39 +05:00
parent 406191cbe8
commit de905457ac
2 changed files with 19 additions and 7 deletions

View File

@ -156,8 +156,12 @@ exports.check_form = function (form_selector, expected, test_name) {
// Wait for any previous send to finish, then send a message.
exports.then_send_message = function (type, params) {
casper.waitForSelector('#compose-send-button:enabled');
casper.waitForSelector('#new_message_content', function () {
casper.then(function () {
casper.waitForSelector('#compose-send-button:enabled');
casper.waitForSelector('#new_message_content');
});
casper.then(function () {
if (type === "stream") {
casper.page.sendEvent('keypress', "c");
} else if (type === "private") {
@ -168,9 +172,14 @@ exports.then_send_message = function (type, params) {
casper.fill('form[action^="/json/messages"]', params);
casper.click('#compose-send-button');
});
casper.waitFor(function emptyComposeBox() {
return casper.getFormValues('form[action^="/json/messages"]').content === '';
}, function () {
casper.then(function () {
casper.waitFor(function emptyComposeBox() {
return casper.getFormValues('form[action^="/json/messages"]').content === '';
});
});
casper.then(function () {
last_send_or_update = timestamp();
});
};

View File

@ -241,8 +241,11 @@ common.then_send_message('stream', {
subject: 'edits',
content: 'test editing 2'
});
casper.waitForText("test editing 1");
casper.waitForText("test editing 2");
casper.then(function () {
casper.waitForText("test editing 1");
casper.waitForText("test editing 2");
});
// wait for message to be sent
casper.waitFor(function () {