nab_com_au 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79c11bf5baf0f70919b24438084f51650b6faa1bc3956e428a16c8420474eff2
4
- data.tar.gz: 5ea65b8fa555359929ff019af8c92a43abb675c0aa761c51b9f270a91aaa7bef
3
+ metadata.gz: 42bf3168adec8ba9d22099b1a270d1209ccb4b26a5fbdaa8211fbfe522384b3c
4
+ data.tar.gz: 804dcfa434860523a8a5e489a499ff0b17a814a8264875df032249172f852547
5
5
  SHA512:
6
- metadata.gz: c66b1df7d1a126b77fcbc8ea903b48dc4663570d05f2a730fc6f5fbedf956e251bed71f3476c4f95f6ac0e0be50da09665b20ae2a3ed52a75642a803dd4822ae
7
- data.tar.gz: 678df5388f00a6bc879de89a1b3276053b22aa85a4fac8d3b6637a1cf12061d705068544e38ab8c0b859e605b5a15de33392de568974daaf9c73e3e223929aa0
6
+ metadata.gz: f976685addd48574eba8f8c9641c2226f4d1405468e810f44770fd305dd368c76eb8179c08b62009996fbce4d6ca8846e7e7e2c5f51a6d30c3a5d4cad674f7bd
7
+ data.tar.gz: 81d6af3f271131702790d5a6069c52f80c2081e498cddc737756b7681cf97dbb5ab23c96d85257798d3cb3eb633a20e0c52122b43b73164a699c8f2ea8c7f476
data/CHANGELOG CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## 20261116
4
4
 
5
+ 0.5.0: ~ NabComAu::Account#login: Waits for the SMS code and the logout button; ~ NabComAu::Account::PAGE_SELECTORS: NAB's new logout button.
6
+
7
+ 1. ~ NabComAu::Account#login: Waits up to default_login_timeout for the logout button and sets @logged_in, so as shutdown logs out.
8
+ 2. + NabComAu::Account#default_login_timeout: Three minutes, for the code NAB now sends by SMS.
9
+ 3. + NabComAu::Account#login_wait
10
+ 4. ~ NabComAu::Account::PAGE_SELECTORS: logout_button_selector: /{id: 'logoutButton'}/{xpath: "//button[@aria-label='Logout']"}/, since the new button's id is shared with an icon of it.
11
+ 5. ~ lib/NabComAu/Account.rb: ~ Notes: + 3 on the logout button, 4 on waiting for the SMS code.
12
+ 6. ~ test/NabComAu/Account_test.rb: Logging in, and giving up waiting, are tested.
13
+ 7. ~ README.md: Credentials say a code is sent by SMS; Limitations lose the note on login not waiting.
14
+ 8. + TODO
15
+ 9. ~ NabComAu::VERSION: /0.4.2/0.5.0/
16
+
17
+
5
18
  0.4.2: + README.md, + LICENSE
6
19
 
7
20
  1. + README.md
data/README.md CHANGED
@@ -33,7 +33,7 @@ $ gem install nab_com_au
33
33
  customer_reference_number: '5678',
34
34
  amount: '1.00'
35
35
  )
36
- nab_account.shutdown # Quits the browser.
36
+ nab_account.shutdown # Logs out, and quits the browser.
37
37
  ```
38
38
  The payment is made: `bpay` goes through NAB's confirmation page, entering the password there, and submits it.
39
39
 
@@ -50,6 +50,8 @@ The username is the NAB ID. It and the password are given, or set afterwards:
50
50
  ```
51
51
  Where either is missing, `login` raises ArgumentError before starting the browser, naming every one missing. `bpay` does the same for the payment's details and the password.
52
52
 
53
+ NAB then sends a code by SMS, which is entered in the browser: `login` waits up to three minutes for it, and for the accounts to appear, so the browser can't be headless.
54
+
53
55
  ### The browser
54
56
 
55
57
  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.
@@ -63,8 +65,6 @@ The browser is WebAccount's: Chrome, unless `browser: :firefox` is given. Given
63
65
 
64
66
  Transfers aren't made yet: `transfer` raises NotImplementedError.
65
67
 
66
- `login` doesn't wait to see that it's logged in, so `logged_in?` stays false, and `shutdown` quits the browser without logging out. `logout` logs out.
67
-
68
68
  The selectors were taken from the live site, and a change to it will break them. Each key of `NabComAu::Account::PAGE_SELECTORS` is also a keyword of `new`, and has a setter, either of which wins over NAB's, so as a selector which has changed can be given without waiting for a new version:
