boq_com_au 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25b9fba8414050a29c7aba82c8f7e19df4ed098ece4345ec16002897fd3d8f10
4
- data.tar.gz: 0e6053f79b2391dcccf6283100508c02b30b54155406663270bac28f32da58a4
3
+ metadata.gz: 169a4211f870a165121c2ac49ec27b58346c7f28b0ecc24bcafbb9d494c74877
4
+ data.tar.gz: fecb838576a38a082066462790e4167a6d58eaaf252389a5d75849130a8c66f9
5
5
  SHA512:
6
- metadata.gz: 3fcf4ff2fb9ecfe8eb73d7cc5751202c4c16f4fd3876f3b448616477f2cc0719cf6b5151c67960ecd3ec9b2a1e18cc1c82472f484376565f68fcf87b84a98782
7
- data.tar.gz: be41871305543362742a9cd6d86e56cfa26a1d320e4a624be742af293d4c5d417fc2d4202302926fec37d3725803e8bd572f07c882fe87c79e5daf292144f64d
6
+ metadata.gz: 4951d8080e25d20cc968437cd2009e39fb87b22b961bb44c7442742ab32d2c84e7dcf1a0bb14b0363a3b8076eb85bbcf87b6276ec7a46ffa96fbb9c3f396aca4
7
+ data.tar.gz: 58615e334a814d0ac6a32c226d78c6cde168cce65e3fcc1bc97e9ead3af68f0d6bfa6bbf4477cdad633aeb6fe8a147ac631915640b37d680188dbaae921884a5
data/CHANGELOG CHANGED
@@ -1,5 +1,30 @@
1
1
  # boq_com_au/CHANGELOG
2
2
 
3
+ ## 20261115
4
+
5
+ 0.4.0: - BoqComAu::Account#initialize: Now uses superclass WebAccount.
6
+
7
+ 1. ~ boq_com_au.gemspec: webaccount /'~> 0.7'/'~> 0.8'/
8
+ 2. - BoqComAu::Account#initialize, WebAccount's reading PAGE_SELECTORS itself.
9
+ 3. ~ test/BoqComAu/Account_test.rb: A login page URL and a selector given win over BOQ's, the rest staying BOQ's; /logs in to BOQ, whatever else is passed to WebAccount/uses BOQ's selectors where none is given/.
10
+ 4. ~ README.md: The keywords of new win over PAGE_SELECTORS.
11
+ 5. ~ BoqComAu::VERSION: /0.3.0/0.4.0/
12
+
13
+
14
+ ## 20261111
15
+
16
+ 0.3.0: ~ BoqComAu::Account uses WebAccount 0.7.0's browser options and download waiting, so as it runs in Firefox as well as Chrome; /chrome_profile_directory:/profile_directory:/.
17
+
18
+ 1. ~ boq_com_au.gemspec: webaccount /'>= 0.6.1'/'~> 0.7'/
19
+ 2. ~ BoqComAu::Account#initialize: /chrome_profile_directory:/profile_directory:/; download_directory:, browser: and driver_options: go to WebAccount, as do headless:, window_size: and user_agent:.
20
+ 3. - BoqComAu::Account#default_driver_options, WebAccount's giving Chrome's options or Firefox's.
21
+ 4. - BoqComAu::Account#download_directory, #click, #stale?, #wait_for, #set_value, WebAccount's doing the same.
22
+ 5. - BoqComAu::Account#newest_csv_filename, #wait_for_download, WebAccount's #wait_for_download waiting longer, and past Firefox's downloads in progress as well as Chrome's.
23
+ 6. ~ test/BoqComAu/Account_test.rb: The tests of what's now WebAccount's are dropped; the options for Chrome and for Firefox, and profile_directory: in place of chrome_profile_directory:, are tested.
24
+ 7. ~ README.md: Firefox and profile_directory:.
25
+ 8. ~ BoqComAu::VERSION: /0.2.0/0.3.0/
26
+
27
+
3
28
  ## 20261104
4
29
 
5
30
  0.2.0: + BoqComAu::Account#download_transactions(period:, from_date:, to_date:), choosing the dates.
data/README.md CHANGED
@@ -31,7 +31,7 @@ $ gem install boq_com_au
31
31
  boq_account.login
32
32
  boq_account.download_transactions(account_number: '12345678')
