lib/kobot/engine.rb in kobot-1.2.0 vs lib/kobot/engine.rb in kobot-1.2.1

- old
+ new

@@ -31,12 +31,12 @@ else Kobot.logger.info("Today=#{@today} is weekend") return end end - if holiday? - Kobot.logger.info("Today=#{@today} is holiday") + if skip? + Kobot.logger.info("Today=#{@today} is skipped as per: --skip=#{Config.skip}") return end unless %i[in out].include? Config.clock Kobot.logger.warn("Invalid clock operation: #{Config.clock}") return @@ -67,10 +67,11 @@ Kobot.logger.error(e.message) Kobot.logger.error(e.backtrace) Mailer.send(clock_notify_message(status: e.message)) logout ensure + Kobot.logger.info('Close browser') @browser&.quit end private @@ -88,12 +89,12 @@ @wait = Selenium::WebDriver::Wait.new(timeout: Config.browser_wait_timeout) Kobot.logger.info('Launch browser successful') end def login - @browser.get @top_url Kobot.logger.info("Navigate to: #{@top_url}") + @browser.get @top_url 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 @@ -106,25 +107,28 @@ @wait.until { @browser.find_element(id: 'location_area').text.include?('位置情報取得済み') } rescue StandardError => e Kobot.logger.warn "Get geolocation failed: #{e.message}" end end - Kobot.logger.info @browser.title + Kobot.logger.info "Page title: #{@browser.title}" end def logout if @browser.current_url.include? 'admin' + Kobot.logger.info('Logout from タイムカード page') @browser.find_element(css: 'div.htBlock-header_logoutButton').click else + Kobot.logger.info('Logout from Myレコーダー page') @wait.until { @browser.find_element(id: 'menu_icon') }.click @wait.until { @browser.find_element(link: 'ログアウト') }.click @browser.switch_to.alert.accept end Kobot.logger.info 'Logout successful' end def read_today_record + Kobot.logger.info('Navigate to タイムカード page') @wait.until { @browser.find_element(id: 'menu_icon') }.click @wait.until { @browser.find_element(link: 'タイムカード') }.click time_table = @wait.until { @browser.find_element(css: 'div.htBlock-adjastableTableF_inner > table') } time_table.find_elements(css: 'tbody > tr').each do |tr| @@ -214,33 +218,37 @@ Kobot.logger.warn("Clock out done already: #{@kot_today_clock_out}") end end 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') else + 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') else + Kobot.logger.info('Clicking the clock in button (退勤)') clock_out_button.click end end def weekend? @now.saturday? || @now.sunday? end - def holiday? + def skip? return false unless Config.skip return false unless Config.skip.respond_to? :include? Config.skip.include? @now.strftime('%F') end