This repository was archived by the owner on Oct 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathlogin.js
More file actions
68 lines (56 loc) · 2.18 KB
/
login.js
File metadata and controls
68 lines (56 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* login.js
* Test that a user can authenticate correctly.
*/
casper.test.begin('Test that a user can authenticate correctly.', 6, function suite(test) {
casper.start(url, function() {
test.assertTitle("DoSomething.org | Largest organization for teens and social cause", "Homepage has expected title");
// We reference the login link's ID to avoid a crazy selector.
test.assertExists("#link--login", "Login link exists on page for anonymous user");
});
casper.then(function() {
// Click the login link in the header navigation menu.
this.click("#link--login");
// We should see a modal with the login form.
this.waitUntilVisible("[data-modal]", function() {
test.assertExists("[data-modal] form[action='/user/login']", "Clicking the login link shows modal login form");
});
});
casper.then(function() {
// Fill and submit bogus login credentials:
this.fill('form[action="/user/login"]', {
name: 'test@example.com',
pass: 'zzzzz'
}, true);
// We should get a specific error message.
casper.waitForSelector('.messages', function() {
test.assertSelectorHasText("div.error", "unrecognized username or password", "Error message appears after submitting invalid credentials");
});
});
casper.thenOpen(url, function() {
// Now let's go back home and login using the login modal.
this.waitUntilVisible("#link--login", function() {
this.click("#link--login");
});
// We should see a modal with the login form.
this.waitUntilVisible("[data-modal]", function() {
this.fill('form[action="/user/login"]', {
name: 'QA_TEST_ACCOUNT@example.com',
pass: 'QA_TEST_ACCOUNT'
}, true);
});
this.waitUntilVisible("#link--logout", function() {
test.assertExists("#link--logout", "Logout link is shown for logged in users");
});
});
casper.thenOpen(url, function() {
// Let's log out using the logout button.
this.click("#link--logout");
this.waitUntilVisible("#link--login", function() {
test.assertExists("#link--login", "Login link is shown again after logging out");
});
});
casper.run(function() {
test.done();
});
});