33
33
  # => "/Users/me/Downloads/12345678_20261103.csv"
34
- boq_account.shutdown # Logs out if still logged in, then quits Chrome.
34
+ boq_account.shutdown # Logs out if still logged in, then quits the browser.
35
35
  ```
36
36
  The account is picked from the list by the digits of its number alone, so `'12345678'` and `'1234 5678'` are the same. Its transactions are exported with Export All as Comma Delimited Format (CSV).
37
37
 
@@ -43,7 +43,7 @@ Without dates, the transactions are those BOQ shows on choosing the account. Giv
43
43
  ```
44
44
  Dates are Dates, or Strings `Date.parse` can read. Where only one of `from_date` and `to_date` is given, the other is a year ago or today.
45
45
 
46
- `download_transactions` waits for the download to finish, and returns the newest CSV file to have appeared in the download directory since Download was clicked. BOQ names it after the account number and the day's date, and Chrome adds a number to that where a file of the name is there already.
46
+ `download_transactions` waits for the download to finish, and returns the newest CSV file to have appeared in the download directory since Download was clicked. BOQ names it after the account number and the day's date, and the browser adds a number to that where a file of the name is there already.
47
47
 
48
48
  Or in one step, logging in, downloading, and shutting down even where the download fails:
49
49
  ```ruby
@@ -62,15 +62,16 @@ Where either is missing, `login` stops, saying which.
62
62
 
63
63
  ### The browser
64
64
 
65
- Chrome is started with its automation flags masked. Given a `chrome_profile_directory`, it's started with that profile, kept between runs, so as the bank sees a returning browser rather than a fresh automated one; without one, each run has a new, temporary profile.
65
+ The browser is WebAccount's: Chrome, unless `browser: :firefox` is given, Chrome being started with its automation flags masked. Given a `profile_directory`, it's started with that profile, kept between runs, so as the bank sees a returning browser rather than a fresh automated one; without one, each run has a new, temporary profile.
66
66
  ```ruby
67
- BoqComAu::Account.new(chrome_profile_directory: '~/path/to/chrome-profile')
67
+ BoqComAu::Account.new(profile_directory: '~/path/to/profile')
68
+ BoqComAu::Account.new(browser: :firefox, profile_directory: '~/path/to/firefox-profile')
68
69
  ```
69
- Chrome downloads into `download_directory`, `~/Downloads` unless given, without asking where, and opens nothing it downloads:
70
+ It downloads into `download_directory`, `~/Downloads` unless given, without asking where, and opens nothing it downloads:
70
71
  ```ruby
71
72
  BoqComAu::Account.new(download_directory: '~/path/to/statements')
