-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.coffee
165 lines (130 loc) · 3.76 KB
/
script.coffee
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
utils = require 'utils'
casper = require('casper').create
verbose: true
logLevel: 'debug'
waitTimeout: 15000
if casper.cli.has(0)
startDate = casper.cli.get(0)
else
startDate = new Date()
startDate = startDate.toLocaleDateString()
USERNAME = ''
PASSWORD = ''
COMPANY_CODE = ''
HOURS_PER_DAY = 7
BACK_LINK = 'img[name="Head_B"]'
FORWARD_LINK = 'img[name="Head_F"]'
VERIFY_LINK = 'img[onclick^="empVerify"]'
DATE_CHANGE_LINK = 'img[name="TCGo"]'
TIME_INT_POPUP_LINK = '.submitsmallstyle'
TIME_SUBMIT_LINK = 'input[name="submit1"]'
LOGIN_WINDOW = '#LoginWindow'
###
This isn't internal grant/job numbers, but the value that timeforce
assgins to the options element of a particular job. Here are some common
ones to use:
CDI: 5757
CI Team: 1122
Zooniverse: 4455
Zooniverse PH: 13766
Zooniverse SETI: 5773
Zooniverse Sloan: 11583
Zooniverse SOCS: 13524
###
JOB = 5757
links = []
currentLink = 0
attempts = 0
getLinks = (startDate) ->
links = document.querySelectorAll '.TCDayNormalBold'
filterLinks = (link) =>
if link.textContent != '0.00'
return false
date = new Date(link.getAttribute('href').split('\'')[1])
startDate = new Date(startDate)
if startDate.getTime() < date.getTime()
return false
if 0 < date.getDay() < 6
return true
else
return false
parseLink = (link) ->
return link.href
(parseLink link for link, i in links when filterLinks link)
parse = ->
utils.dump links
if links is null
if attempts is 1
@echo '# No hours left to fill.', 'COMMENT'
@exit()
else
# For the case where you select a start date that results in no links
# being selected on that page.
@echo '# Retry once.', 'COMMENT'
attempts += 1
@click BACK_LINK
@then parsePage
else
if currentLink < links.length
link = links[currentLink]
link = link.charAt(0).toUpperCase() + link.slice(1) # Sigh
currentLink += 1
@echo '# Clicking link.', 'COMMENT'
@click 'a[href="' + link + '"]'
@wait 500
@waitForPopup /timeHRSelect/, ->
@echo '# Popup exists.', 'COMMENT'
@withPopup /timeHRSelect/, ->
@echo '# Within intermediate popup.', 'COMMENT'
@waitForSelector TIME_INT_POPUP_LINK, ->
@click TIME_INT_POPUP_LINK
@waitForPopup /timeHRChange\.asp/, ->
@echo '# Time input popup exists.', 'COMMENT'
@withPopup /timeHRChange\.asp/, ->
@echo '# Within timecard popup.', 'COMMENT'
@waitForSelector TIME_SUBMIT_LINK, ->
elements =
'thetotalhr': HOURS_PER_DAY
'job': JOB
@fill 'body', elements, false
@click TIME_SUBMIT_LINK
@then parse
else
@echo '# Verifying time is correct.', 'COMMENT'
@test.assertExists VERIFY_LINK, 'Verify link found.'
if @exists VERIFY_LINK
@click VERIFY_LINK
@wait 5000, ->
@then goBack
else
@then goBack
parsePage = ->
@echo '# Parsing new timecard page.', 'COMMENT'
currentLink = 0
links = @evaluate getLinks, startDate
@then parse
goBack = ->
@test.assertExists BACK_LINK, 'Back link found.'
@click BACK_LINK
@then parsePage
casper.start 'https://www.gotimeforce.com', ->
elements =
'username': USERNAME
'Password': PASSWORD
'CompanyCode': COMPANY_CODE
@test.assertExists LOGIN_WINDOW, 'found login form'
@fill LOGIN_WINDOW, elements, false
@click '#Image1'
casper.then ->
@echo '# Filling in hours.', 'COMMENT'
elements =
'datechange': startDate
@fill '.TimeRow1', elements, false
@click DATE_CHANGE_LINK
@on 'popup.loaded', (page) ->
@echo 'Popup loaded.', 'INFO'
utils.dump page.title
@on 'popup.closed', (page) ->
@echo 'Popup closed.', 'INFO'
@then parsePage
casper.run()