westpac_com_au 0.6.2 → 0.6.3
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 +4 -4
- data/CHANGELOG +11 -0
- data/README.md +1 -1
- data/lib/WestpacComAu/Account.rb +13 -5
- data/lib/WestpacComAu/VERSION.rb +1 -1
- data/test/WestpacComAu/Account_test.rb +28 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e45d2e23f67a69e5030e10df12b9f2c312b736c3e6b4080d978df750567a2179
|
|
4
|
+
data.tar.gz: b3412ac9973153b2c13da4750604295b7b68bbf5e1cfe67f0aefe5520ac7f379
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bbacaa0dd3b7df2cc9b43506457e81f636a764969a50ef9850fb00d00d144a0e31c4f1fb2b34fa914b02c404ebd7da78ffc9978f6bf782dcd3dce4ed6fabb878
|
|
7
|
+
data.tar.gz: 43b90ca7377f8bc1c707666412a679fa8640744f2ca4fd525742f78ea5c734b06de3c8b107e9b797f494f2520a855f1439e11074a9cf0d1a4deb434970bc04d5
|
data/CHANGELOG
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
## 20261116
|
|
4
4
|
|
|
5
|
+
0.6.3: ~ WestpacComAu::Account#export_csv: Stops where there's no data to export, rather than waiting for a timeout.
|
|
6
|
+
|
|
7
|
+
1. ~ WestpacComAu::Account::TRANSACTIONS_SELECTORS: + no_data_message
|
|
8
|
+
2. + WestpacComAu::Account#no_data?
|
|
9
|
+
3. ~ WestpacComAu::Account#export_csv: Takes from_date: and to_date:, and raises naming them where Westpac's no-data message shows, a download or the message being waited for.
|
|
10
|
+
4. ~ WestpacComAu::Account#download_transactions: Passes the dates to export_csv.
|
|
11
|
+
5. ~ test/WestpacComAu/Account_test.rb: The export stops upon the no-data message, and times out where there's neither it nor a download.
|
|
12
|
+
6. ~ README.md: download_transactions raises where there's no data for the export.
|
|
13
|
+
7. ~ lib/WestpacComAu/Account.rb: Its notes say so too.
|
|
14
|
+
8. ~ WestpacComAu::VERSION: /0.6.2/0.6.3/
|
|
15
|
+
|
|
5
16
|
0.6.2: The tests share a helper, and VERSION and the gemspec are tested; the gemspec links to the repository.
|
|
6
17
|
|
|
7
18
|
1. + test/helper.rb
|
data/README.md
CHANGED
|
@@ -43,7 +43,7 @@ Without a period or dates, they're those of the last year. Otherwise:
|
|
|
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 Export was clicked.
|
|
46
|
+
`download_transactions` waits for the download to finish, and returns the newest CSV file to have appeared in the download directory since Export was clicked. Where Westpac says instead that no data is available for the export, it raises RuntimeError, naming the dates.
|
|
47
47
|
|
|
48
48
|
Or in one step, logging in, downloading, and shutting down even where the download fails:
|
|
49
49
|
```ruby
|
data/lib/WestpacComAu/Account.rb
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
# 3. Signing out lands on a page saying so, with its form#logout, which at times goes on to the login page, with its form#login; either is taken as logged out. Both pages have an element with the id signin, so that id doesn't tell them apart.
|
|
8
8
|
# 4. Where a one-time code is asked for after signing in, login waits default_wait_timeout seconds for it to be entered by hand.
|
|
9
9
|
# 5. A username or password not given stops login before the browser is started, naming every one missing.
|
|
10
|
-
# 6. The newest finished CSV file to appear in download_directory once Export is clicked is taken to be the export.
|
|
10
|
+
# 6. The newest finished CSV file to appear in download_directory once Export is clicked is taken to be the export. Where Westpac says instead that there's no data for the export, it stops, naming the dates.
|
|
11
11
|
|
|
12
12
|
require 'date'
|
|
13
13
|
require 'webaccount'
|
|
@@ -32,7 +32,8 @@ module WestpacComAu
|
|
|
32
32
|
to_date_field: {id: 'DateRange_EndDate'},
|
|
33
33
|
account_field: {id: 'Accounts_1'},
|
|
34
34
|
csv_radio_button: {id: 'File_type_1'},
|
|
35
|
-
export_button: {css: 'button.export-link'}
|
|
35
|
+
export_button: {css: 'button.export-link'},
|
|
36
|
+
no_data_message: {xpath: '//*[contains(text(), "No data is available for the export search criteria")]'}
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
# period is :all, the last year, or :last_month. Without it, from_date and to_date, which default to a year ago and today. Returns the name of the CSV file downloaded.
|
|
@@ -42,7 +43,7 @@ module WestpacComAu
|
|
|
42
43
|
enter_dates(from_date: from_date, to_date: to_date)
|
|
43
44
|
select_bank_account(account_number)
|
|
44
45
|
click(TRANSACTIONS_SELECTORS[:csv_radio_button])
|
|
45
|
-
export_csv
|
|
46
|
+
export_csv(from_date: from_date, to_date: to_date)
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
private
|
|
@@ -118,10 +119,17 @@ module WestpacComAu
|
|
|
118
119
|
account_field.send_keys(Selenium::WebDriver::Keys[:return])
|
|
119
120
|
end
|
|
120
121
|
|
|
121
|
-
def
|
|
122
|
+
def no_data?
|
|
123
|
+
driver.find_elements(*TRANSACTIONS_SELECTORS[:no_data_message].first).any?(&:displayed?)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Where there's nothing in the period, Westpac says so on the page rather than downloading anything, so either is waited for.
|
|
127
|
+
def export_csv(from_date:, to_date:)
|
|
122
128
|
clicked_at = Time.now
|
|
123
129
|
click(TRANSACTIONS_SELECTORS[:export_button])
|
|
124
|
-
|
|
130
|
+
download_wait.until{newest_download(since: clicked_at) || (no_data? && :no_data)}.tap do |download|
|
|
131
|
+
raise "No transactions from #{formatted_date(from_date)} to #{formatted_date(to_date)}." if download == :no_data
|
|
132
|
+
end
|
|
125
133
|
end
|
|
126
134
|
end
|
|
127
135
|
end
|
data/lib/WestpacComAu/VERSION.rb
CHANGED
|
@@ -75,14 +75,14 @@ describe WestpacComAu::Account do
|
|
|
75
75
|
account.define_singleton_method(:enter_dates){|from_date:, to_date:| steps << [:enter_dates, from_date, to_date]}
|
|
76
76
|
account.define_singleton_method(:select_bank_account){|account_number| steps << [:select_bank_account, account_number]}
|
|
77
77
|
account.define_singleton_method(:click){|selector| steps << [:click, selector]}
|
|
78
|
-
account.define_singleton_method(:export_csv){steps << :export_csv; '/downloads/transactions.csv'}
|
|
78
|
+
account.define_singleton_method(:export_csv){|from_date:, to_date:| steps << [:export_csv, from_date, to_date]; '/downloads/transactions.csv'}
|
|
79
79
|
[account, steps]
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
it "sets the dates, the account and CSV, and is the file exported" do
|
|
83
83
|
account, steps = account_recording_steps
|
|
84
84
|
_(account.download_transactions(account_number: '123456', from_date: '2026-10-01', to_date: '2026-10-31')).must_equal('/downloads/transactions.csv')
|
|
85
|
-
_(steps).must_equal([:get_transactions_page, [:enter_dates, '2026-10-01', '2026-10-31'], [:select_bank_account, '123456'], [:click, {id: 'File_type_1'}], :export_csv])
|
|
85
|
+
_(steps).must_equal([:get_transactions_page, [:enter_dates, '2026-10-01', '2026-10-31'], [:select_bank_account, '123456'], [:click, {id: 'File_type_1'}], [:export_csv, '2026-10-01', '2026-10-31']])
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
it "is the last year where neither a period nor a date is given" do
|
|
@@ -214,13 +214,35 @@ describe WestpacComAu::Account do
|
|
|
214
214
|
end
|
|
215
215
|
|
|
216
216
|
describe "#export_csv" do
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
def no_data_message
|
|
218
|
+
WestpacComAu::Account::TRANSACTIONS_SELECTORS[:no_data_message].first
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# An account which clicks nothing, and whose download directory has the download given, which is none unless given.
|
|
222
|
+
def account_exporting(driver, download: nil)
|
|
223
|
+
account = account_with_driver(driver)
|
|
219
224
|
clicked = []
|
|
220
225
|
account.define_singleton_method(:click){|selector| clicked << selector}
|
|
221
|
-
account.define_singleton_method(:
|
|
222
|
-
|
|
226
|
+
account.define_singleton_method(:newest_download){|since:| since.is_a?(Time) && download}
|
|
227
|
+
account.define_singleton_method(:default_download_timeout){0.1}
|
|
228
|
+
[account, clicked]
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
it "is the download which finishes after Export is clicked" do
|
|
232
|
+
account, clicked = account_exporting(stand_in_driver, download: '/downloads/transactions.csv')
|
|
233
|
+
_(account.send(:export_csv, from_date: Date.new(2026, 10, 1), to_date: Date.new(2026, 10, 31))).must_equal('/downloads/transactions.csv')
|
|
223
234
|
_(clicked).must_equal([{css: 'button.export-link'}])
|
|
224
235
|
end
|
|
236
|
+
|
|
237
|
+
it "stops, naming the dates, where Westpac says there's no data, rather than waiting out the download" do
|
|
238
|
+
account, _clicked = account_exporting(stand_in_driver(elements: {no_data_message => [stand_in_element]}))
|
|
239
|
+
error = _{account.send(:export_csv, from_date: Date.new(2026, 10, 1), to_date: Date.new(2026, 10, 31))}.must_raise(RuntimeError)
|
|
240
|
+
_(error.message).must_equal('No transactions from 01/10/2026 to 31/10/2026.')
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it "times out where there's neither a download nor the message" do
|
|
244
|
+
account, _clicked = account_exporting(stand_in_driver(elements: {no_data_message => [stand_in_element(displayed: false)]}))
|
|
245
|
+
_{account.send(:export_csv, from_date: Date.new(2026, 10, 1), to_date: Date.new(2026, 10, 31))}.must_raise(Selenium::WebDriver::Error::TimeoutError)
|
|
246
|
+
end
|
|
225
247
|
end
|
|
226
248
|
end
|