72
73
  ```
73
- Passing `browser:` or `driver_options:` to `BoqComAu::Account.new` replaces all of that, as for any WebAccount.
74
+ `headless:`, `window_size:` and `user_agent:` are passed to WebAccount too. Passing `driver_options:` replaces the browser's options altogether.
74
75
 
75
76
  Where BOQ asks for a one-time code after logging on, `login` waits up to 30 seconds for it to be entered in the browser.
76
77
 
@@ -78,6 +79,11 @@ Where BOQ asks for a one-time code after logging on, `login` waits up to 30 seco
78
79
 
79
80
  The selectors were taken from the live site. BOQ's ids are generated, so things are found by their labels and text, and a change to the wording of the site will break it.
80
81
 
82
+ Each key of `BoqComAu::Account::PAGE_SELECTORS` is also a keyword of `new`, which wins over BOQ's, so as a login page selector which has changed can be given without waiting for a new version:
83
+ ```ruby
84
+ BoqComAu::Account.new(login_page_submit_button_selector: {id: 'btnLogOn'})
85
+ ```
86
+
81
87
  The tests cover only what doesn't depend on BOQ's site.
82
88
 
83
89
  ## Contributing
data/boq_com_au.gemspec CHANGED
@@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
38
38
 
39
39
  spec.dependencies = [
40
40
  ['selenium-webdriver', '>= 4.0'],
41
- ['webaccount', '>= 0.6.1']
41
+ ['webaccount', '~> 0.8']
42
42
  ]
43
43
 
44
44
  spec.development_dependencies = %w{
@@ -7,9 +7,9 @@
7
7
  # 3. BankFast's links are javascript:void(0) where they aren't the session's key and a callback number, and some, such as Transaction History, are in a menu which is closed. A link which isn't displayed is clicked by JavaScript.
8
8
  # 4. Dropdowns are Chosen's, which hides the select and draws its own: <select id>_chosen, opened by its a.chosen-single and chosen from its li.active-result. A select which is displayed is used as it is.
9
9
  # 5. Where a one-time code is asked for after logging on, login() waits default_wait_timeout seconds for it to be entered by hand.
10
- # 6. Chrome is started with its automation flags masked; and, given a chrome_profile_directory, with that profile, kept between runs, so as the bank sees a returning browser rather than a fresh automated one. It downloads into download_directory without asking, and opens nothing it downloads.
10
+ # 6. The browser, Chrome or Firefox, is WebAccount's: given a profile_directory, it's started with that profile, kept between runs, so as the bank sees a returning browser rather than a fresh automated one. It downloads into download_directory without asking, and opens nothing it downloads.
11
11
  # 7. A username or password not given stops login, saying which is missing.
12
- # 8. BOQ names the exported file after the account number and the date, as 12345678_20261103.csv, and Chrome numbers a second download of the same name; so the newest CSV file to appear in download_directory once Download is clicked is taken to be it. Chrome names a download in progress .crdownload, so a CSV file is a finished one.
12
+ # 8. BOQ names the exported file after the account number and the date, as 12345678_20261103.csv, and the browser numbers a second download of the same name; so the newest finished CSV file to appear in download_directory once Download is clicked is taken to be it.
13
13
  # 9. Dates are BOQ's own, as shown on choosing the account, unless a period or a date is given; then they're set under Advanced Search and searched on before exporting.
14
14
 
15
15
  require 'date'
@@ -37,7 +37,6 @@ module BoqComAu
37
37
  download_button: {xpath: '//*[self::a or self::button][normalize-space()="Download"] | //input[@value="Download"]'}
38
38
  }
39
39
 
40
- attr_reader :download_directory
41
40
  def username
42
41
  @username || raise("No username: it's given as username:.")
43
42
  end
@@ -60,60 +59,8 @@ module BoqComAu
60
59
 
61
60
  private
62
61
 
63
- def initialize(username: nil, password: nil, chrome_profile_directory: nil, download_directory: File.join('~', 'Downloads'), browser: nil, driver_options: nil)
64
- @chrome_profile_directory = chrome_profile_directory && File.expand_path(chrome_profile_directory)
65
- @download_directory = File.expand_path(download_directory)
66
- super(
67
- username: username, password: password,
68
- browser: browser, driver_options: driver_options,
69
- login_page_url: PAGE_SELECTORS[:login_page_url],
70
- login_page_username_field_selector: PAGE_SELECTORS[:login_page_username_field_selector],
71
- login_page_password_field_selector: PAGE_SELECTORS[:login_page_password_field_selector],
72
- login_page_submit_button_selector: PAGE_SELECTORS[:login_page_submit_button_selector],
73
- logout_button_selector: PAGE_SELECTORS[:logout_button_selector],
74
- logged_out_xpath: PAGE_SELECTORS[:logged_out_xpath],
75
- )
76
- end
77
-
78
- # driver construction
79
-
80
- def default_driver_options
81
- return unless browser == :chrome
82
- Selenium::WebDriver::Chrome::Options.new.tap do |o|
83
- o.add_argument("--user-data-dir=#{@chrome_profile_directory}") if @chrome_profile_directory
84
- o.add_argument('--disable-blink-features=AutomationControlled')
85
- o.exclude_switches << 'enable-automation'
86
- o.add_preference(:credentials_enable_service, false)
87
- o.add_preference(:download, default_directory: @download_directory, prompt_for_download: false, directory_upgrade: true, extensions_to_open: '')
88
- end
89
- end
90
-
91
62
  # page interaction
92
63
 
93
- # Found afresh on each attempt, so as an element replaced by a redrawn page is retried rather than ending in StaleElementReferenceError.
94
- def click(selector)
95
- driver.attempt do
96
- element = find(selector)
97
- element.displayed? ? element.click : driver.execute_script('arguments[0].click();', element)
98
- end
99
- end
100
-
101
- def stale?(element)
102
- element.displayed?
103
- false
104
- rescue Selenium::WebDriver::Error::StaleElementReferenceError
105
- true
106
- end
107
-
108
- def wait_for(selector)
109
- driver_wait.until{driver.find_elements(*selector.first).any?(&:displayed?)}
110
- end
111
-
112
- # Dates are set by JavaScript, so as a date picker doesn't open over the fields.
113
- def set_value(element, value)
114
- driver.execute_script("arguments[0].value = arguments[1]; arguments[0].dispatchEvent(new Event('change', {bubbles: true}));", element, value)
115
- end
116
-
117
64
  def chosen_list(select_element)
118
65
  driver.find_elements(id: "#{select_element.attribute('id')}_chosen").first
119
66
  end
@@ -157,16 +104,6 @@ module BoqComAu
157
104
  date.strftime('%d/%m/%Y')
158
105
  end
159
106
 
160
- # downloads
161
-
162
- def newest_csv_filename(since:)
163
- Dir.glob(File.join(@download_directory, '*.csv')).select{|filename| File.mtime(filename) >= since}.max_by{|filename| File.mtime(filename)}
164
- end
165
-
166
- def wait_for_download(since:)
167
- driver_wait.until{newest_csv_filename(since: since)}
168
- end
169
-
170
107
  # transactions
171
108
 
172
109
  def get_transactions_page
@@ -2,5 +2,5 @@
2
2
  # BoqComAu::VERSION
3
3
 
4
4
  module BoqComAu
5
- VERSION = '0.2.0'
5
+ VERSION = '0.4.0'
6
6
  end
@@ -8,7 +8,6 @@ require_relative '../../lib/boq_com_au'
8
8
  require 'date'
9
9
  require 'minitest/autorun'
10
10
  require 'minitest-spec-context'
11
- require 'tmpdir'
12
11
 
13
12
  describe BoqComAu::Account do
14
13
  def stand_in_element(text: '', displayed: true, id: nil)
@@ -68,11 +67,6 @@ describe BoqComAu::Account do
68
67
  [account, opener, options]
69
68
  end
70
69
 
71
- def touch(filename, mtime)
72
- File.write(filename, '')
73
- File.utime(mtime, mtime, filename)
74
- end
75
-
76
70
  describe "#username and #password" do
77
71
  it "are those given" do
78
72
  account = BoqComAu::Account.new(username: 'customer', password: 'secret')
@@ -120,54 +114,40 @@ describe BoqComAu::Account do
120
114
  end
121
115
  end
122
116
 
123
- describe "#default_driver_options" do
124
- it "masks Chrome's automation flags, leaving the profile to Chrome where none is given" do
125
- options = BoqComAu::Account.new.send(:default_driver_options)
126
- _(options.args).must_include('--disable-blink-features=AutomationControlled')
127
- _(options.exclude_switches).must_include('enable-automation')
128
- _(options.args.grep(/--user-data-dir/)).must_be_empty
129
- end
130
-
131
- it "starts Chrome with the profile given, expanded" do
132
- options = BoqComAu::Account.new(chrome_profile_directory: '~/profiles/boq').send(:default_driver_options)
117
+ describe "the browser" do
118
+ it "is Chrome, started with the profile given, expanded, downloading into the download directory given" do
119
+ options = BoqComAu::Account.new(profile_directory: '~/profiles/boq', download_directory: '~/statements').send(:default_driver_options)
120
+ _(options).must_be_kind_of(Selenium::WebDriver::Chrome::Options)
133
121
  _(options.args).must_include("--user-data-dir=#{File.expand_path('~/profiles/boq')}")
122
+ _(options.prefs[:download][:default_directory]).must_equal(File.expand_path('~/statements'))
134
123
  end
135
124
 
136
- it "downloads into the download directory without asking, opening nothing" do
137
- options = BoqComAu::Account.new(download_directory: '~/statements').send(:default_driver_options)
138
- download = options.prefs[:download]
139
- _(download[:default_directory]).must_equal(File.expand_path('~/statements'))
140
- _(download[:prompt_for_download]).must_equal(false)
141
- _(download[:extensions_to_open]).must_equal('')
125
+ it "is Firefox where asked for, started with the profile given, downloading into the download directory given" do
126
+ options = BoqComAu::Account.new(browser: :firefox, profile_directory: '~/profiles/boq', download_directory: '~/statements').send(:default_driver_options)
127
+ _(options).must_be_kind_of(Selenium::WebDriver::Firefox::Options)
128
+ _(options.args).must_equal(['-profile', File.expand_path('~/profiles/boq')])
129
+ _(options.prefs['browser.download.dir']).must_equal(File.expand_path('~/statements'))
142
130
  end
143
131
 
144
132
  it "downloads into ~/Downloads where no directory is given" do
145
133
  _(BoqComAu::Account.new.download_directory).must_equal(File.expand_path('~/Downloads'))
146
134
  end
147
135
 
148
- it "is nil for browsers other than Chrome" do
149
- _(BoqComAu::Account.new(browser: :firefox).send(:default_driver_options)).must_be_nil
136
+ it "takes the profile as profile_directory:, no longer as chrome_profile_directory:" do
137
+ _{BoqComAu::Account.new(chrome_profile_directory: '~/profiles/boq')}.must_raise(ArgumentError)
150
138
  end
151
- end
152
139
 
153
- describe "#click" do
154
- it "finds the element afresh where the one found first has been redrawn" do
155
- old_link, new_link = stand_in_link, stand_in_link
156
- old_link.stale!
157
- driver = stand_in_driver
158
- attempts = 0
159
- driver.define_singleton_method(:attempt) do |&block|
160
- block.call(self)
161
- rescue Selenium::WebDriver::Error::StaleElementReferenceError
162
- attempts += 1
163
- retry if attempts < 3
164
- raise
165
- end
166
- account = account_with_driver(driver)
167
- links = [old_link, new_link]
168
- account.define_singleton_method(:find){|*| links.shift}
169
- account.send(:click, {xpath: '//a'})
170
- _(new_link.clicked?).must_equal(true)
140
+ it "uses BOQ's selectors where none is given" do
141
+ account = BoqComAu::Account.new
142
+ _(account.send(:login_page_username_field_selector)).must_equal(BoqComAu::Account::PAGE_SELECTORS[:login_page_username_field_selector])
143
+ _(account.send(:logout_button_selector)).must_equal(BoqComAu::Account::PAGE_SELECTORS[:logout_button_selector])
144
+ end
145
+
146
+ it "logs in where told to, a keyword winning over BOQ's selector" do
147
+ account = BoqComAu::Account.new(login_page_url: 'https://test.example.com/logon', logout_button_selector: {id: 'logoff'})
148
+ _(account.send(:login_page_url)).must_equal('https://test.example.com/logon')
149
+ _(account.send(:logout_button_selector)).must_equal({id: 'logoff'})
150
+ _(account.send(:login_page_username_field_selector)).must_equal(BoqComAu::Account::PAGE_SELECTORS[:login_page_username_field_selector])
171
151
  end
172
152
  end
173
153
 
@@ -208,28 +188,6 @@ describe BoqComAu::Account do
208
188
  end
209
189
  end
210
190
 
211
- describe "#newest_csv_filename" do
212
- it "is the newest CSV file in the download directory since the time given" do
213
- Dir.mktmpdir do |directory|
214
- since = Time.now - 60
215
- touch(File.join(directory, 'old.csv'), since - 60)
216
- touch(File.join(directory, 'new.csv'), since + 10)
217
- touch(File.join(directory, 'newer.csv'), since + 20)
218
- touch(File.join(directory, 'newest.csv.crdownload'), since + 30)
219
- account = BoqComAu::Account.new(download_directory: directory)
220
- _(account.send(:newest_csv_filename, since: since)).must_equal(File.join(directory, 'newer.csv'))
221
- end
222
- end
223
-
224
- it "is nil where none has appeared since" do
225
- Dir.mktmpdir do |directory|
226
- since = Time.now
227
- touch(File.join(directory, 'old.csv'), since - 60)
228
- _(BoqComAu::Account.new(download_directory: directory).send(:newest_csv_filename, since: since)).must_be_nil
229
- end
230
- end
231
- end
232
-
233
191
  describe "#get_transactions_page" do
234
192
  it "clicks the history link by JavaScript, the link being in a menu which is closed" do
235
193
  driver = stand_in_driver
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boq_com_au
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -27,16 +27,16 @@ dependencies:
27
27
  name: webaccount
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - ">="
30
+ - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 0.6.1
32
+ version: '0.8'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.6.1
39
+ version: '0.8'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: minitest
42
42
  requirement: !ruby/object:Gem::Requirement