-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
85 lines (75 loc) · 2.65 KB
/
index.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
var selenium = require('./selenium.js');
var logName = "webdriverio";
var fb_email = process.env.FB_EMAIL;
var fb_pass = process.env.FB_PASS;
var wishes = [
'Happy Birthday !!',
'Happy Birthday! Have a blast.',
'Many more happy returns of the day',
'I wish you all the happiness in the world! Happy Birthday.',
'Just live it out to the fullest and have fun! Happy Birthday',
'I hope you have the best day ever. Happy Birthday!',
'Happy Birthday!! May all of your birthday wishes come true.',
'Happy Birthday! Welcome to the new age.'
];
var getRandomWish = function() {
var min = 0;
var max = wishes.length;
var index = Math.floor(Math.random() * (max - min) + min);
return wishes[index];
};
selenium.start();
selenium.eventEmitter.on('start', function() {
console.log('[' + logName + '] start event received.');
if (fb_email === "" || fb_email === undefined) {
console.log('[' + logName + '] fb_email env variable not set.');
selenium.exit();
return;
}
if (fb_pass === "" || fb_pass === undefined) {
console.log('[' + logName + '] fb_pass env variable not set.');
selenium.exit();
return;
}
startWebdriverio();
});
function startWebdriverio() {
var webdriverio = require('webdriverio'),
client = webdriverio.remote({
desiredCapabilities: {
browserName: 'phantomjs',
'phantomjs.binary.path': require('phantomjs').path,
},
logLevel: 'silent',
}).init();
client
.url('https://www.facebook.com')
.setValue('#email', fb_email)
.setValue('#pass', fb_pass)
.click('#loginbutton')
.pause(300)
.isExisting('span*=birthday').then(function(isExisting) {
if(isExisting) {
return this.element('span*=birthday').click('.fbRemindersTitle')
.pause(500)
.waitForExist('[name="message_text"]', 1000).then(function() {
return this.setValue('[name="message_text"]', getRandomWish());
}).keys('Enter')
.pause(200);
} else {
console.log('[' + logName + '] Looks like there are no birthdays today.');
return this.pause(100);
}
}).then(function() {
return this.catch(function(e) {
console.log('[' + logName + ' error] ' + e.message);
});
}).then(function() {
this.end().then(function() {
selenium.exit();
});
}).catch(function(err) {
console.log(err);
selenium.exit();
});
}