lib/kobot/engine.rb in kobot-1.2.4 vs lib/kobot/engine.rb in kobot-1.2.5
- old
+ new
@@ -95,47 +95,57 @@
def login
Kobot.logger.info("Navigate to: #{@top_url}")
@browser.get @top_url
@wait.until { @browser.find_element(id: 'modal_window') }
+ modal_title_element = @wait.until { @browser.find_element(css: '.modal-title') }
+ @selector = if modal_title_element.text.downcase.include? 'password'
+ Selector.en
+ else
+ Selector.ja
+ end
Kobot.logger.info "Page title: #{@browser.title}"
Kobot.logger.debug do
"Login with id=#{Credential.kot_id} and password=#{Credential.kot_password}"
end
@browser.find_element(id: 'id').send_keys Credential.kot_id
@browser.find_element(id: 'password').send_keys Credential.kot_password
@browser.find_element(css: 'div.btn-control-message').click
Kobot.logger.info 'Login successful'
- @wait.until { @browser.find_element(id: 'notification_content').text.include?('データを取得しました') }
+ @wait.until do
+ @browser.find_element(id: 'notification_content').text.include?(@selector.login_success_notification_text)
+ end
if Config.browser_geolocation
begin
- @wait.until { @browser.find_element(id: 'location_area').text.include?('位置情報取得済み') }
+ @wait.until do
+ @browser.find_element(id: 'location_area').text.include?(@selector.location_area_notification_text)
+ end
rescue StandardError => e
Kobot.logger.warn "Get geolocation failed: #{e.message}"
end
end
Kobot.logger.info "Page title: #{@browser.title}"
end
def logout
if @browser.current_url.include? 'admin'
- Kobot.logger.info('Logout from タイムカード page')
+ Kobot.logger.info('Logout from Time Card (タイムカード) page')
@browser.find_element(css: 'div.htBlock-header_logoutButton').click
else
- Kobot.logger.info('Logout from Myレコーダー page')
+ Kobot.logger.info('Logout from My Recorder (Myレコーダー) page')
@wait.until { @browser.find_element(id: 'menu_icon') }.click
- @wait.until { @browser.find_element(link: 'ログアウト') }.click
+ @wait.until { @browser.find_element(link: @selector.logout_menu_link_text) }.click
@browser.switch_to.alert.accept
end
Kobot.logger.info 'Logout successful'
end
def read_today_record
- Kobot.logger.info('Navigate to タイムカード page')
+ Kobot.logger.info('Navigate to Time Card (タイムカード) page')
@wait.until { @browser.find_element(id: 'menu_icon') }.click
- @wait.until { @browser.find_element(link: 'タイムカード') }.click
+ @wait.until { @browser.find_element(link: @selector.time_card_menu_link_text) }.click
time_table = @wait.until { @browser.find_element(css: 'div.htBlock-adjastableTableF_inner > table') }
time_table.find_elements(css: 'tbody > tr').each do |tr|
date_cell = tr.find_element(css: 'td.htBlock-scrollTable_day')
next unless date_cell.text.include? @today
@@ -224,25 +234,25 @@
def click_clock_in_button
Kobot.logger.info("Navigate to: #{@top_url}")
@browser.get @top_url
clock_in_button = @wait.until { @browser.find_element(css: 'div.record-clock-in') }
if Config.dryrun
- Kobot.logger.info('[Dryrun] clock in button (出勤) would have been clicked')
+ Kobot.logger.info('[Dryrun] Clock-in button (出勤) would have been clicked')
else
- Kobot.logger.info('Clicking the clock in button (出勤)')
+ Kobot.logger.info('Clicking the Clock-in button (出勤)')
clock_in_button.click
end
end
def click_clock_out_button
Kobot.logger.info("Navigate to: #{@top_url}")
@browser.get @top_url
clock_out_button = @wait.until { @browser.find_element(css: 'div.record-clock-out') }
if Config.dryrun
- Kobot.logger.info('[Dryrun] clock out button (退勤) would have been clicked')
+ Kobot.logger.info('[Dryrun] Clock-out button (退勤) would have been clicked')
else
- Kobot.logger.info('Clicking the clock in button (退勤)')
+ Kobot.logger.info('Clicking the Clock-out button (退勤)')
clock_out_button.click
end
end
def weekend?
@@ -255,21 +265,24 @@
Config.skip.include? @now.strftime('%F')
end
def kot_weekend?
- %w[土 日].any? { |kanji| @kot_today&.include? kanji }
+ [
+ @selector.kot_date_saturday,
+ @selector.kot_date_sunday
+ ].any? { |weekend| @kot_today&.include? weekend }
end
def kot_public_holiday?
- return true if @kot_today_type&.include? '休日'
+ return true if @kot_today_type&.include? @selector.kot_workday_time_off_text
kot_today_highlighted = %w[sunday saturday].any? do |css|
@kot_today_css_class&.include? css
end
if kot_today_highlighted
Kobot.logger.warn(
- "Today=#{@kot_today} is highlighted (holiday) but not marked as 休日"
+ "Today=#{@kot_today} is highlighted (holiday) but not marked as #{@selector.kot_workday_time_off_text}"
)
end
kot_today_highlighted
end