lib/kobot/engine.rb in kobot-2.0.0 vs lib/kobot/engine.rb in kobot-2.1.0
- old
+ new
@@ -98,38 +98,44 @@
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.info "Page title (before login): #{@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 do
- @browser.find_element(id: 'notification_content').text.include?(@selector.login_success_notification_text)
+ clock_in_button = @wait.until { @browser.find_element(css: '.record-clock-in') }
+ @selector = if clock_in_button.text.include? '出勤'
+ Kobot.logger.info('Identify UI in Japanese')
+ Selector.ja
+ else
+ Kobot.logger.info('Identify UI in English')
+ Selector.en
+ end
+ begin
+ @wait.until do
+ @browser.find_element(id: 'notification_content').text.include?(@selector.login_success_notification_text)
+ end
+ rescue StandardError => e
+ Kobot.logger.warn "Failed to validate login success notification text: #{e.message}"
end
if Config.browser_geolocation
begin
@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}"
+ Kobot.logger.info "Page title (after login): #{@browser.title}"
end
def logout
if @browser.current_url.include? 'admin'
Kobot.logger.info('Logout from Time Card (タイムカード) page')
@@ -151,10 +157,10 @@
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
- Kobot.logger.info('Reading today record')
+ Kobot.logger.info('Read today record')
@kot_data = {}
@kot_data[:today] = date_cell.text
@kot_data[:today_css_class] = date_cell.attribute('class')
@kot_data[:today_type] = tr.find_element(css: 'td.work_day_type').text
@kot_data[:today_schedule] = tr.find_element(css: 'td.schedule').text