-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-cookie-and-starturl.js
42 lines (39 loc) · 1.21 KB
/
get-cookie-and-starturl.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
/* jshint node: true */
var tucanLogin = require('./tucan-login.js');
var data = {
startUrl: undefined,
cookie: undefined
};
module.exports = function getCookieAndStartUrl(username, password, baseUrl, selectors) {
return tucanLogin
.login(username, password, baseUrl, selectors)
.tap(log('Retreiving cookie and startUrl'))
.click(selectors.Veranstaltungen)
.waitForSelector(selectors.Anmeldung)
.click(selectors.Anmeldung)
.waitForSelector(selectors.HeadlineAnmeldung)
.tap(log('Getting startUrl'))
.url()
.then(function(url) {
data.startUrl = url;
})
.tap(log('Getting cookie'))
.cookies()
.spread(function(cookie) {
data.cookie = cookie.name + '=' + cookie.value;
})
.close()
.then(function() {
return [data.startUrl, data.cookie];
})
.catch(function(err) {
console.error('There was an error retrieving cookie/starturl, please check your credentials (see README)', err);
throw err;
});
};
function log() {
var args = arguments;
return function() {
console.log.apply(console, args);
};
}