kobot 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e8cedf9053f994144d21b233b2c68fb4e03aff011192f1273e1ad24d347c4f9
4
- data.tar.gz: 8daab86f87c5ffe5e0588c9029ccd062954ca7ad3557769861ef19fd07347c79
3
+ metadata.gz: f35251b3ce8549b6b268a9741ecc88398f4fca4e1fbe27c343e2a1c35d456ca0
4
+ data.tar.gz: 1af276cc34607f075650b5be4df65c9666449c761b410fb5cc63629fe0392ff7
5
5
  SHA512:
6
- metadata.gz: 4aaaa2f0e8eebe98487536158b0f571e794b76db95dec5cd2eb268037dfd0888045d6cebbeb46876162ed9944813f7429e8a4466da20ca9010ecacfd552cd302
7
- data.tar.gz: 9ede3410f3ad664982db308f382140eb19bc8140970fc4991f68829a0c63fe664a6978b99ef5753036954a0bbabb9731b3f7e5fe08aff11c589798898ce0ec59
6
+ metadata.gz: a1a76b64eb1aa1019a12b4f1d4a2d34c84d79cf020b0ebc7cee7c1bd4902b180aec70790ee236883100bfd2501bbee9846f61b5b40dd8fb3996159e58b94b0df
7
+ data.tar.gz: a81c35396d3dde1a74ab9aad3c3535e92699268f49a133f9f43514b192bae808a84f1974c9f9c537690ce3561c942251c044591fc363b54c619b44586ede7670
data/CHANGELOG.md CHANGED
@@ -25,3 +25,6 @@
25
25
 
26
26
  ### v1.2.4
27
27
  - Changed to use boolean values for validation instead of raising exceptions
28
+
29
+ ### v1.2.5
30
+ - Added I18n support for both English and Japanese KOT UI
data/lib/kobot/engine.rb CHANGED
@@ -97,6 +97,12 @@ module Kobot
97
97
  Kobot.logger.info("Navigate to: #{@top_url}")
98
98
  @browser.get @top_url
99
99
  @wait.until { @browser.find_element(id: 'modal_window') }
100
+ modal_title_element = @wait.until { @browser.find_element(css: '.modal-title') }
101
+ @selector = if modal_title_element.text.downcase.include? 'password'
102
+ Selector.en
103
+ else
104
+ Selector.ja
105
+ end
100
106
  Kobot.logger.info "Page title: #{@browser.title}"
101
107
  Kobot.logger.debug do
102
108
  "Login with id=#{Credential.kot_id} and password=#{Credential.kot_password}"
@@ -106,10 +112,14 @@ module Kobot
106
112
  @browser.find_element(css: 'div.btn-control-message').click
107
113
 
108
114
  Kobot.logger.info 'Login successful'
109
- @wait.until { @browser.find_element(id: 'notification_content').text.include?('データを取得しました') }
115
+ @wait.until do
116
+ @browser.find_element(id: 'notification_content').text.include?(@selector.login_success_notification_text)
117
+ end
110
118
  if Config.browser_geolocation
111
119
  begin
112
- @wait.until { @browser.find_element(id: 'location_area').text.include?('位置情報取得済み') }
120
+ @wait.until do
121
+ @browser.find_element(id: 'location_area').text.include?(@selector.location_area_notification_text)
122
+ end
113
123
  rescue StandardError => e
114
124
  Kobot.logger.warn "Get geolocation failed: #{e.message}"
115
125
  end
@@ -119,21 +129,21 @@ module Kobot
119
129
 
120
130
  def logout
121
131
  if @browser.current_url.include? 'admin'
122
- Kobot.logger.info('Logout from タイムカード page')
132
+ Kobot.logger.info('Logout from Time Card (タイムカード) page')
123
133
  @browser.find_element(css: 'div.htBlock-header_logoutButton').click
124
134
  else
125
- Kobot.logger.info('Logout from Myレコーダー page')
135
+ Kobot.logger.info('Logout from My Recorder (Myレコーダー) page')
126
136
  @wait.until { @browser.find_element(id: 'menu_icon') }.click
127
- @wait.until { @browser.find_element(link: 'ログアウト') }.click
137
+ @wait.until { @browser.find_element(link: @selector.logout_menu_link_text) }.click
128
138
  @browser.switch_to.alert.accept
129
139
  end
130
140
  Kobot.logger.info 'Logout successful'
131
141
  end
132
142
 
133
143
  def read_today_record
134
- Kobot.logger.info('Navigate to タイムカード page')
144
+ Kobot.logger.info('Navigate to Time Card (タイムカード) page')
135
145
  @wait.until { @browser.find_element(id: 'menu_icon') }.click
136
- @wait.until { @browser.find_element(link: 'タイムカード') }.click
146
+ @wait.until { @browser.find_element(link: @selector.time_card_menu_link_text) }.click
137
147
 
138
148
  time_table = @wait.until { @browser.find_element(css: 'div.htBlock-adjastableTableF_inner > table') }
139
149
  time_table.find_elements(css: 'tbody > tr').each do |tr|
@@ -226,9 +236,9 @@ module Kobot
226
236
  @browser.get @top_url
227
237
  clock_in_button = @wait.until { @browser.find_element(css: 'div.record-clock-in') }
228
238
  if Config.dryrun
229
- Kobot.logger.info('[Dryrun] clock in button (出勤) would have been clicked')
239
+ Kobot.logger.info('[Dryrun] Clock-in button (出勤) would have been clicked')
230
240
  else
231
- Kobot.logger.info('Clicking the clock in button (出勤)')
241
+ Kobot.logger.info('Clicking the Clock-in button (出勤)')
232
242
  clock_in_button.click
233
243
  end
234
244
  end
@@ -238,9 +248,9 @@ module Kobot
238
248
  @browser.get @top_url
239
249
  clock_out_button = @wait.until { @browser.find_element(css: 'div.record-clock-out') }
240
250
  if Config.dryrun
241
- Kobot.logger.info('[Dryrun] clock out button (退勤) would have been clicked')
251
+ Kobot.logger.info('[Dryrun] Clock-out button (退勤) would have been clicked')
242
252
  else
243
- Kobot.logger.info('Clicking the clock in button (退勤)')
253
+ Kobot.logger.info('Clicking the Clock-out button (退勤)')
244
254
  clock_out_button.click
245
255
  end
246
256
  end
@@ -257,18 +267,21 @@ module Kobot
257
267
  end
258
268
 
259
269
  def kot_weekend?
260
- %w[土 日].any? { |kanji| @kot_today&.include? kanji }
270
+ [
271
+ @selector.kot_date_saturday,
272
+ @selector.kot_date_sunday
273
+ ].any? { |weekend| @kot_today&.include? weekend }
261
274
  end
262
275
 
263
276
  def kot_public_holiday?
264
- return true if @kot_today_type&.include? '休日'
277
+ return true if @kot_today_type&.include? @selector.kot_workday_time_off_text
265
278
 
266
279
  kot_today_highlighted = %w[sunday saturday].any? do |css|
267
280
  @kot_today_css_class&.include? css
268
281
  end
269
282
  if kot_today_highlighted
270
283
  Kobot.logger.warn(
271
- "Today=#{@kot_today} is highlighted (holiday) but not marked as 休日"
284
+ "Today=#{@kot_today} is highlighted (holiday) but not marked as #{@selector.kot_workday_time_off_text}"
272
285
  )
273
286
  end
274
287
  kot_today_highlighted
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kobot
4
+ # The texts used in selectors to identify the elements on KOT UI.
5
+ class Selector
6
+ attr_accessor :login_success_notification_text,
7
+ :location_area_notification_text,
8
+ :time_card_menu_link_text,
9
+ :kot_date_saturday,
10
+ :kot_date_sunday,
11
+ :kot_workday_time_off_text,
12
+ :logout_menu_link_text
13
+
14
+ class << self
15
+ def en
16
+ selector = Selector.new
17
+ selector.login_success_notification_text = 'Data has been obtained'
18
+ selector.location_area_notification_text = 'Obtained location'
19
+ selector.time_card_menu_link_text = 'Time Card'
20
+ selector.kot_date_saturday = 'Sat'
21
+ selector.kot_date_sunday = 'Sun'
22
+ selector.kot_workday_time_off_text = 'time-off'
23
+ selector.logout_menu_link_text = 'Sign out'
24
+ selector
25
+ end
26
+
27
+ def ja
28
+ selector = Selector.new
29
+ selector.login_success_notification_text = 'データを取得しました'
30
+ selector.location_area_notification_text = '位置情報取得済み'
31
+ selector.time_card_menu_link_text = 'タイムカード'
32
+ selector.kot_date_saturday = '土'
33
+ selector.kot_date_sunday = '日'
34
+ selector.kot_workday_time_off_text = '休日'
35
+ selector.logout_menu_link_text = 'ログアウト'
36
+ selector
37
+ end
38
+ end
39
+ end
40
+ end
data/lib/kobot/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kobot
4
- VERSION = '1.2.4'
4
+ VERSION = '1.2.5'
5
5
  end
data/lib/kobot.rb CHANGED
@@ -4,6 +4,7 @@ require 'kobot/version'
4
4
  require 'kobot/exception'
5
5
  require 'kobot/option'
6
6
  require 'kobot/config'
7
+ require 'kobot/selector'
7
8
  require 'kobot/credential'
8
9
  require 'kobot/logger'
9
10
  require 'kobot/mailer'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jiang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-18 00:00:00.000000000 Z
11
+ date: 2021-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webdrivers
@@ -83,6 +83,7 @@ files:
83
83
  - lib/kobot/logger.rb
84
84
  - lib/kobot/mailer.rb
85
85
  - lib/kobot/option.rb
86
+ - lib/kobot/selector.rb
86
87
  - lib/kobot/version.rb
87
88
  homepage: https://github.com/yuan-jiang/kobot
88
89
  licenses:
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  - !ruby/object:Gem::Version
108
109
  version: '0'
109
110
  requirements: []
110
- rubygems_version: 3.0.3
111
+ rubygems_version: 3.1.2
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: Kobot automates the clock in/out of KING OF TIME.