69
69
  ```ruby
70
70
  NabComAu::Account.new(login_page_submit_button_selector: {id: 'loginButton'})
@@ -4,6 +4,8 @@
4
4
  # Notes:
5
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
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
+ # 3. NAB's logout button appears twice, as text and as an icon, each with the id logoutInternetBanking, so as the text one is chosen by its label.
8
+ # 4. login() waits for the logout button for as long as default_login_timeout, so as the code NAB sends by SMS can be entered in the browser.
7
9
 
8
10
  require 'webaccount'
9
11
 
@@ -18,7 +20,7 @@ module NabComAu
18
20
  login_page_username_field_selector: {id: 'username'},
19
21
  login_page_password_field_selector: {id: 'password'},
20
22
  login_page_submit_button_selector: {xpath: "//button[contains(text(), 'Login')]"},
21
- logout_button_selector: {id: 'logoutButton'},
23
+ logout_button_selector: {xpath: "//button[@aria-label='Logout']"},
22
24
  logged_out_selector: {xpath: "//*[contains(text(), 'You have been successfully logged out.')]"}
23
25
  }
24
26
 
@@ -38,6 +40,9 @@ module NabComAu
38
40
  sleep 3
39
41
  login_page_submit_button.click
40
42
  end
43
+ @logged_in = login_wait.until do
44
+ driver.element_present?(logout_button_selector.keys.first, logout_button_selector.values.first)
45
+ end
41
46
  end
42
47
 
43
48
  def bpay(source_bank_account_name_or_number:, biller_name_or_code:, customer_reference_number:, amount:)
@@ -62,5 +67,16 @@ module NabComAu
62
67
  transfer.driver = driver
63
68
  transfer.pay
64
69
  end
70
+
71
+ private
72
+
73
+ # For logging in: the code sent by SMS, as well as the authentication and the redirect.
74
+ def default_login_timeout
75
+ 180
76
+ end
77
+
78
+ def login_wait
79
+ @login_wait ||= Selenium::WebDriver::Wait.new(timeout: default_login_timeout)
80
+ end
65
81
  end
66
82
  end
@@ -2,5 +2,5 @@
2
2
  # NabComAu::VERSION
3
3
 
4
4
  module NabComAu
5
- VERSION = '0.4.2'
5
+ VERSION = '0.5.0'
6
6
  end
@@ -10,6 +10,27 @@ describe NabComAu::Account do
10
10
  NabComAu::Account.new(**args).tap{|account| account.driver = untouchable_driver}
11
11
  end
12
12
 
13
+ # A browser on which the login page's fields and button are stand-ins, and the logout button is present or not as given.
14
+ def login_driver(logged_in:)
15
+ elements = Hash.new{|hash, selector| hash[selector] = StandInElement.new}
16
+ driver = Object.new
17
+ driver.define_singleton_method(:attempt){|&block| block.call}
18
+ driver.define_singleton_method(:get){|url| @url = url}
19
+ driver.define_singleton_method(:url){@url}
20
+ driver.define_singleton_method(:find_element){|how, what| elements[{how => what}]}
21
+ driver.define_singleton_method(:element_present?){|how, what| logged_in}
22
+ [driver, elements]
23
+ end
24
+
25
+ def logging_in_account(logged_in:)
26
+ driver, elements = login_driver(logged_in: logged_in)
27
+ account = NabComAu::Account.new(username: 'username', password: 'password')
28
+ account.driver = driver
29
+ account.define_singleton_method(:sleep){|*|}
30
+ account.define_singleton_method(:default_login_timeout){0.1}
31
+ [account, elements]
32
+ end
33
+
13
34
  def recording_bpay_pay
14
35
  calls = []
15
36
  NabComAu::Bpay.define_singleton_method(:new) do |**payment|
@@ -30,7 +51,7 @@ describe NabComAu::Account do
30
51
  _(account.send(:login_page_username_field_selector)).must_equal({id: 'username'})
31
52
  _(account.send(:login_page_password_field_selector)).must_equal({id: 'password'})
32
53
  _(account.send(:login_page_submit_button_selector)).must_equal({xpath: "//button[contains(text(), 'Login')]"})
33
- _(account.send(:logout_button_selector)).must_equal({id: 'logoutButton'})
54
+ _(account.send(:logout_button_selector)).must_equal({xpath: "//button[@aria-label='Logout']"})
34
55
  _(account.logged_out_selector).must_equal({xpath: "//*[contains(text(), 'You have been successfully logged out.')]"})
35
56
  end
36
57
 
@@ -93,6 +114,26 @@ describe NabComAu::Account do
93
114
  error = _{account.login}.must_raise ArgumentError
94
115
  _(error.message).must_equal 'username, password are missing.'
95
116
  end
117
+
118
+ it "enters the username and password, submits them, and is logged in once the logout button is there" do
119
+ account, elements = logging_in_account(logged_in: true)
120
+ account.login
121
+ _(account.driver.url).must_equal 'https://ib.nab.com.au/nabib/index.jsp'
122
+ _(elements[{id: 'username'}].typed).must_equal ['username']
123
+ _(elements[{id: 'password'}].typed).must_equal ['password']
124
+ _(elements[{xpath: "//button[contains(text(), 'Login')]"}].clicked?).must_equal true
125
+ _(account.logged_in?).must_equal true
126
+ end
127
+
128
+ it "gives up waiting for the logout button after default_login_timeout, not being logged in" do
129
+ account, _elements = logging_in_account(logged_in: false)
130
+ _{account.login}.must_raise Selenium::WebDriver::Error::TimeoutError
131
+ _(account.logged_in?).must_equal false
132
+ end
133
+
134
+ it "waits three minutes for the logout button, by default" do
135
+ _(account.send(:default_login_timeout)).must_equal 180
136
+ end
96
137
  end
97
138
 
98
139
  describe "#bpay" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nab_com_au
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran