Class: Cxeed::Proxy
- Inherits:
-
Object
- Object
- Cxeed::Proxy
- Defined in:
- lib/cxeed/proxy.rb
Instance Method Summary collapse
- #arrive(time = Time.now.strftime('%H:%M')) ⇒ Object
- #day_attendance(day) ⇒ Object
-
#initialize(credential) ⇒ Proxy
constructor
A new instance of Proxy.
- #leave(time = Time.now.strftime('%H:%M')) ⇒ Object
- #login ⇒ Object
- #login_test ⇒ Object
- #navigate_to_input_form ⇒ Object
- #today ⇒ Object
Constructor Details
#initialize(credential) ⇒ Proxy
Returns a new instance of Proxy.
6 7 8 9 10 11 |
# File 'lib/cxeed/proxy.rb', line 6 def initialize(credential) caps = Selenium::WebDriver::Remote::Capabilities.chrome('chromeOptions': {args: i(--headless --disable-gpu window-size=1920,1080)}) @driver = Selenium::WebDriver.for :chrome, desired_capabilities: caps @credential = credential end |
Instance Method Details
#arrive(time = Time.now.strftime('%H:%M')) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cxeed/proxy.rb', line 44 def arrive(time = Time.now.strftime('%H:%M')) login navigate_to_input_form # 出勤時間の入力 work_field = @driver.find_element(:xpath, '//td[@id="grdXyw1100G-rc-0-6"]') @driver.action.send_keys(work_field, time).perform # 登録処理 @driver.find_element(:xpath, '//input[@name="regbutton"]').click end |
#day_attendance(day) ⇒ Object
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 |
# File 'lib/cxeed/proxy.rb', line 84 def day_attendance(day) login navigate_to_input_form # 日付の整形 day_str = DateTime.parse(day).strftime('%Y%m%d') backspace = "\ue003" # 処理期間の入力 @driver.find_element(:xpath, '//input[@name="StartYMD"]').send_keys(backspace * 8) @driver.find_element(:xpath, '//input[@name="StartYMD"]').send_keys(day_str) @driver.find_element(:xpath, '//input[@name="EndYMD"]').send_keys(backspace * 8) @driver.find_element(:xpath, '//input[@name="EndYMD"]').send_keys(day_str) # 検索 @driver.find_element(:xpath, '//input[@name="srchbutton"]').click date = @driver.find_element(:xpath, '//td[@id="grdXyw1100G-rc-0-0"]/nobr').text arrive_at = @driver.find_element(:xpath, '//td[@id="grdXyw1100G-rc-0-6"]/nobr').text leave_at = @driver.find_element(:xpath, '//td[@id="grdXyw1100G-rc-0-9"]/nobr').text Cxeed::Attendance.new date, arrive_at, leave_at end |
#leave(time = Time.now.strftime('%H:%M')) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cxeed/proxy.rb', line 57 def leave(time = Time.now.strftime('%H:%M')) login navigate_to_input_form # 退勤時間の入力 work_field = @driver.find_element(:xpath, '//td[@id="grdXyw1100G-rc-0-9"]') @driver.action.send_keys(work_field, time).perform # 登録処理 @driver.find_element(:xpath, '//input[@name="regbutton"]').click end |
#login ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cxeed/proxy.rb', line 13 def login @driver.navigate.to(@credential.login_url) # 会社コード入力 @driver.find_element(:name, 'DataSource').send_keys(@credential.company_code) # 個人コード入力 @driver.find_element(:name, 'LoginID').send_keys(@credential.employee_code) # パスワード入力 @driver.find_element(:name, 'PassWord').send_keys(@credential.password) # ログイン処理 @driver.find_element(:xpath, '//td[@class="loginBtn"]/a').click end |
#login_test ⇒ Object
26 27 28 29 30 |
# File 'lib/cxeed/proxy.rb', line 26 def login_test login @driver.current_url end |
#navigate_to_input_form ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cxeed/proxy.rb', line 32 def navigate_to_input_form # frameの指定 @driver.switch_to.frame @driver.find_element(id: 'FRAME1') # 勤務データ入力遷移 @driver.find_element(:xpath, '//a[@title="勤務データ入力"]').click # 一旦main documentに戻る @driver.switch_to.default_content # frameの指定 @driver.switch_to.frame @driver.find_element(name: 'FRAME2') end |
#today ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cxeed/proxy.rb', line 70 def today login navigate_to_input_form date = @driver.find_element(:xpath, '//td[@id="grdXyw1100G-rc-0-0"]/nobr').text arrive_at = @driver.find_element(:xpath, '//td[@id="grdXyw1100G-rc-0-6"]/nobr').text leave_at = @driver.find_element(:xpath, '//td[@id="grdXyw1100G-rc-0-9"]/nobr').text today = Cxeed::Attendance.new date, arrive_at, leave_at today end |