-
Notifications
You must be signed in to change notification settings - Fork 1
/
new_user_secondary.js
executable file
·227 lines (212 loc) · 6.4 KB
/
new_user_secondary.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env node
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const
vows = require('vows'),
path = require('path'),
wd = require('wd'),
assert = require('assert'),
restmail = require('./lib/restmail.js'),
utils = require('./lib/utils.js');
// setup
var suite = vows.describe(path.relative("..", __dirname));
suite.options.error = false;
browser = wd.remote();
const URLS = {
"123done": 'http://dev.123done.org',
persona: 'https://login.dev.anosrep.org',
myfavoritebeer: 'https://login.dev.anosrep.org',
eyedeeme: 'https://eyedee.me',
};
suite.addBatch({
"starting a session": {
topic: function() {
browser.init(this.callback);
},
"succeeds": function(err) {
assert.isNull(err);
},
"setting implicit timeout": {
topic: function() {
browser.setImplicitWaitTimeout(20000, this.callback);
},
"works also": function(err) {
assert.isUndefined(err);
}
}
}
});
suite.addBatch({
"loading sample rp": {
topic: function() {
browser.get(URLS["123done"], this.callback);
},
"succeeds": function(err, foo) {
assert.isUndefined(err);
}
}
});
const theEmail = restmail.randomEmail(10);
suite.addBatch({
"finding button": {
topic: function() {
browser.elementByCss('li#loggedout button img', this.callback);
},
"visibility": {
topic: function(err, element) {
var self = this;
utils.waitFor(100, 3000, function(done) {
browser.displayed(element, function(err, displayed) {
done(!err && displayed, err, displayed);
});
}, function (err, displayed) {
self.callback(err, element, displayed);
});
},
"occurs": function(err, element, displayed) {
assert.isNull(err);
assert.isTrue(displayed);
},
"and clicking": {
topic: function(err, element) {
browser.clickElement(element, this.callback);
},
"succeeds": function(err) { assert.isUndefined(err); },
"and selecting the dialog window": {
topic: function() {
browser.window("__persona_dialog", this.callback);
},
"succeeds": function(err) { assert.isUndefined(err); },
"and the title": {
topic: function() {
browser.title(this.callback)
},
"is from the dialog": function(err, title) {
assert.isNull(err);
assert.equal(title, 'Mozilla Persona: A Better Way to Sign In');
}
}
}
}
}
}
});
suite.addBatch({
"wait for input text box": {
topic: function() {
browser.elementByCss('input#email', this.callback);
},
"succeeds": function(err) {
assert.isNull(err);
},
"and typing an email address": {
topic: function(err, elem) {
browser.type(elem, theEmail, this.callback);
},
"succeeds": function(err, elem) { assert.isUndefined(err); },
"and finding the next button": {
topic: function() {
browser.elementByCss('p.submit.buttonrow button.start', this.callback);
},
"succeeds": function(err) { assert.isNull(err); },
"and clicking it": {
topic: function(err, elem) {
browser.clickElement(elem, this.callback);
},
"succeeds": function(err) { assert.isUndefined(err); }
}
}
}
}
});
suite.addBatch({
"finding password input": {
topic: function() {
browser.elementByCss('div#set_password input#password', this.callback);
},
"succeeds": function(err) { assert.isNull(err); },
"and typing password": {
topic: function(err, elem) {
browser.type(elem, theEmail.split('@')[0], this.callback);
},
"succeeds": function(err) { assert.isUndefined(err); },
"and finding the verify password input": {
topic: function() {
browser.elementByCss('input#vpassword', this.callback);
},
"succeeds": function(err) { assert.isNull(err); },
"and retyping password": {
topic: function(err, elem) {
browser.type(elem, theEmail.split('@')[0], this.callback);
},
"succeeds": function(err) { assert.isUndefined(err); },
"and finding the next button": {
topic: function() {
browser.elementByCss('button#verify_user', this.callback);
},
"succeeds": function(err) { assert.isNull(err); },
"and clicking it": {
topic: function(err, elem) {
browser.clickElement(elem, this.callback);
},
"succeeds": function(err) { assert.isUndefined(err); }
}
}
}
}
}
}
});
suite.addBatch({
"checking email": {
topic: function() {
restmail.getVerificationLink({ email: theEmail }, this.callback);
},
"finds email": function(err, link, email) {
assert.isNull(err);
assert.ok(link);
},
"and opening verification page": {
topic: function(err, link, email) {
var self = this;
browser.close(function() {
browser.windowHandles(function(err, data) {
assert.ok(!err);
assert.equal(data.length, 1);
browser.window(data[0], function(err) {
browser.get(link, self.callback);
});
});
});
},
"causes redirect to 123done": {
topic: function() {
utils.waitFor(700, 20000, function(done) {
browser.elementByCss('li#loggedin span', function(err, elem) {
if (err) return done(false, err, elem);
browser.text(elem, function(err, text) {
done(!err && typeof text === 'string' && text.length, err, text);
});
});
}, this.callback);
},
"and proper email address is logged in": function(err, text) {
assert.isNull(err);
assert.strictEqual(text, theEmail);
}
}
}
}
});
suite.addBatch({
"ending a session": {
topic: function() {
browser.quit(this.callback);
},
"succeeds": function(err) { assert.isUndefined(err); }
}
});
// run or export the suite.
if (process.argv[1] === __filename) suite.run();
else suite.export(module);