nab_com_au 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 70ea8fa4c1c09b78411479f27506c76c59d7c15764e67874072663ca1b61c8c5
4
+ data.tar.gz: f87968139f9f86b91b2c69ef479eddbff9962a08fb764a65ee90af1e68d1cd55
5
+ SHA512:
6
+ metadata.gz: ffbf27cde4c0b499ceb237e86f04f9d4f7cbd257f7878d6e2aea2ba7894c9d2ecfc4f5d31fd87599cdde0801e505d0d2ad7fa4599ed2f2c8848189da09b25951
7
+ data.tar.gz: b3d103c9ce81e1a119f505f3a50ae4824d824712360cd46dbda918044346f00e6f55ff979f8f6f32065ba3a92c87556e17c8875fff7189cc5f2a37250ee0598c
data/CHANGELOG ADDED
@@ -0,0 +1,129 @@
1
+ # nab_com_au/CHANGELOG
2
+
3
+ ## 20261115
4
+
5
+ 0.3.0: - NabComAu::Account#initialize: Now uses superclass WebAccount; + nab_com_au.gemspec.
6
+
7
+ 1. - NabComAu::Account#initialize, WebAccount's taking the browser's options, such as browser:, profile_directory: and headless:, and reading PAGE_SELECTORS itself.
8
+ 2. /NabComAu::Account::PAGE_IDS/PAGE_SELECTORS/: Keyed as WebAccount's keywords are, the ids given as selectors; + login_page_submit_button_selector.
9
+ 3. - NabComAu::Account#login_page_submit_button, WebAccount's finding the button by login_page_submit_button_selector.
10
+ 4. + nab_com_au.gemspec, upon webaccount ~> 0.8.
11
+ 5. + lib/nab_com_au.rb
12
+ 6. + NabComAu::VERSION
13
+ 7. ~ Gemfile: The gemspec's dependencies, in place of its own.
14
+ 8. ~ test/NabComAu/Account_test.rb: PAGE_SELECTORS, and WebAccount's initialize with the browser's options, are tested.
15
+ 9. ~ lib/NabComAu/Account.rb: ~ Notes: + 2 on new()
16
+
17
+
18
+ ## 20261114
19
+
20
+ 0.2.1: Bpay payments working.
21
+
22
+ 1. ~ NabComAu::Account: require 'webaccount', ~> 0.7, in place of WebAccount 0.2.5, the ids in PAGE_IDS being passed to it as selectors.
23
+ 2. /NabComAu::Account: attr_accessor :driver/attr_writer :driver/, so as WebAccount starts a browser where none is given.
24
+ 3. ~ NabComAu::Account#login: Raises ArgumentError where username: or password: is missing.
25
+ 4. ~ NabComAu::Account#bpay: Hands its browser to the NabComAu::Bpay, and pays with the account's password.
26
+ 5. ~ NabComAu::Account#transfer: Passes its own arguments to the NabComAu::Transfer, in place of target and customer_reference_number, which weren't defined; hands it its browser; and pays it.
27
+ 6. ~ NabComAu::Account: autoload :Bpay and :Transfer from beside lib/NabComAu/Account.rb, rather than from the load path.
28
+ 7. ~ lib/NabComAu/Bpay.rb: require_relative '../Nab', whose Nab.to_nab_account_number_format it calls.
29
+ 8. ~ NabComAu::Bpay#pay: + validate_args(), raising ArgumentError naming whichever of the payment's details and the password are missing, before going to the payment.
30
+ 9. ~ NabComAu::Transfer#pay: Raises NotImplementedError, rather than running the BPAY steps.
31
+ 10. - NabComAu::Transfer#transfer_and_pay_button, #transfer_link, and the BPAY methods copied from NabComAu::Bpay.
32
+ 11. ~ Nab.to_nab_account_number_format: Leaves the string it's given unchanged.
33
+ 12. ~ lib/NabComAu/Account.rb, lib/Nab.rb: The date, version and changes go from the headers, the CHANGELOG now carrying them. lib/NabComAu/Bpay.rb and lib/NabComAu/Transfer.rb are given headers.
34
+ 13. + CHANGELOG, with an entry for each version from 0.0.0.
35
+ 14. + Gemfile, + Rakefile
36
+ 15. + test/helper.rb, test/Nab_test.rb, test/NabComAu/Account_test.rb, test/NabComAu/Bpay_test.rb, test/NabComAu/Transfer_test.rb: Offline, with stand-ins for the browser and its elements.
37
+
38
+
39
+ ## 20230627
40
+
41
+ 0.2.0: + NabComAu::Bpay, + NabComAu::Transfer
42
+
43
+ 1. + Nab.to_nab_account_number_format, moved out of lib/NabComAu/Account.rb.
44
+ 2. + NabComAu::Bpay, a NabComAu::Account, is given a payment's details and makes it with #pay. The bpay_ methods, #transfer_and_pay_button, #bill_payment_link, #new_bill_payment and #new_bill_payment_confirmation move into it.
45
+ 3. + NabComAu::Transfer, a NabComAu::Account, is given a transfer's source account, target BSB and account number, note and amount. + #transfer_link; its #pay is so far the BPAY steps.
46
+ 4. ~ NabComAu::Account#bpay: It makes a NabComAu::Bpay and pays it; - password:.
47
+ 5. + NabComAu::Account#transfer, which makes a NabComAu::Transfer and prints it.
48
+ 6. + NabComAu::Account: autoload :Bpay, :Transfer
49
+ 7. ~ PAGE_IDS: The username field is username, and - login_page_submit_button_id.
50
+ 8. + NabComAu::Account#login_page_submit_button, the button reading Login.
51
+ 9. ~ NabComAu::Account#login: The waits are back.
52
+ 10. /NabComAu::Account#driver=/attr_accessor :driver/
53
+ 11. ~ lib/NabComAu/Account.rb: The self-run section is removed.
54
+
55
+
56
+ ## 20220508
57
+
58
+ 0.1.8: New bill payment confirmation page.
59
+
60
+ 1. + NabComAu::Account#bpay_password_field
61
+ 2. + NabComAu::Account#bpay_enter_password
62
+ 3. + NabComAu::Account#bpay_new_bill_payment_submit_button
63
+ 4. + NabComAu::Account#new_bill_payment_confirmation
64
+ 5. ~ NabComAu::Account#bpay, to make use of confirmation methods above; and to make use of a passed in value for password.
65
+
66
+
67
+ 0.1.7: New bill payment page.
68
+
69
+ 1. + NabComAu::Account#bpay_customer_reference_number_field
70
+ 2. + NabComAu::Account#bpay_enter_customer_reference_number
71
+ 3. + NabComAu::Account#bpay_payment_amount_field
72
+ 4. + NabComAu::Account#bpay_enter_payment_amount
73
+ 5. + NabComAu::Account#bpay_new_bill_payment_next_button
74
+ 6. + NabComAu::Account#new_bill_payment
75
+ 7. ~ NabComAu::Account#bpay, to make use of the methods above.
76
+
77
+
78
+ ## 20220425, 26
79
+
80
+ 0.1.6: Handle ambiguity when entering biller codes.
81
+
82
+ 1. + NabComAu::Account#login, so as to add delays, possibly temporary.
83
+ 2. + NabComAu::Account#bpay_biller_direct_hit?
84
+ 3. + NabComAu::Account#bpay_search_result_selection
85
+ 4. ~ NabComAu::Account#bpay, to make use of disambiguation methods above.
86
+
87
+
88
+ ## 20220425
89
+
90
+ 0.1.5: + NabComAu::Account#bpay_enter_biller_name
91
+
92
+ 1. + NabComAu::Account#bpay_biller_name_field
93
+ 2. ~ NabComAu::Account#bpay
94
+
95
+
96
+ 0.1.4: + NabComAu::Account#bpay_submit_button
97
+
98
+ 1. ~ NabComAu::Account#bpay
99
+ 2. ~ NabComAu::Account#bpay_bank_account_select_list, to use css name instead of xpath.
100
+
101
+
102
+ 0.1.3: + NabComAu::Account#bpay_biller_select_list
103
+
104
+ 1. + NabComAu::Account#bpay_biller_code_field
105
+ 2. + NabComAu::Account#bpay_select_biller
106
+ 3. + NabComAu::Account#bpay_enter_biller_code
107
+ 4. ~ NabComAu::Account#bpay
108
+
109
+
110
+ 0.1.2: + Nab#to_nab_account_number_format
111
+
112
+ 1. ~ NabComAu::Account#bpay_select_bank_account
113
+
114
+
115
+ 0.1.1: + NabComAu::Account#bpay_bank_account_select_list
116
+
117
+ 1. + NabComAu::Account#bpay_select_bank_account
118
+ 2. ~ NabComAu::Account#bpay
119
+
120
+
121
+ ## 20220424
122
+
123
+ 0.1.0: + NabComAu::Account#bpay
124
+
125
+ 1. + NabComAu::Account#transfer_and_pay_button
126
+ 2. + NabComAu::Account#bill_payment_link
127
+
128
+
129
+ 0.0.0: + NabComAu::Account
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://www.rubygems.org'
2
+
3
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # Rakefile
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ end
8
+
9
+ task default: :test
data/lib/Nab.rb ADDED
@@ -0,0 +1,26 @@
1
+ # Nab.rb
2
+ # Nab
3
+
4
+ # Notes:
5
+ # 1. Extracted from NabComAu 0.1.8.
6
+ # 2. This is a separate namespace from NabComAu because this isn't website traversal specific.
7
+
8
+ module Nab
9
+ def to_nab_account_number_format(account_number)
10
+ return unless account_number.match(/^[\d-]+$/)
11
+ unless account_number.match(/^\d\d-\d\d\d-\d\d\d\d$/)
12
+ unless account_number.match(/^\d\d\d\d\d\d\d\d\d$/)
13
+ account_number = account_number.delete('-')
14
+ end
15
+ account_number_parts = account_number.split('')
16
+ new_account_number_parts = []
17
+ new_account_number_parts << "#{account_number_parts[0]}#{account_number_parts[1]}"
18
+ new_account_number_parts << "#{account_number_parts[2]}#{account_number_parts[3]}#{account_number_parts[4]}"
19
+ new_account_number_parts << "#{account_number_parts[5]}#{account_number_parts[6]}#{account_number_parts[7]}#{account_number_parts[8]}"
20
+ account_number = new_account_number_parts.join('-')
21
+ end
22
+ account_number
23
+ end
24
+
25
+ module_function :to_nab_account_number_format
26
+ end
@@ -0,0 +1,65 @@
1
+ # NabComAu/Account.rb
2
+ # NabComAu::Account
3
+
4
+ # Notes:
5
+ # 1. Searching by BPay biller code produces a substring match, hence even if the biller code is complete and correct, then an extra step is required.
6
+ # 2. new() is WebAccount's: it takes the browser's options, such as browser:, profile_directory: and headless:, and NAB's pages come from PAGE_SELECTORS, unless a keyword is given in place of one.
7
+
8
+ require 'webaccount'
9
+
10
+ module NabComAu
11
+
12
+ autoload :Bpay, File.join(__dir__, 'Bpay')
13
+ autoload :Transfer, File.join(__dir__, 'Transfer')
14
+
15
+ class Account < WebAccount
16
+ PAGE_SELECTORS = {
17
+ login_page_url: 'https://ib.nab.com.au/nabib/index.jsp',
18
+ login_page_username_field_selector: {id: 'username'},
19
+ login_page_password_field_selector: {id: 'password'},
20
+ login_page_submit_button_selector: {xpath: "//button[contains(text(), 'Login')]"},
21
+ logout_button_selector: {id: 'logoutButton'},
22
+ logged_out_xpath: ''
23
+ }
24
+
25
+ attr_writer :driver
26
+
27
+ def login(username: nil, password: nil)
28
+ @logged_in = false
29
+ username ||= self.username or raise ArgumentError, "Can't log in without username:."
30
+ password ||= self.password or raise ArgumentError, "Can't log in without password:."
31
+ driver.attempt do
32
+ get_login_page
33
+ sleep 1
34
+ enter_username(username)
35
+ sleep 2
36
+ enter_password(password)
37
+ sleep 3
38
+ login_page_submit_button.click
39
+ end
40
+ end
41
+
42
+ def bpay(source_bank_account_name_or_number:, biller_name_or_code:, customer_reference_number:, amount:)
43
+ bpay = Bpay.new(
44
+ source_bank_account_name_or_number: source_bank_account_name_or_number,
45
+ biller_name_or_code: biller_name_or_code,
46
+ customer_reference_number: customer_reference_number,
47
+ amount: amount
48
+ )
49
+ bpay.driver = driver
50
+ bpay.pay(password: password)
51
+ end
52
+
53
+ def transfer(source_bank_account_name_or_number: nil, target_bsb: nil, target_bank_account_number: nil, note: nil, amount: nil)
54
+ transfer = Transfer.new(
55
+ source_bank_account_name_or_number: source_bank_account_name_or_number,
56
+ target_bsb: target_bsb,
57
+ target_bank_account_number: target_bank_account_number,
58
+ note: note,
59
+ amount: amount
60
+ )
61
+ transfer.driver = driver
62
+ transfer.pay
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,222 @@
1
+ # NabComAu/Bpay.rb
2
+ # NabComAu::Bpay
3
+
4
+ require_relative '../Nab'
5
+
6
+ module NabComAu
7
+ class Bpay < NabComAu::Account
8
+ def initialize(source_bank_account_name_or_number: nil, biller_name_or_code: nil, customer_reference_number: nil, amount: nil)
9
+ @source_bank_account_name_or_number = source_bank_account_name_or_number
10
+ @biller_name_or_code = biller_name_or_code
11
+ @customer_reference_number = customer_reference_number
12
+ @amount = amount
13
+ end
14
+
15
+ def transfer_and_pay_button
16
+ driver_wait.until do
17
+ @driver.element_present?(:xpath, '//*[@id="transferPay"]/button')
18
+ end
19
+ @driver.find_element(xpath: '//*[@id="transferPay"]/button')
20
+ end
21
+
22
+ def bill_payment_link
23
+ driver_wait.until do
24
+ @driver.element_present?(:xpath, '//*[@id="transferPay"]/ul/li[1]/ul/li[4]/a')
25
+ end
26
+ @driver.find_element(xpath: '//*[@id="transferPay"]/ul/li[1]/ul/li[4]/a')
27
+ end
28
+
29
+ def bpay_bank_account_select_list
30
+ driver_wait.until do
31
+ @driver.element_present?(:css, '[name="selectedAcctIndx"]')
32
+ end
33
+ @driver.find_element(css: '[name="selectedAcctIndx"]')
34
+ end
35
+
36
+ def bpay_biller_select_list
37
+ driver_wait.until do
38
+ @driver.element_present?(:css, '[name="billerRef"]')
39
+ end
40
+ @driver.find_element(css: '[name="billerRef"]')
41
+ end
42
+
43
+ def bpay_biller_code_field
44
+ driver_wait.until do
45
+ @driver.element_present?(:css, '[name="billerCode"]')
46
+ end
47
+ @driver.find_element(css: '[name="billerCode"]')
48
+ end
49
+
50
+ def bpay_biller_name_field
51
+ driver_wait.until do
52
+ @driver.element_present?(:css, '[name="billerName"]')
53
+ end
54
+ @driver.find_element(css: '[name="billerName"]')
55
+ end
56
+
57
+ def bpay_submit_button
58
+ @driver.find_element(css: '[name="search"]')
59
+ end
60
+
61
+ def bpay_select_bank_account(account_name_or_number)
62
+ unless account_name_or_number.match(/[a-zA-Z]/)
63
+ account_name_or_number = Nab.to_nab_account_number_format(account_name_or_number)
64
+ end
65
+ webdriver_select_list = Selenium::WebDriver::Support::Select.new(bpay_bank_account_select_list)
66
+ if option = webdriver_select_list.options.detect{|option| option.attribute(:text) =~ /#{account_name_or_number}/}
67
+ option.click
68
+ else
69
+ raise "Can't find supplied account name or number from the dropdown list."
70
+ end
71
+ end
72
+
73
+ def bpay_select_biller(biller_name)
74
+ webdriver_select_list = Selenium::WebDriver::Support::Select.new(bpay_biller_select_list)
75
+ if option = webdriver_select_list.options.detect{|option| option.attribute(:text) =~ /#{biller_name}/}
76
+ option.click
77
+ end
78
+ option
79
+ end
80
+
81
+ def bpay_enter_biller_code(biller_code)
82
+ bpay_biller_code_field.clear
83
+ bpay_biller_code_field.send_keys(biller_code)
84
+ end
85
+
86
+ def bpay_enter_biller_name(biller_name)
87
+ bpay_biller_name_field.clear
88
+ bpay_biller_name_field.send_keys(biller_name)
89
+ end
90
+
91
+ def bpay_biller_direct_hit?
92
+ if element = @driver.find_element(xpath: '//*[@class="pageTitle"]')
93
+ element.text.match(/New bill payment/)
94
+ end
95
+ end
96
+
97
+ def bpay_search_result_selection(bpay_biller_code)
98
+ bpay_biller_cell = @driver.find_element(xpath: "//td[contains(text(), '#{bpay_biller_code}')]")
99
+ bpay_biller_cell.find_element(:xpath, '../td/a')
100
+ end
101
+
102
+ # New bill payment
103
+
104
+ def bpay_customer_reference_number_field
105
+ @driver.find_element(:name, 'custRefNumber')
106
+ end
107
+
108
+ def bpay_enter_customer_reference_number(customer_reference_number)
109
+ bpay_customer_reference_number_field.clear
110
+ bpay_customer_reference_number_field.send_keys(customer_reference_number)
111
+ end
112
+
113
+ def bpay_payment_amount_field
114
+ @bpay_payment_amount_field ||= (
115
+ driver_wait.until do
116
+ @driver.element_present?(:css, '[name="paymentAmount"]')
117
+ end
118
+ @driver.find_element(css: '[name="paymentAmount"]')
119
+ )
120
+ end
121
+
122
+ def bpay_enter_payment_amount(amount)
123
+ bpay_payment_amount_field.clear
124
+ bpay_payment_amount_field.send_keys(amount)
125
+ end
126
+
127
+ def bpay_new_bill_payment_next_button
128
+ @bpay_new_bill_payment_next_button ||= (
129
+ driver_wait.until do
130
+ @driver.element_present?(:css, '[name="nextButton"]')
131
+ end
132
+ @driver.find_element(css: '[name="nextButton"]')
133
+ )
134
+ end
135
+
136
+ def new_bill_payment(customer_reference_number:, amount:)
137
+ bpay_enter_customer_reference_number(customer_reference_number)
138
+ bpay_enter_payment_amount(amount)
139
+ bpay_new_bill_payment_next_button.click
140
+ end
141
+
142
+ # New bill payment confirmation
143
+
144
+ def bpay_password_field
145
+ @bpay_password_field ||= (
146
+ driver_wait.until do
147
+ @driver.element_present?(:css, '[name="password"]')
148
+ end
149
+ @driver.find_element(css: '[name="password"]')
150
+ )
151
+ end
152
+
153
+ def bpay_enter_password(password)
154
+ bpay_password_field.clear
155
+ bpay_password_field.send_keys(password)
156
+ end
157
+
158
+ def bpay_new_bill_payment_submit_button
159
+ @bpay_new_bill_payment_submit_button ||= (
160
+ driver_wait.until do
161
+ @driver.element_present?(:css, '[name="nextButton"]')
162
+ end
163
+ @driver.find_element(css: '[name="nextButton"]')
164
+ )
165
+ end
166
+
167
+ def new_bill_payment_confirmation(password:)
168
+ bpay_enter_password(password)
169
+ bpay_new_bill_payment_submit_button.click
170
+ end
171
+
172
+ def pay(source_bank_account_name_or_number: nil, biller_name_or_code: nil, customer_reference_number: nil, amount: nil, password: nil)
173
+ source_bank_account_name_or_number ||= @source_bank_account_name_or_number
174
+ biller_name_or_code ||= @biller_name_or_code
175
+ customer_reference_number ||= @customer_reference_number
176
+ amount ||= @amount
177
+ password ||= @password
178
+ validate_args(
179
+ source_bank_account_name_or_number: source_bank_account_name_or_number,
180
+ biller_name_or_code: biller_name_or_code,
181
+ customer_reference_number: customer_reference_number,
182
+ amount: amount,
183
+ password: password
184
+ )
185
+ transfer_and_pay_button.click
186
+ sleep 1
187
+ bill_payment_link.click
188
+ sleep 1
189
+ bpay_select_bank_account(source_bank_account_name_or_number)
190
+ if biller_name_or_code.match(/^\d+$/) # is a number, then enter code
191
+ bpay_enter_biller_code(biller_name_or_code)
192
+ else # is a name, then use the select list
193
+ unless bpay_select_biller(biller_name_or_code) # If the the string can't be found in the dropdown list, then use the search field...
194
+ bpay_enter_biller_name(biller_name_or_code)
195
+ end
196
+ end
197
+ bpay_submit_button.click
198
+ sleep 1
199
+ unless bpay_biller_direct_hit?
200
+ bpay_search_result_selection(biller_name_or_code).click
201
+ end
202
+ sleep 1
203
+ new_bill_payment(customer_reference_number: customer_reference_number, amount: amount)
204
+ sleep 1
205
+ new_bill_payment_confirmation(password: password)
206
+ sleep 1
207
+ end
208
+
209
+ private
210
+
211
+ def validate_args(args)
212
+ missing_args = []
213
+ args.each do |arg_name, value|
214
+ missing_args << arg_name unless value
215
+ end
216
+ return if missing_args.empty?
217
+ aggregate_error = missing_args.join(', ')
218
+ copula = missing_args.count > 1 ? 'are' : 'is'
219
+ raise ArgumentError, "#{aggregate_error} #{copula} missing."
220
+ end
221
+ end
222
+ end
@@ -0,0 +1,18 @@
1
+ # NabComAu/Transfer.rb
2
+ # NabComAu::Transfer
3
+
4
+ module NabComAu
5
+ class Transfer < NabComAu::Account
6
+ def initialize(source_bank_account_name_or_number: nil, target_bsb: nil, target_bank_account_number: nil, note: nil, amount: nil)
7
+ @source_bank_account_name_or_number = source_bank_account_name_or_number
8
+ @target_bsb = target_bsb
9
+ @target_bank_account_number = target_bank_account_number
10
+ @note = note
11
+ @amount = amount
12
+ end
13
+
14
+ def pay(source_bank_account_name_or_number: nil, target_bsb: nil, target_bank_account_number: nil, note: nil, amount: nil)
15
+ raise NotImplementedError, "Transfers aren't made yet: the transfer page's fields haven't been worked out."
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ # NabComAu/VERSION.rb
2
+ # NabComAu::VERSION
3
+
4
+ module NabComAu
5
+ VERSION = '0.3.0'
6
+ end
data/lib/nab_com_au.rb ADDED
@@ -0,0 +1,5 @@
1
+ # nab_com_au.rb
2
+ # NabComAu
3
+
4
+ require_relative './NabComAu/Account'
5
+ require_relative './NabComAu/VERSION'
@@ -0,0 +1,47 @@
1
+ require_relative './lib/NabComAu/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 = 'nab_com_au'
15
+ spec.version = NabComAu::VERSION
16
+
17
+ spec.summary = "Pay bills by BPAY from NAB Internet Banking via Selenium WebDriver."
18
+ spec.description = "Log into NAB Internet Banking with a username and password, and pay a bill by BPAY from an account, going as far as the confirmation page unless told to confirm."
19
+
20
+ spec.author = 'thoran'
21
+ spec.email = 'code@thoran.com'
22
+ spec.homepage = 'https://github.com/thoran/nab_com_au'
23
+ spec.license = 'MIT'
24
+
25
+ spec.require_paths = ['lib']
26
+ spec.required_ruby_version = '>= 3.3'
27
+
28
+ spec.files = [
29
+ 'nab_com_au.gemspec',
30
+ Dir['lib/**/*.rb'],
31
+ Dir['test/**/*.rb'],
32
+ 'CHANGELOG',
33
+ 'Gemfile',
34
+ 'Rakefile',
35
+ ].flatten
36
+
37
+ spec.dependencies = [
38
+ ['selenium-webdriver', '>= 4.0'],
39
+ ['webaccount', '~> 0.8']
40
+ ]
41
+
42
+ spec.development_dependencies = %w{
43
+ minitest
44
+ minitest-spec-context
45
+ rake
46
+ }
47
+ end
@@ -0,0 +1,103 @@
1
+ # test/NabComAu/Account_test.rb
2
+
3
+ # Notes:
4
+ # 1. NabComAu::Bpay.new is swapped for a stand-in which records what it was given, for the length of an example, and put back afterwards.
5
+
6
+ require_relative '../helper'
7
+
8
+ describe NabComAu::Account do
9
+ def account(**args)
10
+ NabComAu::Account.new(**args).tap{|account| account.driver = untouchable_driver}
11
+ end
12
+
13
+ def recording_bpay_pay
14
+ calls = []
15
+ NabComAu::Bpay.define_singleton_method(:new) do |**payment|
16
+ bpay = Object.new
17
+ bpay.define_singleton_method(:driver=){|driver| @driver = driver}
18
+ bpay.define_singleton_method(:pay){|**args| calls << {driver: @driver, payment: payment, args: args}}
19
+ bpay
20
+ end
21
+ yield calls
22
+ ensure
23
+ NabComAu::Bpay.singleton_class.remove_method(:new)
24
+ end
25
+
26
+ describe "PAGE_SELECTORS" do
27
+ it "gives NAB's login page, its fields and buttons" do
28
+ account = account()
29
+ _(account.send(:login_page_url)).must_equal 'https://ib.nab.com.au/nabib/index.jsp'
30
+ _(account.send(:login_page_username_field_selector)).must_equal({id: 'username'})
31
+ _(account.send(:login_page_password_field_selector)).must_equal({id: 'password'})
32
+ _(account.send(:login_page_submit_button_selector)).must_equal({xpath: "//button[contains(text(), 'Login')]"})
33
+ _(account.send(:logout_button_selector)).must_equal({id: 'logoutButton'})
34
+ end
35
+
36
+ it "gives way to a keyword given to new()" do
37
+ account = account(login_page_url: 'https://example.com/login')
38
+ _(account.send(:login_page_url)).must_equal 'https://example.com/login'
39
+ end
40
+
41
+ it "is a Bpay's too" do
42
+ _(NabComAu::Bpay.new.send(:login_page_url)).must_equal 'https://ib.nab.com.au/nabib/index.jsp'
43
+ end
44
+ end
45
+
46
+ describe "#initialize" do
47
+ it "is WebAccount's" do
48
+ _(NabComAu::Account.instance_method(:initialize).owner).must_equal WebAccount
49
+ end
50
+
51
+ it "takes the browser's options" do
52
+ account = NabComAu::Account.new(browser: :firefox, profile_directory: '/profile', headless: true)
53
+ _(account.send(:browser)).must_equal :firefox
54
+ _(account.instance_variable_get(:@profile_directory)).must_equal '/profile'
55
+ _(account.instance_variable_get(:@headless)).must_equal true
56
+ end
57
+
58
+ it "says which keyword is mistyped" do
59
+ error = _{NabComAu::Account.new(brower: :firefox)}.must_raise ArgumentError
60
+ _(error.message).must_match(/brower/)
61
+ end
62
+ end
63
+
64
+ describe "#driver=" do
65
+ it "is the browser driven, none being started" do
66
+ driver = untouchable_driver
67
+ account = NabComAu::Account.new
68
+ account.driver = driver
69
+ _(account.driver).must_be_same_as driver
70
+ end
71
+ end
72
+
73
+ describe "#login" do
74
+ it "says username: is missing, before using the browser" do
75
+ error = _{account(password: 'password').login}.must_raise ArgumentError
76
+ _(error.message).must_match(/username:/)
77
+ end
78
+
79
+ it "says password: is missing, before using the browser" do
80
+ error = _{account(username: 'username').login}.must_raise ArgumentError
81
+ _(error.message).must_match(/password:/)
82
+ end
83
+ end
84
+
85
+ describe "#bpay" do
86
+ it "pays with the account's browser and password" do
87
+ recording_bpay_pay do |calls|
88
+ account = account(username: 'username', password: 'password')
89
+ account.bpay(source_bank_account_name_or_number: 'Everyday Account', biller_name_or_code: '1234', customer_reference_number: '5678', amount: '1.00')
90
+ _(calls.size).must_equal 1
91
+ _(calls.first[:driver]).must_be_same_as account.driver
92
+ _(calls.first[:payment]).must_equal({source_bank_account_name_or_number: 'Everyday Account', biller_name_or_code: '1234', customer_reference_number: '5678', amount: '1.00'})
93
+ _(calls.first[:args]).must_equal({password: 'password'})
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "#transfer" do
99
+ it "raises rather than making a transfer" do
100
+ _{account.transfer(source_bank_account_name_or_number: 'Everyday Account', target_bsb: '000-000', target_bank_account_number: '000000000', note: 'note', amount: '1.00')}.must_raise NotImplementedError
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,107 @@
1
+ # test/NabComAu/Bpay_test.rb
2
+
3
+ # Notes:
4
+ # 1. Every element pay() reaches for is a stand-in on the Bpay itself, and its browser is one which fails if used, so the submit clicked is only ever a stand-in's.
5
+
6
+ require_relative '../helper'
7
+
8
+ describe NabComAu::Bpay do
9
+ PAYMENT = {
10
+ source_bank_account_name_or_number: '123456789',
11
+ biller_name_or_code: '1234',
12
+ customer_reference_number: '5678',
13
+ amount: '1.00',
14
+ password: 'password'
15
+ }
16
+
17
+ # A Bpay whose pages are stand-ins: a list of accounts and a list of billers; and, where direct_hit is false, a search which ends upon a list of results.
18
+ def bpay(payment: {}, accounts: ['Everyday Account 12-345-6789'], billers: ['Electricity'], direct_hit: true)
19
+ elements = {
20
+ transfer_and_pay_button: StandInElement.new,
21
+ bill_payment_link: StandInElement.new,
22
+ bpay_bank_account_select_list: stand_in_select(*accounts),
23
+ bpay_biller_select_list: stand_in_select(*billers),
24
+ bpay_biller_code_field: StandInElement.new,
25
+ bpay_biller_name_field: StandInElement.new,
26
+ bpay_submit_button: StandInElement.new,
27
+ search_result: StandInElement.new,
28
+ bpay_customer_reference_number_field: StandInElement.new,
29
+ bpay_payment_amount_field: StandInElement.new,
30
+ bpay_new_bill_payment_next_button: StandInElement.new,
31
+ bpay_password_field: StandInElement.new,
32
+ bpay_new_bill_payment_submit_button: StandInElement.new
33
+ }
34
+ bpay = NabComAu::Bpay.new(**payment)
35
+ bpay.driver = untouchable_driver
36
+ elements.each{|name, element| bpay.define_singleton_method(name){element}}
37
+ bpay.define_singleton_method(:bpay_biller_direct_hit?){direct_hit}
38
+ bpay.define_singleton_method(:bpay_search_result_selection){|biller| elements[:search_result]}
39
+ bpay.define_singleton_method(:sleep){|*|}
40
+ [bpay, elements]
41
+ end
42
+
43
+ def selected(select_list)
44
+ select_list.find_elements.select(&:clicked?).map(&:text)
45
+ end
46
+
47
+ describe "#pay" do
48
+ it "pays from the account given, with the biller code, reference, amount and password given" do
49
+ bpay, elements = bpay()
50
+ bpay.pay(**PAYMENT)
51
+ _(selected(elements[:bpay_bank_account_select_list])).must_equal ['Everyday Account 12-345-6789']
52
+ _(elements[:bpay_biller_code_field].typed).must_equal ['1234']
53
+ _(elements[:bpay_customer_reference_number_field].typed).must_equal ['5678']
54
+ _(elements[:bpay_payment_amount_field].typed).must_equal ['1.00']
55
+ _(elements[:bpay_password_field].typed).must_equal ['password']
56
+ _(elements[:bpay_new_bill_payment_submit_button].clicked?).must_equal true
57
+ end
58
+
59
+ it "chooses a biller named from the list" do
60
+ bpay, elements = bpay()
61
+ bpay.pay(**PAYMENT, biller_name_or_code: 'Electricity')
62
+ _(selected(elements[:bpay_biller_select_list])).must_equal ['Electricity']
63
+ _(elements[:bpay_biller_name_field].typed).must_be_empty
64
+ end
65
+
66
+ it "searches for a biller named which isn't in the list" do
67
+ bpay, elements = bpay()
68
+ bpay.pay(**PAYMENT, biller_name_or_code: 'Water')
69
+ _(elements[:bpay_biller_name_field].typed).must_equal ['Water']
70
+ end
71
+
72
+ it "chooses from the search results where the biller code matches more than one biller" do
73
+ bpay, elements = bpay(direct_hit: false)
74
+ bpay.pay(**PAYMENT)
75
+ _(elements[:search_result].clicked?).must_equal true
76
+ end
77
+
78
+ it "raises where the account isn't in the list" do
79
+ bpay, elements = bpay(accounts: ['Savings Account 98-765-4321'])
80
+ _{bpay.pay(**PAYMENT)}.must_raise RuntimeError
81
+ _(elements[:bpay_new_bill_payment_submit_button].clicked?).must_equal false
82
+ end
83
+
84
+ PAYMENT.each_key do |name|
85
+ it "says #{name} is missing, before going to the payment" do
86
+ bpay, elements = bpay()
87
+ error = _{bpay.pay(**PAYMENT, name => nil)}.must_raise ArgumentError
88
+ _(error.message).must_equal "#{name} is missing."
89
+ _(elements[:transfer_and_pay_button].clicked?).must_equal false
90
+ end
91
+ end
92
+
93
+ it "says all of what's missing at once" do
94
+ bpay, elements = bpay()
95
+ error = _{bpay.pay(**PAYMENT, amount: nil, password: nil)}.must_raise ArgumentError
96
+ _(error.message).must_equal 'amount, password are missing.'
97
+ _(elements[:transfer_and_pay_button].clicked?).must_equal false
98
+ end
99
+
100
+ it "takes the payment given to new()" do
101
+ bpay, elements = bpay(payment: PAYMENT.reject{|name, _| name == :password})
102
+ bpay.pay(password: 'password')
103
+ _(elements[:bpay_customer_reference_number_field].typed).must_equal ['5678']
104
+ _(elements[:bpay_new_bill_payment_submit_button].clicked?).must_equal true
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,13 @@
1
+ # test/NabComAu/Transfer_test.rb
2
+
3
+ require_relative '../helper'
4
+
5
+ describe NabComAu::Transfer do
6
+ describe "#pay" do
7
+ it "raises without using the browser" do
8
+ transfer = NabComAu::Transfer.new(source_bank_account_name_or_number: 'Everyday Account', target_bsb: '000-000', target_bank_account_number: '000000000', note: 'note', amount: '1.00')
9
+ transfer.driver = untouchable_driver
10
+ _{transfer.pay}.must_raise NotImplementedError
11
+ end
12
+ end
13
+ end
data/test/Nab_test.rb ADDED
@@ -0,0 +1,30 @@
1
+ # test/Nab_test.rb
2
+
3
+ require_relative './helper'
4
+ require_relative '../lib/Nab'
5
+
6
+ describe Nab do
7
+ describe ".to_nab_account_number_format" do
8
+ it "groups nine digits in twos, threes and fours" do
9
+ _(Nab.to_nab_account_number_format('123456789')).must_equal '12-345-6789'
10
+ end
11
+
12
+ it "leaves an account number already in that form as it is" do
13
+ _(Nab.to_nab_account_number_format('12-345-6789')).must_equal '12-345-6789'
14
+ end
15
+
16
+ it "regroups an account number with its dashes elsewhere" do
17
+ _(Nab.to_nab_account_number_format('1234-56789')).must_equal '12-345-6789'
18
+ end
19
+
20
+ it "doesn't change the string it's given" do
21
+ account_number = '1234-56789'
22
+ Nab.to_nab_account_number_format(account_number)
23
+ _(account_number).must_equal '1234-56789'
24
+ end
25
+
26
+ it "is nil for an account name" do
27
+ _(Nab.to_nab_account_number_format('Everyday Account')).must_be_nil
28
+ end
29
+ end
30
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,40 @@
1
+ # test/helper.rb
2
+
3
+ # Notes:
4
+ # 1. No browser and no NAB: elements and browsers are stand-ins, which record what's done to them, so as nothing is ever sent anywhere.
5
+
6
+ require 'minitest/autorun'
7
+ require 'minitest-spec-context'
8
+
9
+ require_relative '../lib/NabComAu/Account'
10
+
11
+ # An element which records what's typed into it and whether it's been clicked. One given options is a select, as Selenium::WebDriver::Support::Select wants.
12
+ class StandInElement
13
+ attr_reader :typed, :text
14
+
15
+ def initialize(text: '', options: nil)
16
+ @text, @options = text, options
17
+ @typed = []
18
+ end
19
+
20
+ def clear; @typed.clear; end
21
+ def send_keys(keys); @typed << keys; end
22
+ def click; @clicked = true; end
23
+ def clicked?; !!@clicked; end
24
+ def attribute(name); @text if name.to_s == 'text'; end
25
+ def tag_name; @options ? 'select' : 'input'; end
26
+ def dom_attribute(name); nil; end
27
+ def find_elements(*); @options || []; end
28
+ end
29
+
30
+ def stand_in_select(*texts)
31
+ StandInElement.new(options: texts.map{|text| StandInElement.new(text: text)})
32
+ end
33
+
34
+ # A browser which fails the example if anything asks it to do anything.
35
+ def untouchable_driver
36
+ driver = Object.new
37
+ def driver.method_missing(name, *) = raise("The browser was used: #{name}.")
38
+ def driver.respond_to_missing?(*) = true
39
+ driver
40
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nab_com_au
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.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.8'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.8'
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 NAB Internet Banking with a username and password, and pay a
83
+ bill by BPAY from an account, going as far as the confirmation page unless told
84
+ to confirm.
85
+ email: code@thoran.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - CHANGELOG
91
+ - Gemfile
92
+ - Rakefile
93
+ - lib/Nab.rb
94
+ - lib/NabComAu/Account.rb
95
+ - lib/NabComAu/Bpay.rb
96
+ - lib/NabComAu/Transfer.rb
97
+ - lib/NabComAu/VERSION.rb
98
+ - lib/nab_com_au.rb
99
+ - nab_com_au.gemspec
100
+ - test/NabComAu/Account_test.rb
101
+ - test/NabComAu/Bpay_test.rb
102
+ - test/NabComAu/Transfer_test.rb
103
+ - test/Nab_test.rb
104
+ - test/helper.rb
105
+ homepage: https://github.com/thoran/nab_com_au
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '3.3'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 4.0.23
124
+ specification_version: 4
125
+ summary: Pay bills by BPAY from NAB Internet Banking via Selenium WebDriver.
126
+ test_files: []