boq_com_au 0.2.0 → 0.3.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: f547e1eca5d228aa0fbe37a82921b33370977e513f209b5e57bab82d8347b6bb
4
+ data.tar.gz: 0aa18118dc2ce6a0726fdbac97bff153f89cf7a55febf13240a5a2237447ecf5
5
5
  SHA512:
6
- metadata.gz: 3fcf4ff2fb9ecfe8eb73d7cc5751202c4c16f4fd3876f3b448616477f2cc0719cf6b5151c67960ecd3ec9b2a1e18cc1c82472f484376565f68fcf87b84a98782
7
- data.tar.gz: be41871305543362742a9cd6d86e56cfa26a1d320e4a624be742af293d4c5d417fc2d4202302926fec37d3725803e8bd572f07c882fe87c79e5daf292144f64d
6
+ metadata.gz: 31711622ea4cf7f3ffbc005b00abe07c7859529badc32b338defa02a6fa65713ed9b10674f671b545d65ac0ed4933ac622d751e02dd3c919fa7b5fc67b678779
7
+ data.tar.gz: 537ee3dad673b7a379c15da75b271b3e5bff94a55fccbe94fb7c633168cd7e14a655892e1eac3c06284404122e6ae02098af35db237da2ca23e4a8e990cbb625
data/CHANGELOG CHANGED
@@ -1,5 +1,19 @@
1
1
  # boq_com_au/CHANGELOG
2
2
 
3
+ ## 20261111
4
+
5
+ 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:/.
6
+
7
+ 1. ~ boq_com_au.gemspec: webaccount /'>= 0.6.1'/'~> 0.7'/
8
+ 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:.
9
+ 3. - BoqComAu::Account#default_driver_options, WebAccount's giving Chrome's options or Firefox's.
10
+ 4. - BoqComAu::Account#download_directory, #click, #stale?, #wait_for, #set_value, WebAccount's doing the same.
11
+ 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.
12
+ 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.
13
+ 7. ~ README.md: Firefox and profile_directory:.
14
+ 8. ~ BoqComAu::VERSION: /0.2.0/0.3.0/
15
+
16
+
3
17
  ## 20261104
4
18
 
5
19
  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
 
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.7']
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,12 @@ 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
62
+ def initialize(username: nil, password: nil, **web_account_args)
63
+ super(username: username, password: password, **web_account_args, **PAGE_SELECTORS)
89
64
  end
90
65
 
91
66
  # page interaction
92
67
 
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
68
  def chosen_list(select_element)
118
69
  driver.find_elements(id: "#{select_element.attribute('id')}_chosen").first
119
70
  end
@@ -157,16 +108,6 @@ module BoqComAu
157
108
  date.strftime('%d/%m/%Y')
158
109
  end
159
110
 
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
111
  # transactions
171
112
 
172
113
  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.3.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,33 @@ 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 "logs in to BOQ, whatever else is passed to WebAccount" do
141
+ account = BoqComAu::Account.new(headless: true, window_size: [1280, 800])
142
+ _(account.send(: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])
171
144
  end
172
145
  end
173
146
 
@@ -208,28 +181,6 @@ describe BoqComAu::Account do
208
181
  end
209
182
  end
210
183
 
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
184
  describe "#get_transactions_page" do
234
185
  it "clicks the history link by JavaScript, the link being in a menu which is closed" do
235
186
  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.3.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.7'
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.7'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: minitest
42
42
  requirement: !ruby/object:Gem::Requirement