lib/kobot/engine.rb in kobot-1.2.1 vs lib/kobot/engine.rb in kobot-1.2.2
- old
+ new
@@ -4,11 +4,10 @@
module Kobot
# The core class that launches browser, logins to KOT, reads today
# record, and conducts clock in or clock out action based on config.
class Engine
-
def initialize
@now = Time.now.getlocal(Config.kot_timezone_offset)
@today = @now.strftime(Config.kot_date_format)
@top_url = Config.kot_url
end
@@ -91,10 +90,12 @@
end
def login
Kobot.logger.info("Navigate to: #{@top_url}")
@browser.get @top_url
+ @wait.until { @browser.find_element(id: 'modal_window') }
+ 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
@@ -137,12 +138,16 @@
Kobot.logger.info('Reading today record')
@kot_today = date_cell.text
@kot_today_css_class = date_cell.attribute('class')
@kot_today_type = tr.find_element(css: 'td.work_day_type').text
- @kot_today_clock_in = tr.find_element(css: 'td.start_end_timerecord[data-ht-sort-index="START_TIMERECORD"]').text
- @kot_today_clock_out = tr.find_element(css: 'td.start_end_timerecord[data-ht-sort-index="END_TIMERECORD"]').text
+ @kot_today_clock_in = tr.find_element(
+ css: 'td.start_end_timerecord[data-ht-sort-index="START_TIMERECORD"]'
+ ).text
+ @kot_today_clock_out = tr.find_element(
+ css: 'td.start_end_timerecord[data-ht-sort-index="END_TIMERECORD"]'
+ ).text
Kobot.logger.debug do
{
kot_toay: @kot_today,
kot_today_css_class: @kot_today_css_class,
kot_today_type: @kot_today_type,
@@ -156,29 +161,22 @@
def verify_today_record!
raise KotRecordError, "Today=#{@today} is not found on kot" if @kot_today.strip.empty?
if kot_weekend?
- unless Config.force
- raise KotRecordError,
- "Today=#{@today} is marked as weekend on kot: #{@kot_today}"
- end
+ raise KotRecordError, "Today=#{@today} is marked as weekend on kot: #{@kot_today}" unless Config.force
Kobot.logger.info(
"[Force] should have exited: today=#{@today} is marked as weekend on kot: #{@kot_today}"
)
end
- if kot_public_holiday?
- unless Config.force
- raise KotRecordError,
- "Today=#{@today} is marked as public holiday on kot: #{@kot_today}"
- end
+ return unless kot_public_holiday?
+ raise KotRecordError, "Today=#{@today} is marked as public holiday on kot: #{@kot_today}" unless Config.force
- Kobot.logger.info(
- "[Force] should have exited: today=#{@today} is marked as public holiday on kot: #{@kot_today}"
- )
- end
+ Kobot.logger.info(
+ "[Force] should have exited: today=#{@today} is marked as public holiday on kot: #{@kot_today}"
+ )
end
def clock_in!
Kobot.logger.warn("Clock in during the afternoon: #{@now}") if @now.hour > 12
if @kot_today_clock_in.strip.empty?