Remove race conditions in casper tests.

Chaining together `wait*` functions can create race conditions in the
frontend tests. To avoid race condition, we need to insert `then`
function between two `wait*` functions.
This commit is contained in:
Umair Khan 2016-09-08 17:10:41 +05:00 committed by Tim Abbott
parent 8fbbb3a471
commit d171e2c8d9
2 changed files with 127 additions and 85 deletions

View File

@ -141,46 +141,58 @@ function un_narrow() {
// Narrow by clicking links.
common.wait_for_receive(function () {
casper.test.info('Narrowing by clicking stream');
casper.click('*[title="Narrow to stream \\\"Verona\\\""]');
casper.then(function () {
common.wait_for_receive(function () {
casper.test.info('Narrowing by clicking stream');
casper.click('*[title="Narrow to stream \\\"Verona\\\""]');
});
});
casper.waitUntilVisible('#zfilt', function () {
expect_stream();
casper.then(function () {
casper.waitUntilVisible('#zfilt', function () {
expect_stream();
});
});
casper.then(check_narrow_title('Verona - Zulip Dev - Zulip'));
un_narrow();
casper.waitUntilVisible('#zhome', function () {
expect_home();
casper.test.info('Narrowing by clicking subject');
casper.click('*[title="Narrow to stream \\\"Verona\\\", topic \\\"frontend test\\\""]');
});
casper.then(check_narrow_title('frontend test - Zulip Dev - Zulip'));
casper.waitUntilVisible('#zfilt', function () {
expect_stream_subject();
// This time, un-narrow by hitting the search 'x'
casper.test.info('Un-narrowing');
casper.click('#search_exit');
casper.then(function () {
casper.waitUntilVisible('#zhome', function () {
expect_home();
casper.test.info('Narrowing by clicking subject');
casper.click('*[title="Narrow to stream \\\"Verona\\\", topic \\\"frontend test\\\""]');
});
});
casper.waitUntilVisible('#zhome', function () {
expect_home();
casper.test.info('Narrowing by clicking personal');
casper.click('*[title="Narrow to your private messages with Cordelia Lear, King Hamlet"]');
casper.then(function () {
check_narrow_title('frontend test - Zulip Dev - Zulip');
casper.waitUntilVisible('#zfilt', function () {
expect_stream_subject();
// This time, un-narrow by hitting the search 'x'
casper.test.info('Un-narrowing');
casper.click('#search_exit');
});
});
casper.then(check_narrow_title('private - Zulip Dev - Zulip'));
casper.then(function () {
casper.waitUntilVisible('#zhome', function () {
expect_home();
casper.test.info('Narrowing by clicking personal');
casper.click('*[title="Narrow to your private messages with Cordelia Lear, King Hamlet"]');
});
});
casper.waitUntilVisible('#zfilt', function () {
expect_huddle();
casper.then(function () {
check_narrow_title('private - Zulip Dev - Zulip');
casper.waitUntilVisible('#zfilt', function () {
expect_huddle();
// Un-narrow by clicking "Zulip"
casper.test.info('Un-narrowing');
casper.click('.brand');
// Un-narrow by clicking "Zulip"
casper.test.info('Un-narrowing');
casper.click('.brand');
});
});
@ -195,27 +207,33 @@ function search_and_check(str, item, check, narrow_title) {
function search_silent_user(str, item) {
common.select_item_via_typeahead('#search_query', str, item);
casper.waitUntilVisible('#silent_user', function () {
casper.test.info("Empty feed for silent user visible.");
var expected_message = "\n You haven't received any messages sent by this user yet!"+
"\n ";
this.test.assertEquals(casper.fetchText('#silent_user'), expected_message);
casper.then(function () {
casper.waitUntilVisible('#silent_user', function () {
casper.test.info("Empty feed for silent user visible.");
var expected_message = "\n You haven't received any messages sent by this user yet!"+
"\n ";
this.test.assertEquals(casper.fetchText('#silent_user'), expected_message);
});
});
un_narrow();
}
function search_non_existing_user(str, item) {
common.select_item_via_typeahead('#search_query', str, item);
casper.waitUntilVisible('#non_existing_user', function () {
casper.test.info("Empty feed for non existing user visible.");
var expected_message = "\n This user does not exist!"+
"\n ";
this.test.assertEquals(casper.fetchText('#non_existing_user'), expected_message);
casper.then(function () {
casper.waitUntilVisible('#non_existing_user', function () {
casper.test.info("Empty feed for non existing user visible.");
var expected_message = "\n This user does not exist!"+
"\n ";
this.test.assertEquals(casper.fetchText('#non_existing_user'), expected_message);
});
});
un_narrow();
}
casper.waitUntilVisible('#zhome', expect_home);
casper.then(function () {
casper.waitUntilVisible('#zhome', expect_home);
});
// Test stream / recipient autocomplete in the search bar
search_and_check('Verona', 'Narrow to stream', expect_stream,

View File

@ -19,60 +19,78 @@ casper.waitForText("And reply to this message", function () {
casper.page.sendEvent('keypress', "c");
});
casper.waitUntilVisible('#compose', function () {
casper.test.assertVisible('#stream', 'Stream input box visible');
common.check_form('#send_message_form', {stream: '', subject: ''}, "Stream empty on new compose");
casper.click('body');
casper.page.sendEvent('keypress', "C");
casper.then(function () {
casper.waitUntilVisible('#compose', function () {
casper.test.assertVisible('#stream', 'Stream input box visible');
common.check_form('#send_message_form', {stream: '', subject: ''}, "Stream empty on new compose");
casper.click('body');
casper.page.sendEvent('keypress', "C");
});
});
casper.waitUntilVisible('#private_message_recipient', function () {
common.check_form('#send_message_form', {recipient: ''}, "Recipient empty on new PM");
casper.click('body');
casper.page.sendEvent('keypress', 'c');
casper.then(function () {
casper.waitUntilVisible('#private_message_recipient', function () {
common.check_form('#send_message_form', {recipient: ''}, "Recipient empty on new PM");
casper.click('body');
casper.page.sendEvent('keypress', 'c');
});
});
casper.waitUntilVisible('#stream', function () {
common.check_form('#send_message_form', {stream: '', subject: ''}, "Stream empty on new compose");
casper.then(function () {
casper.waitUntilVisible('#stream', function () {
common.check_form('#send_message_form', {stream: '', subject: ''}, "Stream empty on new compose");
// Check that when you reply to a message it pre-populates the stream and subject fields
casper.click('body');
// Check that when you reply to a message it pre-populates the stream and subject fields
casper.click('body');
});
});
casper.waitWhileVisible('#stream', function () {
casper.clickLabel("We reply to this message");
casper.then(function () {
casper.waitWhileVisible('#stream', function () {
casper.clickLabel("We reply to this message");
});
});
casper.waitUntilVisible('#stream', function () {
common.check_form('#send_message_form', {stream: "Verona", subject: "Reply test"}, "Stream populated after reply by click");
// Or recipient field
casper.click('body');
casper.clickLabel("And reply to this message");
casper.then(function () {
casper.waitUntilVisible('#stream', function () {
common.check_form('#send_message_form', {stream: "Verona", subject: "Reply test"}, "Stream populated after reply by click");
// Or recipient field
casper.click('body');
casper.clickLabel("And reply to this message");
});
});
casper.waitUntilVisible('#private_message_recipient', function () {
common.check_form('#send_message_form', {recipient: "cordelia@zulip.com"}, "Recipient populated after PM click");
casper.then(function () {
casper.waitUntilVisible('#private_message_recipient', function () {
common.check_form('#send_message_form', {recipient: "cordelia@zulip.com"}, "Recipient populated after PM click");
common.keypress(27); //escape
casper.page.sendEvent('keypress', 'k');
casper.page.sendEvent('keypress', 'r');
common.keypress(27); //escape
casper.page.sendEvent('keypress', 'k');
casper.page.sendEvent('keypress', 'r');
});
});
casper.waitUntilVisible('#stream', function () {
common.check_form('#send_message_form', {stream: "Verona", subject: "Reply test"}, "Stream populated after reply with `r`");
casper.then(function () {
casper.waitUntilVisible('#stream', function () {
common.check_form('#send_message_form', {stream: "Verona", subject: "Reply test"}, "Stream populated after reply with `r`");
// Test "closing" the compose box
casper.click('body');
// Test "closing" the compose box
casper.click('body');
});
});
casper.waitWhileVisible('#stream', function () {
casper.test.assertNotVisible('#stream', 'Close stream compose box');
casper.page.sendEvent('keypress', "C");
casper.click('body');
casper.then(function () {
casper.waitWhileVisible('#stream', function () {
casper.test.assertNotVisible('#stream', 'Close stream compose box');
casper.page.sendEvent('keypress', "C");
casper.click('body');
});
});
casper.waitWhileVisible('#private-message', function () {
casper.test.assertNotVisible('#private-message', 'Close PM compose box');
casper.then(function () {
casper.waitWhileVisible('#private-message', function () {
casper.test.assertNotVisible('#private-message', 'Close PM compose box');
});
});
// Test focus after narrowing to PMs with a user and typing 'c'
@ -82,10 +100,13 @@ casper.then(function () {
casper.waitUntilVisible('#tab_list li.private_message', function () {
casper.page.sendEvent('keypress', 'c');
});
casper.waitUntilVisible('#compose', function () {
casper.test.assertEval(function () {
return document.activeElement === $('#stream')[0];
}, 'Stream box focused after narrowing to PMs with a user and pressing `c`');
casper.then(function () {
casper.waitUntilVisible('#compose', function () {
casper.test.assertEval(function () {
return document.activeElement === $('#stream')[0];
}, 'Stream box focused after narrowing to PMs with a user and pressing `c`');
});
});
// Make sure multiple PM recipients display properly.
@ -107,14 +128,17 @@ casper.then(function () {
casper.waitUntilVisible('#zhome', function () {
casper.clickLabel('A huddle to check spaces');
});
casper.waitUntilVisible('#compose', function () {
// It may be possible to get the textbox contents with CasperJS,
// but it's easier to just evaluate jQuery in page context here.
var displayed_recipients = casper.evaluate(function () {
return $('#private_message_recipient').val();
casper.then(function () {
casper.waitUntilVisible('#compose', function () {
// It may be possible to get the textbox contents with CasperJS,
// but it's easier to just evaluate jQuery in page context here.
var displayed_recipients = casper.evaluate(function () {
return $('#private_message_recipient').val();
});
casper.test.assertEquals(displayed_recipients, recipients.join(', '),
'Recipients are displayed correctly in a huddle reply');
});
casper.test.assertEquals(displayed_recipients, recipients.join(', '),
'Recipients are displayed correctly in a huddle reply');
});
common.then_log_out();