-
Notifications
You must be signed in to change notification settings - Fork 0
/
eat_it_timeforce.rb
executable file
·68 lines (58 loc) · 1.94 KB
/
eat_it_timeforce.rb
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
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'pry'
Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'https://www.gotimeforce.com'
include Capybara::DSL
def append_jquery
page.execute_script <<-JAVASCRIPT
var jQ = document.createElement('script');
jQ.language = 'JavaScript';
jQ.type = 'text/javascript';
jQ.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js';
document.getElementsByTagName('body')[0].appendChild(jQ);
JAVASCRIPT
end
def mark_links
page.execute_script <<-JAVASCRIPT
$(function() {
$('.TCActiveDayCell').parent().children('th').each(function(index, elem) {
if($(elem).text() != 'S') {
var clickable = $( $('a.TCDayNormalBold, a.TCDayNormalBoldModified')[index] );
if(!clickable.hasClass('a.TCDayNormalBoldModified') && clickable.text() == '0.00') {
clickable.addClass('weekday-hours-link');
}
}
});
});
JAVASCRIPT
end
def eat_it_timeforce(username, password, funding_source)
department = 'Adler Planetarium'
visit '/qqest/login/login.asp'
fill_in 'username', :with => username
fill_in 'Password', :with => password
fill_in 'CompanyCode', :with => 'adler'
click_on 'Login'
while true do
append_jquery
mark_links
weekday = page.find('.weekday-hours-link') rescue nil
break unless weekday
weekday.click
within_window(page.driver.browser.window_handles.last) do
add_hours = page.find('.headerRow td:nth-child(1) .submitsmallstyle')
add_hours.click
fill_in 'thetotalhr', :with => '7'
select department, :from => 'department'
select funding_source, :from => 'job'
submit_button = page.find('.headerRow input')
submit_button.click
close_box = page.find('.headerRow td:nth-child(3) .submitsmallstyle')
close_box.click
end
end
end
eat_it_timeforce ARGV[0], ARGV[1], ARGV[2]