westpac_com_au 0.6.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 +7 -0
- data/CHANGELOG +193 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +107 -0
- data/Rakefile +9 -0
- data/lib/WestpacComAu/Account.rb +143 -0
- data/lib/WestpacComAu/Transactions.rb +18 -0
- data/lib/WestpacComAu/VERSION.rb +6 -0
- data/lib/westpac_com_au.rb +6 -0
- data/test/WestpacComAu/Account_test.rb +228 -0
- data/test/WestpacComAu/Transactions_test.rb +47 -0
- data/westpac_com_au.gemspec +49 -0
- metadata +122 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6c802d540cdab07de0bf66b0f599529a88b3b1e33089f78d0fbc05d505c3e32d
|
|
4
|
+
data.tar.gz: 1c30e9a6f93983fc4f66de84e58643f2e5c1ab3e9d9b5d86116dbb198ac75a05
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 379229a73a35a6d5f5cfa01daca3830db0fed959aa31c013e57c44e91e64f8948e89d7637ee89012220534a33506492b60636fb5680708eb9167ae4c394103d2
|
|
7
|
+
data.tar.gz: 686dfc31312f391deed97a193dbfb35824826daa7527c57ee374ebd6cc87c44fe0bc8fa2097ab00197039b42112b17e250b3f570ecf00cb382f3b3611b15bdae
|
data/CHANGELOG
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 20261116
|
|
4
|
+
|
|
5
|
+
0.6.0: Ready for publishing.
|
|
6
|
+
|
|
7
|
+
1. + westpac_com_au.gemspec
|
|
8
|
+
2. + CHANGELOG: With entries for 0.0.0 to 0.5.3 taken from their headers' change notes.
|
|
9
|
+
3. + Gemfile
|
|
10
|
+
4. + Rakefile
|
|
11
|
+
5. + LICENSE
|
|
12
|
+
6. + README.md
|
|
13
|
+
7. + lib/westpac_com_au.rb
|
|
14
|
+
8. + lib/WestpacComAu/VERSION.rb
|
|
15
|
+
9. ~ lib/WestpacComAu/Account.rb: - require 'Array/extract_optionsX', 'Date/self.last_year', 'Date/self.parse', 'Month', 'Selenium/WebDriver/SearchContext/ElementPresentQ/element_presentQ'; /require 'WebAccount'/require 'webaccount'/; + require 'date'.
|
|
16
|
+
10. /WestpacComAu::Account::PAGE_IDS/WestpacComAu::Account::PAGE_SELECTORS/: Follows the changes in WebAccount.
|
|
17
|
+
11. - WestpacComAu::Account#initialize: Use WebAccount superclass reading the PAGE_SELECTORS itself.
|
|
18
|
+
12. + WestpacComAu::Account#validate_args
|
|
19
|
+
13. ~ WestpacComAu::Account#login: Defer to WebAccount superclass.
|
|
20
|
+
14. - WestpacComAu::Account#logout: Use WebAccount superclass.
|
|
21
|
+
15. + WestpacComAu::Account::COOKIE_NOTICE_BUTTON_SELECTOR, #cookie_notice_button, #decline_cookies, #get_login_page: Accept essential cookies only.
|
|
22
|
+
16. ~ WestpacComAu::Account#download_transactions: Takes account_number:, period:, from_date: and to_date: as keywords, chooses CSV, and returns the name of the file downloaded.
|
|
23
|
+
17. - WestpacComAu::Account#download_custom_period_transactions, #download_last_months_transactions, #download_all_transactions
|
|
24
|
+
18. + WestpacComAu::Account#dates, #last_month_start_date, #last_month_finish_date
|
|
25
|
+
19. + WestpacComAu::Account::TRANSACTIONS_PAGE_URL, ::TRANSACTIONS_SELECTORS: The date fields are found by their ids.
|
|
26
|
+
20. - WestpacComAu::Account#download_submit_button, #from_date_field, #to_date_field, #bank_account_field, #enter_from_date, #enter_to_date
|
|
27
|
+
21. ~ WestpacComAu::Account#enter_dates: The dates are set by WebAccount's set_value, the date picker throwing typed dates away; and it stops where they didn't take, rather than exporting another range.
|
|
28
|
+
22. + WestpacComAu::Account#export_csv
|
|
29
|
+
23. ~ WestpacComAu::Account#get_transactions_page: Waits for the date fields rather than sleeping, and declines the cookie notice.
|
|
30
|
+
24. ~ lib/WestpacComAu/Account.rb: - self-run block
|
|
31
|
+
25. /class WestpacComAu::Transactions/module WestpacComAu::Transactions/; - require 'Array/all_but_first', 'Date/last_year', 'fileutils', 'time'; /require 'WestpacComAu/Account'/require_relative './Account'/.
|
|
32
|
+
26. ~ WestpacComAu::Transactions.download_csv_file: Takes username:, password:, period:, from_date:, to_date: and web_account_options:, and returns the name of the file downloaded. The account is shut down even where the download fails.
|
|
33
|
+
27. - WestpacComAu::Transactions.csv_filename: Use name of the file being downloaded.
|
|
34
|
+
28. + test/WestpacComAu/Account_test.rb
|
|
35
|
+
29. + test/WestpacComAu/Transactions_test.rb
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## 20210217
|
|
39
|
+
|
|
40
|
+
0.5.3: ~ WestpacComAu::Account#login: Waits for the dashboard again.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## 20200529
|
|
44
|
+
|
|
45
|
+
0.5.2: /require 'Selenium/WebDriver/SearchContext/ElementTests'/require 'Selenium/WebDriver/SearchContext/ElementPresentQ/element_presentQ'/
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## 20191013
|
|
49
|
+
|
|
50
|
+
0.5.1: /require 'Month.rbd/Month'/require 'Month'/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## 20190908
|
|
54
|
+
|
|
55
|
+
0.5.0: Westpac replaced the password keypad with a password field, and changed its account field.
|
|
56
|
+
|
|
57
|
+
1. ~ PAGE_IDS: + login_page_password_field_id, and it's WestpacComAu::Account::PAGE_IDS.
|
|
58
|
+
2. - WestpacComAu::Account#enter_password, #password_button: WebAccount's types the password into the field.
|
|
59
|
+
3. ~ WestpacComAu::Account#bank_account_field: Accounts_1
|
|
60
|
+
4. ~ WestpacComAu::Account#select_bank_account: Presses Enter after the account number.
|
|
61
|
+
5. ~ WestpacComAu::Account#login: Sets @logged_in rather than waiting for the dashboard, the wait failing.
|
|
62
|
+
6. ~ WestpacComAu::Account: /@driver/driver/
|
|
63
|
+
7. + lib/WestpacComAu/Transactions.rb: WestpacComAu::Transactions.download_csv_file removes the day's export from the Downloads directory, then logs in, downloads an account's transactions from a date to today, and shuts down.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## 20171223
|
|
67
|
+
|
|
68
|
+
0.4.0: ~ WestpacComAu::Account is a WebAccount, taking username: in place of customer_id:.
|
|
69
|
+
|
|
70
|
+
1. /lib/WestpacComAu.rb/lib/WestpacComAu/Account.rb/
|
|
71
|
+
2. + require 'WebAccount'
|
|
72
|
+
3. + PAGE_IDS: The login page's URL, username field and submit button.
|
|
73
|
+
4. ~ WestpacComAu::Account#initialize: Takes username: and password:, and passes them with PAGE_IDS to WebAccount.
|
|
74
|
+
5. ~ WestpacComAu::Account#login: Takes username: and password:, and logs in with WebAccount's methods.
|
|
75
|
+
6. ~ WestpacComAu::Account#enter_password, #password_button: Override WebAccount's, the password being clicked in on the keypad.
|
|
76
|
+
7. - WestpacComAu::Account#customer_id, #password, #shutdown, #logged_in?, #enter_customer_id, #customer_id_field, #sign_in: WebAccount's do the same.
|
|
77
|
+
8. /WestpacComAu::Account#submit_button/WestpacComAu::Account#download_submit_button/, the export button alone.
|
|
78
|
+
9. ~ lib/WestpacComAu/Account.rb: Run from the command line, it logs in with the username and password given, downloads the transactions, and shuts down.
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## 20160820
|
|
82
|
+
|
|
83
|
+
0.3.0: Westpac renamed its username field and its submit button, and made the password keypad's keys buttons.
|
|
84
|
+
|
|
85
|
+
1. ~ WestpacComAu::Account#customer_id_field: fakeusername
|
|
86
|
+
2. ~ WestpacComAu::Account#password_button: The keypad's <button> bearing the character.
|
|
87
|
+
3. ~ WestpacComAu::Account#submit_button: signin
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
## 20160403
|
|
91
|
+
|
|
92
|
+
0.2.0: Westpac's account selection changed from a select list to a field.
|
|
93
|
+
|
|
94
|
+
1. /WestpacComAu::Account#bank_account_dropdown_list/WestpacComAu::Account#bank_account_field/
|
|
95
|
+
2. ~ WestpacComAu::Account#select_bank_account: Types the account number into the field.
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## 20150208
|
|
99
|
+
|
|
100
|
+
0.1.0: Westpac's link to the transactions export changed, and its export button lost its id.
|
|
101
|
+
|
|
102
|
+
1. ~ WestpacComAu::Account#get_transactions_page: Goes straight to the transactions export.
|
|
103
|
+
2. ~ WestpacComAu::Account#submit_button: The export button is found by .export-link.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## 20140801
|
|
107
|
+
|
|
108
|
+
0.0.14: ~ WestpacComAu::Account#initialize: The wait is 180 seconds rather than 60.
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
## 20140720
|
|
112
|
+
|
|
113
|
+
0.0.13: ~ WestpacComAu::Account#login: Overview.Accounts.List counts as logged in, as well as overview-dashboard.
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
## 20140629
|
|
117
|
+
|
|
118
|
+
0.0.12: ~ WestpacComAu::Account#initialize: The wait is 60 seconds rather than 30.
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
0.0.11: ~ WestpacComAu::Account#download_transactions: + period: :all, the last year; and the dates default to the last year.
|
|
122
|
+
|
|
123
|
+
1. + WestpacComAu::Account#download_all_transactions, #enter_dates
|
|
124
|
+
2. ~ WestpacComAu::Account#download_last_months_transactions: Goes through #download_custom_period_transactions.
|
|
125
|
+
3. - WestpacComAu::Account#last_month_from_date, #last_month_to_date, #enter_last_month_first_date, #enter_last_month_last_date
|
|
126
|
+
4. /WestpacComAu::Account#select_bank_account_from_dropdown_list/WestpacComAu::Account#select_bank_account/
|
|
127
|
+
5. + require 'Date/self.last_year'
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
0.0.10: + WestpacComAu::Account#download_custom_period_transactions, taking from_date: and to_date:.
|
|
131
|
+
|
|
132
|
+
1. ~ WestpacComAu::Account#download_transactions: period: :last_month, or otherwise the dates given.
|
|
133
|
+
2. /WestpacComAu::Account#last_months_transactions/WestpacComAu::Account#download_last_months_transactions/
|
|
134
|
+
3. + WestpacComAu::Account#enter_from_date, #enter_to_date, #formatted_date
|
|
135
|
+
4. - WestpacComAu::Account#last_month_number, #last_month_year, #last_month_date_common_parts, #last_month_first_date, #last_month_last_date
|
|
136
|
+
5. + WestpacComAu::Account#last_month_from_date, #last_month_to_date: Month.last's start and finish dates.
|
|
137
|
+
6. + require 'Date/self.parse'
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
0.0.9: ~ WestpacComAu::Account#login: The "Multiple sessions" page is no longer handled.
|
|
141
|
+
|
|
142
|
+
1. + WestpacComAu::Account#from_date_field, #to_date_field, #enter_last_month_first_date, #enter_last_month_last_date, #bank_account_dropdown_list
|
|
143
|
+
2. + WestpacComAu::Account#select_bank_account_from_dropdown_list, which raises where the account isn't in the list.
|
|
144
|
+
3. ~ WestpacComAu::Account#last_months_transactions: Enters the to date before the from date, the from date's picker covering the to field.
|
|
145
|
+
4. ~ WestpacComAu::Account#logout: + the "Multiple sessions" page's Sign out link.
|
|
146
|
+
5. ~ WestpacComAu::Account#submit_button: Where there's no btn-submit, it's the first button, which exports.
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
0.0.8: ~ WestpacComAu::Account#login: From a "Multiple sessions" page, it logs out and signs in again.
|
|
150
|
+
|
|
151
|
+
1. ~ WestpacComAu::Account#logout: Where there's no Sign Out link, the logout URL is gone to.
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
## 20140628, 29
|
|
155
|
+
|
|
156
|
+
0.0.7: ~ WestpacComAu::Account#login: A "Multiple sessions" page is waited on until the dashboard appears.
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
## 20140628
|
|
160
|
+
|
|
161
|
+
0.0.6: + WestpacComAu::Account#shutdown, which logs out and quits the browser.
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
0.0.5: + WestpacComAu::Account#logout
|
|
165
|
+
|
|
166
|
+
1. ~ WestpacComAu::Account#last_months_transactions: Waits 10 seconds after exporting.
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
0.0.4: ~ WestpacComAu::Account#last_months_transactions: The export button is clicked.
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
0.0.3: ~ WestpacComAu::Account#download_transactions: + period:, + account_number:, the account being chosen from the list.
|
|
173
|
+
|
|
174
|
+
1. ~ WestpacComAu::Account#last_months_transactions: + account_number
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
0.0.2: + WestpacComAu::Account#download_transactions, entering last month's dates on the transactions export.
|
|
178
|
+
|
|
179
|
+
1. + WestpacComAu::Account#last_months_transactions
|
|
180
|
+
2. + WestpacComAu::Account#last_month_number, #last_month_year, #last_month_date_common_parts, #last_month_first_date, #last_month_last_date
|
|
181
|
+
3. + require 'Month.rbd/Month'
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
0.0.1: + WestpacComAu::Account#get_transactions_page, which goes from Reports and Exports to the transactions export, logging in first where it isn't.
|
|
185
|
+
|
|
186
|
+
1. ~ WestpacComAu::Account#initialize: /@http_client/@driver/, with a wait of 30 seconds.
|
|
187
|
+
2. ~ WestpacComAu::Account#login: Waits for the dashboard.
|
|
188
|
+
3. + WestpacComAu::Account#logged_in?
|
|
189
|
+
4. + require 'Selenium/WebDriver/SearchContext/ElementTests'
|
|
190
|
+
5. ~ lib/WestpacComAu.rb: The notes of the login page's ids are removed.
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
0.0.0: + lib/WestpacComAu.rb: WestpacComAu::Account logs into Westpac Online Banking with a customer ID, clicking the password in on the keypad.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2026 thoran
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# westpac_com_au
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
Log into Westpac Online Banking (banking.westpac.com.au) and export an account's transactions as a CSV file.
|
|
6
|
+
|
|
7
|
+
It drives a browser via Selenium WebDriver and WebAccount.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Add this line to your application's Gemfile:
|
|
12
|
+
```ruby
|
|
13
|
+
gem 'westpac_com_au'
|
|
14
|
+
```
|
|
15
|
+
And then execute:
|
|
16
|
+
```shell
|
|
17
|
+
$ bundle
|
|
18
|
+
```
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
```shell
|
|
21
|
+
$ gem install westpac_com_au
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Downloading transactions
|
|
27
|
+
```ruby
|
|
28
|
+
require 'westpac_com_au'
|
|
29
|
+
|
|
30
|
+
westpac_account = WestpacComAu::Account.new(username: customer_id, password: password)
|
|
31
|
+
westpac_account.login
|
|
32
|
+
westpac_account.download_transactions(account_number: '123456')
|
|
33
|
+
# => "/Users/me/Downloads/Data_export_16112026.csv"
|
|
34
|
+
westpac_account.shutdown # Logs out if still logged in, then quits the browser.
|
|
35
|
+
```
|
|
36
|
+
The account number is typed into the export page's account field, and the account Westpac suggests for it is taken. The transactions are exported as CSV.
|
|
37
|
+
|
|
38
|
+
Without a period or dates, they're those of the last year. Otherwise:
|
|
39
|
+
```ruby
|
|
40
|
+
westpac_account.download_transactions(account_number: '123456', period: :last_month)
|
|
41
|
+
westpac_account.download_transactions(account_number: '123456', period: :all) # The last year.
|
|
42
|
+
westpac_account.download_transactions(account_number: '123456', from_date: '2026-01-01', to_date: '2026-06-30')
|
|
43
|
+
```
|
|
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
|
+
|
|
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.
|
|
47
|
+
|
|
48
|
+
Or in one step, logging in, downloading, and shutting down even where the download fails:
|
|
49
|
+
```ruby
|
|
50
|
+
WestpacComAu::Transactions.download_csv_file(account_number: '123456', username: customer_id, password: password, period: :last_month)
|
|
51
|
+
```
|
|
52
|
+
It takes `period:`, `from_date:` and `to_date:` as `download_transactions` does. `web_account_options:` are passed to `WestpacComAu::Account.new`:
|
|
53
|
+
```ruby
|
|
54
|
+
WestpacComAu::Transactions.download_csv_file(account_number: '123456', username: customer_id, password: password, web_account_options: {download_directory: '~/path/to/statements'})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Credentials
|
|
58
|
+
|
|
59
|
+
The username is the customer ID. It and the password are given, or set afterwards:
|
|
60
|
+
```ruby
|
|
61
|
+
westpac_account.username, westpac_account.password = customer_id, password
|
|
62
|
+
```
|
|
63
|
+
Where either is missing, `login` raises ArgumentError before starting the browser, naming every one missing.
|
|
64
|
+
|
|
65
|
+
### The browser
|
|
66
|
+
|
|
67
|
+
The browser is WebAccount's: Chrome, unless `browser: :firefox` is given. Given a `profile_directory`, it's started with that profile, kept between runs; without one, each run has a new, temporary profile.
|
|
68
|
+
```ruby
|
|
69
|
+
WestpacComAu::Account.new(profile_directory: '~/path/to/profile')
|
|
70
|
+
```
|
|
71
|
+
It downloads into `download_directory`, `~/Downloads` unless given, without asking where. `headless:`, `window_size:` and `user_agent:` are passed to WebAccount too, and `driver_options:` replaces the browser's options altogether.
|
|
72
|
+
|
|
73
|
+
Where Westpac's cookie notice is showing, Accept essential only is clicked. Where Westpac asks for a one-time code after signing in, `login` waits up to 30 seconds for it to be entered in the browser.
|
|
74
|
+
|
|
75
|
+
## Westpac's site
|
|
76
|
+
|
|
77
|
+
Each version worked against Westpac's site of its time. Only the latest is meant to work now.
|
|
78
|
+
|
|
79
|
+
| Westpac's site | Seen | WestpacComAu |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| Keypad password, select list of accounts, export reached from the reports page | 20140628 | 0.0.0–0.0.14 |
|
|
82
|
+
| Export link moved, submit button lost its id | by 20150208 | 0.1.0 |
|
|
83
|
+
| Account chosen in a text field | by 20160403 | 0.2.0 |
|
|
84
|
+
| Username field, keypad buttons and submit button renamed | by 20160820 | 0.3.0–0.4.0 |
|
|
85
|
+
| Keypad replaced by a password field; account field changed | about 2018, met 20190908 | 0.5.0–0.5.3 |
|
|
86
|
+
| Login at banking.westpac.com.au, a signed-out page | by 2023 | 0.6.0 |
|
|
87
|
+
| A cookie notice | 2026 | 0.6.0 |
|
|
88
|
+
|
|
89
|
+
## Limitations
|
|
90
|
+
|
|
91
|
+
The selectors were taken from the live site, and a change to it will break them.
|
|
92
|
+
|
|
93
|
+
Each key of `WestpacComAu::Account::PAGE_SELECTORS` is also a keyword of `new`, and has a setter, either of which wins over Westpac's, so as a selector which has changed can be given without waiting for a new version:
|
|
94
|
+
```ruby
|
|
95
|
+
WestpacComAu::Account.new(logout_button_selector: {xpath: '//a[normalize-space()="Sign out"]'})
|
|
96
|
+
westpac_account.logged_out_selector = {css: 'form#logout'}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The tests cover only what doesn't depend on Westpac's site.
|
|
100
|
+
|
|
101
|
+
## Contributing
|
|
102
|
+
|
|
103
|
+
1. Fork it: https://github.com/thoran/westpac_com_au/fork
|
|
104
|
+
2. Create your feature branch: `git checkout -b my-new-feature`
|
|
105
|
+
3. Commit your changes: `git commit -am 'Add some feature'`
|
|
106
|
+
4. Push to the branch: `git push origin my-new-feature`
|
|
107
|
+
5. Create a new pull request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# WestpacComAu/Account.rb
|
|
2
|
+
# WestpacComAu::Account
|
|
3
|
+
|
|
4
|
+
# Notes:
|
|
5
|
+
# 1. Westpac shows a cookie notice, drawn by Didomi, on the login page and at times on later pages. Where it's showing, Accept essential only is clicked before going on.
|
|
6
|
+
# 2. The Sign Out link has no id, so it's found by its text. It's what login waits for, as it's on every page after logging in.
|
|
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
|
+
# 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
|
+
# 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.
|
|
11
|
+
|
|
12
|
+
require 'date'
|
|
13
|
+
require 'webaccount'
|
|
14
|
+
|
|
15
|
+
module WestpacComAu
|
|
16
|
+
class Account < WebAccount
|
|
17
|
+
PAGE_SELECTORS = {
|
|
18
|
+
login_page_url: 'https://banking.westpac.com.au/wbc/banking/handler?TAM_OP=login&segment=personal&logout=false',
|
|
19
|
+
login_page_username_field_selector: {id: 'fakeusername'},
|
|
20
|
+
login_page_password_field_selector: {id: 'password'},
|
|
21
|
+
login_page_submit_button_selector: {id: 'signin'},
|
|
22
|
+
logout_button_selector: {xpath: '//a[normalize-space()="Sign Out"]'},
|
|
23
|
+
logged_out_selector: {css: 'form#logout, form#login'}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
COOKIE_NOTICE_BUTTON_SELECTOR = {id: 'didomi-notice-disagree-button'}
|
|
27
|
+
|
|
28
|
+
TRANSACTIONS_PAGE_URL = 'https://banking.westpac.com.au/secure/banking/reportsandexports/exportparameters/2/'
|
|
29
|
+
|
|
30
|
+
TRANSACTIONS_SELECTORS = {
|
|
31
|
+
from_date_field: {id: 'DateRange_StartDate'},
|
|
32
|
+
to_date_field: {id: 'DateRange_EndDate'},
|
|
33
|
+
account_field: {id: 'Accounts_1'},
|
|
34
|
+
csv_radio_button: {id: 'File_type_1'},
|
|
35
|
+
export_button: {css: 'button.export-link'}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
def login(username: nil, password: nil)
|
|
39
|
+
validate_args(username: username || self.username, password: password || self.password)
|
|
40
|
+
super
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# 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.
|
|
44
|
+
def download_transactions(account_number:, period: nil, from_date: nil, to_date: nil)
|
|
45
|
+
from_date, to_date = dates(period: period, from_date: from_date, to_date: to_date)
|
|
46
|
+
get_transactions_page
|
|
47
|
+
enter_dates(from_date: from_date, to_date: to_date)
|
|
48
|
+
select_bank_account(account_number)
|
|
49
|
+
click(TRANSACTIONS_SELECTORS[:csv_radio_button])
|
|
50
|
+
export_csv
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def validate_args(args)
|
|
56
|
+
missing_args = []
|
|
57
|
+
args.each do |arg_name, value|
|
|
58
|
+
missing_args << arg_name unless value
|
|
59
|
+
end
|
|
60
|
+
return if missing_args.empty?
|
|
61
|
+
aggregate_error = missing_args.join(', ')
|
|
62
|
+
copula = missing_args.count > 1 ? 'are' : 'is'
|
|
63
|
+
raise ArgumentError, "#{aggregate_error} #{copula} missing."
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# cookie notice
|
|
67
|
+
|
|
68
|
+
# Didomi draws its notice once the page has loaded, so it's waited for briefly. Where the choice is remembered, as in a profile kept between runs, there's none.
|
|
69
|
+
def cookie_notice_button
|
|
70
|
+
find_wait.until{driver.find_elements(*COOKIE_NOTICE_BUTTON_SELECTOR.first).detect(&:displayed?)}
|
|
71
|
+
rescue Selenium::WebDriver::Error::TimeoutError
|
|
72
|
+
nil
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def decline_cookies
|
|
76
|
+
cookie_notice_button&.click
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# logging in
|
|
80
|
+
|
|
81
|
+
def get_login_page
|
|
82
|
+
super
|
|
83
|
+
decline_cookies
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# dates
|
|
87
|
+
|
|
88
|
+
def last_month_start_date
|
|
89
|
+
Date.today.prev_month - (Date.today.prev_month.day - 1)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def last_month_finish_date
|
|
93
|
+
Date.today - Date.today.day
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def dates(period:, from_date:, to_date:)
|
|
97
|
+
case period
|
|
98
|
+
when :all then [Date.today.prev_year, Date.today]
|
|
99
|
+
when :last_month then [last_month_start_date, last_month_finish_date]
|
|
100
|
+
when nil then [from_date || Date.today.prev_year, to_date || Date.today]
|
|
101
|
+
else raise ArgumentError, "Unknown period #{period.inspect}: it's :all or :last_month."
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def formatted_date(date)
|
|
106
|
+
date = Date.parse(date) if date.is_a?(String)
|
|
107
|
+
date.strftime('%d/%m/%Y')
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# transactions
|
|
111
|
+
|
|
112
|
+
def get_transactions_page
|
|
113
|
+
login unless logged_in?
|
|
114
|
+
driver.get(TRANSACTIONS_PAGE_URL)
|
|
115
|
+
wait_for(TRANSACTIONS_SELECTORS[:from_date_field])
|
|
116
|
+
decline_cookies
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Set by WebAccount's set_value, typed dates being thrown away by the date picker; and stops where the values didn't take, rather than exporting another range.
|
|
120
|
+
def enter_dates(from_date:, to_date:)
|
|
121
|
+
from_date_field, to_date_field = find(TRANSACTIONS_SELECTORS[:from_date_field]), find(TRANSACTIONS_SELECTORS[:to_date_field])
|
|
122
|
+
set_value(from_date_field, formatted_date(from_date))
|
|
123
|
+
set_value(to_date_field, formatted_date(to_date))
|
|
124
|
+
unless [from_date_field, to_date_field].map{|field| field.attribute('value')} == [formatted_date(from_date), formatted_date(to_date)]
|
|
125
|
+
raise "The dates #{formatted_date(from_date)} to #{formatted_date(to_date)} didn't take."
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# The account field suggests accounts as the number is typed, and Enter takes the suggestion.
|
|
130
|
+
def select_bank_account(account_number)
|
|
131
|
+
account_field = find(TRANSACTIONS_SELECTORS[:account_field])
|
|
132
|
+
account_field.send_keys(account_number)
|
|
133
|
+
sleep 1
|
|
134
|
+
account_field.send_keys(Selenium::WebDriver::Keys[:return])
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def export_csv
|
|
138
|
+
clicked_at = Time.now
|
|
139
|
+
click(TRANSACTIONS_SELECTORS[:export_button])
|
|
140
|
+
wait_for_download(since: clicked_at)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# WestpacComAu/Transactions.rb
|
|
2
|
+
# WestpacComAu::Transactions
|
|
3
|
+
|
|
4
|
+
require_relative './Account'
|
|
5
|
+
|
|
6
|
+
module WestpacComAu
|
|
7
|
+
module Transactions
|
|
8
|
+
class << self
|
|
9
|
+
# web_account_options go to WestpacComAu::Account.new as they are, as browser:, profile_directory:, download_directory: and the like. Returns the name of the CSV file downloaded.
|
|
10
|
+
def download_csv_file(account_number:, username: nil, password: nil, period: nil, from_date: nil, to_date: nil, web_account_options: {})
|
|
11
|
+
westpac_account = WestpacComAu::Account.new(username: username, password: password, **web_account_options)
|
|
12
|
+
westpac_account.download_transactions(account_number: account_number, period: period, from_date: from_date, to_date: to_date)
|
|
13
|
+
ensure
|
|
14
|
+
westpac_account&.shutdown
|
|
15
|
+
end
|
|
16
|
+
end # class << self
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# test/WestpacComAu/Account_test.rb
|
|
2
|
+
|
|
3
|
+
# Notes:
|
|
4
|
+
# 1. No browser and no Westpac: only what doesn't depend on the site is tested. Every account which might reach for its browser is given a stand-in, so as none is started.
|
|
5
|
+
|
|
6
|
+
require_relative '../../lib/westpac_com_au'
|
|
7
|
+
|
|
8
|
+
require 'date'
|
|
9
|
+
require 'minitest/autorun'
|
|
10
|
+
require 'minitest-spec-context'
|
|
11
|
+
|
|
12
|
+
describe WestpacComAu::Account do
|
|
13
|
+
def stand_in_element(displayed: true)
|
|
14
|
+
element = Object.new
|
|
15
|
+
element.define_singleton_method(:displayed?){displayed}
|
|
16
|
+
element.define_singleton_method(:click){@clicked = true}
|
|
17
|
+
element.define_singleton_method(:clicked?){!!@clicked}
|
|
18
|
+
element.define_singleton_method(:clear){(@keys ||= []) << :clear}
|
|
19
|
+
element.define_singleton_method(:send_keys){|keys| (@keys ||= []) << keys}
|
|
20
|
+
element.define_singleton_method(:keys){@keys || []}
|
|
21
|
+
element
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Finds the elements given for each selector type and value, and none for any other.
|
|
25
|
+
def stand_in_driver(elements: {})
|
|
26
|
+
driver = Object.new
|
|
27
|
+
driver.define_singleton_method(:find_elements){|type, value| elements.fetch([type, value], [])}
|
|
28
|
+
driver.define_singleton_method(:get){|url| (@urls ||= []) << url}
|
|
29
|
+
driver.define_singleton_method(:urls){@urls || []}
|
|
30
|
+
driver
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def account_with_driver(driver, **args)
|
|
34
|
+
account = WestpacComAu::Account.new(**args)
|
|
35
|
+
account.instance_variable_set(:@driver, driver)
|
|
36
|
+
account.instance_variable_set(:@logged_in, true)
|
|
37
|
+
account.define_singleton_method(:default_find_timeout){0.1}
|
|
38
|
+
account
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe "#username and #password" do
|
|
42
|
+
it "are those given" do
|
|
43
|
+
account = WestpacComAu::Account.new(username: 'customer', password: 'secret')
|
|
44
|
+
_(account.username).must_equal('customer')
|
|
45
|
+
_(account.password).must_equal('secret')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "can be set after construction" do
|
|
49
|
+
account = WestpacComAu::Account.new
|
|
50
|
+
account.username, account.password = 'customer', 'secret'
|
|
51
|
+
_(account.username).must_equal('customer')
|
|
52
|
+
_(account.password).must_equal('secret')
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "#login" do
|
|
57
|
+
it "names the one missing, before starting the browser" do
|
|
58
|
+
account = WestpacComAu::Account.new(username: 'customer')
|
|
59
|
+
_(_{account.login}.must_raise(ArgumentError).message).must_equal('password is missing.')
|
|
60
|
+
_(account.instance_variable_get(:@driver)).must_be_nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "names both where both are missing" do
|
|
64
|
+
_(_{WestpacComAu::Account.new.login}.must_raise(ArgumentError).message).must_equal('username, password are missing.')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "takes either given to login itself as given" do
|
|
68
|
+
_(_{WestpacComAu::Account.new.login(username: 'customer')}.must_raise(ArgumentError).message).must_equal('password is missing.')
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe "#download_transactions" do
|
|
73
|
+
def account_recording_steps
|
|
74
|
+
account = account_with_driver(stand_in_driver)
|
|
75
|
+
steps = []
|
|
76
|
+
account.define_singleton_method(:get_transactions_page){steps << :get_transactions_page}
|
|
77
|
+
account.define_singleton_method(:enter_dates){|from_date:, to_date:| steps << [:enter_dates, from_date, to_date]}
|
|
78
|
+
account.define_singleton_method(:select_bank_account){|account_number| steps << [:select_bank_account, account_number]}
|
|
79
|
+
account.define_singleton_method(:click){|selector| steps << [:click, selector]}
|
|
80
|
+
account.define_singleton_method(:export_csv){steps << :export_csv; '/downloads/transactions.csv'}
|
|
81
|
+
[account, steps]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "sets the dates, the account and CSV, and is the file exported" do
|
|
85
|
+
account, steps = account_recording_steps
|
|
86
|
+
_(account.download_transactions(account_number: '123456', from_date: '2026-10-01', to_date: '2026-10-31')).must_equal('/downloads/transactions.csv')
|
|
87
|
+
_(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])
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "is the last year where neither a period nor a date is given" do
|
|
91
|
+
account, steps = account_recording_steps
|
|
92
|
+
account.download_transactions(account_number: '123456')
|
|
93
|
+
_(steps[1]).must_equal([:enter_dates, Date.today.prev_year, Date.today])
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "requires an account number, before going to the transactions page" do
|
|
97
|
+
account, steps = account_recording_steps
|
|
98
|
+
_(_{account.download_transactions}.must_raise(ArgumentError).message).must_equal('missing keyword: :account_number')
|
|
99
|
+
_(steps).must_be_empty
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
describe "the selectors" do
|
|
104
|
+
it "are Westpac's where none is given" do
|
|
105
|
+
account = WestpacComAu::Account.new
|
|
106
|
+
_(account.login_page_url).must_equal('https://banking.westpac.com.au/wbc/banking/handler?TAM_OP=login&segment=personal&logout=false')
|
|
107
|
+
_(account.login_page_username_field_selector).must_equal({id: 'fakeusername'})
|
|
108
|
+
_(account.login_page_password_field_selector).must_equal({id: 'password'})
|
|
109
|
+
_(account.login_page_submit_button_selector).must_equal({id: 'signin'})
|
|
110
|
+
_(account.logout_button_selector).must_equal({xpath: '//a[normalize-space()="Sign Out"]'})
|
|
111
|
+
_(account.logged_out_selector).must_equal({css: 'form#logout, form#login'})
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "are those given to new, or set afterwards, over Westpac's" do
|
|
115
|
+
account = WestpacComAu::Account.new(logout_button_selector: {id: 'signout'})
|
|
116
|
+
account.logged_out_selector = {css: 'form#logout'}
|
|
117
|
+
_(account.logout_button_selector).must_equal({id: 'signout'})
|
|
118
|
+
_(account.logged_out_selector).must_equal({css: 'form#logout'})
|
|
119
|
+
_(account.login_page_username_field_selector).must_equal({id: 'fakeusername'})
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe "the cookie notice" do
|
|
124
|
+
it "is declined, with Accept essential only, where it's showing" do
|
|
125
|
+
button = stand_in_element
|
|
126
|
+
account = account_with_driver(stand_in_driver(elements: {[:id, 'didomi-notice-disagree-button'] => [button]}))
|
|
127
|
+
account.send(:decline_cookies)
|
|
128
|
+
_(button.clicked?).must_equal(true)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "is left where it's there but not showing" do
|
|
132
|
+
button = stand_in_element(displayed: false)
|
|
133
|
+
account = account_with_driver(stand_in_driver(elements: {[:id, 'didomi-notice-disagree-button'] => [button]}))
|
|
134
|
+
_(account.send(:decline_cookies)).must_be_nil
|
|
135
|
+
_(button.clicked?).must_equal(false)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "is passed over where there's none" do
|
|
139
|
+
account = account_with_driver(stand_in_driver)
|
|
140
|
+
_(account.send(:decline_cookies)).must_be_nil
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "is declined on getting the login page" do
|
|
144
|
+
button = stand_in_element
|
|
145
|
+
driver = stand_in_driver(elements: {[:id, 'didomi-notice-disagree-button'] => [button]})
|
|
146
|
+
account = account_with_driver(driver)
|
|
147
|
+
account.send(:get_login_page)
|
|
148
|
+
_(driver.urls).must_equal([WestpacComAu::Account::PAGE_SELECTORS[:login_page_url]])
|
|
149
|
+
_(button.clicked?).must_equal(true)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
describe "#dates" do
|
|
154
|
+
def dates(**args)
|
|
155
|
+
WestpacComAu::Account.new.send(:dates, **{period: nil, from_date: nil, to_date: nil}.merge(args))
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it "is the last year for :all" do
|
|
159
|
+
_(dates(period: :all)).must_equal([Date.today.prev_year, Date.today])
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "is last month for :last_month" do
|
|
163
|
+
today = Date.today
|
|
164
|
+
_(dates(period: :last_month)).must_equal([Date.new(today.prev_month.year, today.prev_month.month, 1), Date.new(today.year, today.month, 1) - 1])
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it "is the dates given, defaulting either to a year ago or today" do
|
|
168
|
+
_(dates(from_date: '2026-01-01', to_date: '2026-02-01')).must_equal(['2026-01-01', '2026-02-01'])
|
|
169
|
+
_(dates(from_date: '2026-01-01')).must_equal(['2026-01-01', Date.today])
|
|
170
|
+
_(dates(to_date: '2026-02-01')).must_equal([Date.today.prev_year, '2026-02-01'])
|
|
171
|
+
_(dates).must_equal([Date.today.prev_year, Date.today])
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "refuses a period it doesn't know" do
|
|
175
|
+
_{dates(period: :fortnight)}.must_raise(ArgumentError)
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
describe "#formatted_date" do
|
|
180
|
+
it "is day/month/year, from a Date or a String" do
|
|
181
|
+
account = WestpacComAu::Account.new
|
|
182
|
+
_(account.send(:formatted_date, Date.new(2026, 3, 4))).must_equal('04/03/2026')
|
|
183
|
+
_(account.send(:formatted_date, '2026-03-04')).must_equal('04/03/2026')
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
describe "#enter_dates" do
|
|
188
|
+
def stand_in_date_field(value)
|
|
189
|
+
field = Object.new
|
|
190
|
+
field.instance_variable_set(:@value, value)
|
|
191
|
+
field.define_singleton_method(:attribute){|name| @value if name == 'value'}
|
|
192
|
+
field.define_singleton_method(:value=){|value| @value = value}
|
|
193
|
+
field
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# An account whose set_value() sets the field, or, where the page throws the value away, doesn't.
|
|
197
|
+
def account_with_date_fields(from_field, to_field, taking: true)
|
|
198
|
+
account = account_with_driver(stand_in_driver)
|
|
199
|
+
account.define_singleton_method(:find){|selector| selector == {id: 'DateRange_StartDate'} ? from_field : to_field}
|
|
200
|
+
account.define_singleton_method(:set_value){|field, value| field.value = value if taking}
|
|
201
|
+
account
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
it "sets the from and to fields" do
|
|
205
|
+
from_field, to_field = stand_in_date_field('16/11/2026'), stand_in_date_field('16/11/2026')
|
|
206
|
+
account = account_with_date_fields(from_field, to_field)
|
|
207
|
+
account.send(:enter_dates, from_date: Date.new(2026, 10, 1), to_date: Date.new(2026, 10, 31))
|
|
208
|
+
_([from_field, to_field].map{|field| field.attribute('value')}).must_equal(['01/10/2026', '31/10/2026'])
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it "says so where the dates didn't take, rather than exporting another range" do
|
|
212
|
+
account = account_with_date_fields(stand_in_date_field('16/11/2026'), stand_in_date_field('16/11/2026'), taking: false)
|
|
213
|
+
error = _{account.send(:enter_dates, from_date: Date.new(2026, 10, 1), to_date: Date.new(2026, 10, 31))}.must_raise(RuntimeError)
|
|
214
|
+
_(error.message).must_include('01/10/2026 to 31/10/2026')
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
describe "#export_csv" do
|
|
219
|
+
it "is the download which finishes after Export is clicked" do
|
|
220
|
+
account = account_with_driver(stand_in_driver)
|
|
221
|
+
clicked = []
|
|
222
|
+
account.define_singleton_method(:click){|selector| clicked << selector}
|
|
223
|
+
account.define_singleton_method(:wait_for_download){|since:| since.is_a?(Time) && '/downloads/transactions.csv'}
|
|
224
|
+
_(account.send(:export_csv)).must_equal('/downloads/transactions.csv')
|
|
225
|
+
_(clicked).must_equal([{css: 'button.export-link'}])
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# test/WestpacComAu/Transactions_test.rb
|
|
2
|
+
|
|
3
|
+
# Notes:
|
|
4
|
+
# 1. WestpacComAu::Account.new is swapped for a stand-in for the length of each example and put back afterwards, so as no browser is started.
|
|
5
|
+
|
|
6
|
+
require_relative '../../lib/westpac_com_au'
|
|
7
|
+
|
|
8
|
+
require 'minitest/autorun'
|
|
9
|
+
require 'minitest-spec-context'
|
|
10
|
+
|
|
11
|
+
describe WestpacComAu::Transactions do
|
|
12
|
+
def with_stand_in_account(download: ->{'/downloads/transactions.csv'})
|
|
13
|
+
account = Object.new
|
|
14
|
+
account.define_singleton_method(:download_transactions){|account_number:, **dates| (@asked ||= []) << [account_number, dates]; download.call}
|
|
15
|
+
account.define_singleton_method(:asked){@asked}
|
|
16
|
+
account.define_singleton_method(:shutdown){@shut_down = true}
|
|
17
|
+
account.define_singleton_method(:shut_down?){!!@shut_down}
|
|
18
|
+
arguments = []
|
|
19
|
+
original = WestpacComAu::Account.method(:new)
|
|
20
|
+
WestpacComAu::Account.define_singleton_method(:new){|**args| arguments << args; account}
|
|
21
|
+
yield account, arguments
|
|
22
|
+
ensure
|
|
23
|
+
WestpacComAu::Account.define_singleton_method(:new, original)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe ".download_csv_file" do
|
|
27
|
+
it "is the file downloaded, for the account and period given, the credentials and web_account_options going to the account, which is shut down" do
|
|
28
|
+
with_stand_in_account do |account, arguments|
|
|
29
|
+
_(WestpacComAu::Transactions.download_csv_file(account_number: '123456', username: 'customer', password: 'secret', period: :last_month, web_account_options: {download_directory: '/downloads'})).must_equal('/downloads/transactions.csv')
|
|
30
|
+
_(account.asked).must_equal([['123456', {period: :last_month, from_date: nil, to_date: nil}]])
|
|
31
|
+
_(arguments).must_equal([{username: 'customer', password: 'secret', download_directory: '/downloads'}])
|
|
32
|
+
_(account.shut_down?).must_equal(true)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "shuts the account down even where the download fails" do
|
|
37
|
+
with_stand_in_account(download: ->{raise Selenium::WebDriver::Error::TimeoutError}) do |account, _arguments|
|
|
38
|
+
_{WestpacComAu::Transactions.download_csv_file(account_number: '123456')}.must_raise(Selenium::WebDriver::Error::TimeoutError)
|
|
39
|
+
_(account.shut_down?).must_equal(true)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "refuses a keyword it doesn't know, rather than passing it on" do
|
|
44
|
+
_{WestpacComAu::Transactions.download_csv_file(account_number: '123456', download_directory: '/downloads')}.must_raise(ArgumentError)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require_relative './lib/WestpacComAu/VERSION'
|
|
2
|
+
|
|
3
|
+
class Gem::Specification
|
|
4
|
+
def dependencies=(gems)
|
|
5
|
+
gems.each{|gem| add_dependency(*gem)}
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def development_dependencies=(gems)
|
|
9
|
+
gems.each{|gem| add_development_dependency(*gem)}
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
Gem::Specification.new do |spec|
|
|
14
|
+
spec.name = 'westpac_com_au'
|
|
15
|
+
spec.version = WestpacComAu::VERSION
|
|
16
|
+
|
|
17
|
+
spec.summary = "Interact with Westpac Online Banking via Selenium WebDriver."
|
|
18
|
+
spec.description = "Log into Westpac Online Banking (banking.westpac.com.au) and export an account's transactions as a CSV file."
|
|
19
|
+
|
|
20
|
+
spec.author = 'thoran'
|
|
21
|
+
spec.email = 'code@thoran.com'
|
|
22
|
+
spec.homepage = 'https://github.com/thoran/westpac_com_au'
|
|
23
|
+
spec.license = 'MIT'
|
|
24
|
+
|
|
25
|
+
spec.require_paths = ['lib']
|
|
26
|
+
spec.required_ruby_version = '>= 3.3'
|
|
27
|
+
|
|
28
|
+
spec.files = [
|
|
29
|
+
'westpac_com_au.gemspec',
|
|
30
|
+
Dir['lib/**/*.rb'],
|
|
31
|
+
Dir['test/**/*.rb'],
|
|
32
|
+
'CHANGELOG',
|
|
33
|
+
'Gemfile',
|
|
34
|
+
'LICENSE',
|
|
35
|
+
'Rakefile',
|
|
36
|
+
'README.md',
|
|
37
|
+
].flatten
|
|
38
|
+
|
|
39
|
+
spec.dependencies = [
|
|
40
|
+
['selenium-webdriver', '>= 4.0'],
|
|
41
|
+
['webaccount', '~> 0.9']
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
spec.development_dependencies = %w{
|
|
45
|
+
minitest
|
|
46
|
+
minitest-spec-context
|
|
47
|
+
rake
|
|
48
|
+
}
|
|
49
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: westpac_com_au
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.6.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- thoran
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: selenium-webdriver
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '4.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '4.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: webaccount
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0.9'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0.9'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: minitest
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: minitest-spec-context
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rake
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
description: Log into Westpac Online Banking (banking.westpac.com.au) and export an
|
|
83
|
+
account's transactions as a CSV file.
|
|
84
|
+
email: code@thoran.com
|
|
85
|
+
executables: []
|
|
86
|
+
extensions: []
|
|
87
|
+
extra_rdoc_files: []
|
|
88
|
+
files:
|
|
89
|
+
- CHANGELOG
|
|
90
|
+
- Gemfile
|
|
91
|
+
- LICENSE
|
|
92
|
+
- README.md
|
|
93
|
+
- Rakefile
|
|
94
|
+
- lib/WestpacComAu/Account.rb
|
|
95
|
+
- lib/WestpacComAu/Transactions.rb
|
|
96
|
+
- lib/WestpacComAu/VERSION.rb
|
|
97
|
+
- lib/westpac_com_au.rb
|
|
98
|
+
- test/WestpacComAu/Account_test.rb
|
|
99
|
+
- test/WestpacComAu/Transactions_test.rb
|
|
100
|
+
- westpac_com_au.gemspec
|
|
101
|
+
homepage: https://github.com/thoran/westpac_com_au
|
|
102
|
+
licenses:
|
|
103
|
+
- MIT
|
|
104
|
+
metadata: {}
|
|
105
|
+
rdoc_options: []
|
|
106
|
+
require_paths:
|
|
107
|
+
- lib
|
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
|
+
requirements:
|
|
110
|
+
- - ">="
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: '3.3'
|
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
requirements: []
|
|
119
|
+
rubygems_version: 4.0.23
|
|
120
|
+
specification_version: 4
|
|
121
|
+
summary: Interact with Westpac Online Banking via Selenium WebDriver.
|
|
122
|
+
test_files: []
|