webaccount 0.5.0 → 0.6.1

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: 90b5b4da3fa0eee7ac4a4c6c85ce3b59a7640bc7aaff8065b7c8432920d8a255
4
- data.tar.gz: 1a5efd14b2d09b0dd2d6eeaef4128272d7e34e18779e62cf968a95455858ee1a
3
+ metadata.gz: 874519c62d687f06115a348e4e5b6dee2d351e5ebbc9be296c7365f95122e6b0
4
+ data.tar.gz: 196013753d9d54cdc05c180920f1d28f9328053c3c3db7977a7c2b6b7059f709
5
5
  SHA512:
6
- metadata.gz: dbf5f58ce0a99f2232796010962a20f39b45a55e8ba0c5c414b2c3c50ea3c8f54fe409ab4b36878d36a5cf849664b187c3119bc3a79e483c50c2e2196f3b55a8
7
- data.tar.gz: 935406e37e640aafd799a60a422314282874d0ffc5369fe398dde3b0948987da01583fc649ffdb47ebf58c421c0881fcf2a00dbeabeb5595ad1e92cac890b37c
6
+ metadata.gz: a4741b9a5ace0a475145490628d6e664a5ac0c805ada36ffd10bebf49ddd0a75312c21afc8a6cfe7152ce2388f38fc50baaec9cb0a5ef5b29e92a8777b8cac9d
7
+ data.tar.gz: ba3085ac593bd153d894d9d20a2ca80051f3828f9f7333d06baf24152e21ef892daea5d6139bad6f5ce63d5dbdc80a8a0144ee6ff4b4fd4ebcfe149100b66b62
data/CHANGELOG CHANGED
@@ -1,7 +1,29 @@
1
- # CHANGELOG
1
+ # webaccount/CHANGELOG
2
+
3
+ ## 20261103
4
+
5
+ 0.6.1: ~ WebAccount#shutdown quits the browser even where logging out fails.
6
+
7
+ A logout which raised, its button not found or the logged-out marker not appearing, left the browser open and still logged in.
8
+
9
+ 1. ~ WebAccount#shutdown(): driver.quit in an ensure.
10
+ 2. ~ test/webaccount_test.rb: + shutdown logs out then quits, quits where logging out raises, and doesn't log out where not logged in. The second fails against 0.6.0.
11
+ 3. ~ README.md: shutdown kills the session even if logging out fails.
12
+ 4. ~ VERSION: /0.6.0/0.6.1/
13
+
2
14
 
3
15
  ## 20261011
4
16
 
17
+ 0.6.0: + WebAccount#still_logged_in?, which says at once whether the page now showing still has the logout button.
18
+
19
+ logged_in? answers from what login() found, and is not told when a session expires afterwards; logged_out? waits up to default_wait_timeout, 30s, for the logged-out marker, which is too long to ask of every page. Something driving the browser from page to page, as 0.5.0 lets it, had no quick way to notice that the session had ended underneath it.
20
+
21
+ 1. + WebAccount#still_logged_in?(): whether the logout button is on the page now showing, by element_present?, which does not wait; and logged_in? is brought into line with the answer.
22
+ 2. ~ test/webaccount_test.rb: + true and false with logged_in? following, and a single look rather than a wait, with a stand-in for the browser. All three fail against 0.5.0.
23
+ 3. ~ README.md: + still_logged_in?, under Driving the browser once logged in; /WebAccount\/fork/webaccount\/fork/ in Contributing, the repository having been renamed webaccount.
24
+ 4. ~ CHANGELOG: /# CHANGELOG/# webaccount\/CHANGELOG/, after the repository.
25
+ 5. ~ VERSION: /0.5.0/0.6.0/
26
+
5
27
  0.5.0: + WebAccount#driver, public, so that the logged-in browser can be driven from outside.
6
28
 
7
29
  driver was private, so once login() had done its work the session it made could be used only by a sub-class. Something which wants the pages behind a login without being a WebAccount, a spider fetching and screenshotting them, had no way to reach the browser holding the session.
data/README.md CHANGED
@@ -137,7 +137,7 @@ There are two, both overridable in a sub-class:
137
137
  my_account = MyAccount.new(username: username, password: password)
138
138
  my_account.login
139
139
  my_account.logout
140
- my_account.shutdown # If necessary it logs out and then kills the selenium session.
140
+ my_account.shutdown # If necessary it logs out, and then, even if logging out fails, kills the selenium session.
141
141
  ```
142
142
 
143
143
  ### Driving the browser once logged in
@@ -152,6 +152,12 @@ There are two, both overridable in a sub-class:
152
152
  my_account.shutdown
153
153
  ```
154
154
 
155
+ `still_logged_in?` says whether the page now showing still has the logout button, at once rather than after waiting, so that something moving from page to page can tell when the session has ended, and log in again:
156
+ ```ruby
157
+ my_account.driver.get(url)
158
+ my_account.login unless my_account.still_logged_in?
159
+ ```
160
+
155
161
  ### Overriding the login method to customise logins
156
162
  ```ruby
157
163
  require 'webaccount'
@@ -186,7 +192,7 @@ Prefer `find` over `driver.find_element`: it waits up to `default_find_timeout`
186
192
 
187
193
  ## Contributing
188
194
 
189
- 1. Fork it: https://github.com/thoran/WebAccount/fork
195
+ 1. Fork it: https://github.com/thoran/webaccount/fork
190
196
  2. Create your feature branch: `git checkout -b my-new-feature`
191
197
  3. Commit your changes: `git commit -am 'Add some feature'`
192
198
  4. Push to the branch: `git push origin my-new-feature`
@@ -2,5 +2,5 @@
2
2
  # WebAccount::VERSION
3
3
 
4
4
  class WebAccount
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.1'
6
6
  end
data/lib/webaccount.rb CHANGED
@@ -51,8 +51,10 @@ class WebAccount
51
51
  end
52
52
  alias_method :logoff, :logout
53
53
 
54
+ # The browser is quit whether or not logging out succeeds, so as a failed logout doesn't leave a logged-in browser behind.
54
55
  def shutdown
55
56
  logout if logged_in?
57
+ ensure
56
58
  driver.quit
57
59
  end
58
60
 
@@ -72,6 +74,10 @@ class WebAccount
72
74
  end
73
75
  end
74
76
 
77
+ def still_logged_in?
78
+ @logged_in = driver.element_present?(logout_button_selector.keys.first, logout_button_selector.values.first)
79
+ end
80
+
75
81
  private
76
82
 
77
83
  # driver construction
@@ -42,4 +42,69 @@ describe WebAccount do
42
42
  end
43
43
  end
44
44
  end
45
+
46
+ describe "#shutdown" do
47
+ def account_with_browser(logged_in:)
48
+ browser = Object.new
49
+ browser.define_singleton_method(:quit){@quit = true}
50
+ browser.define_singleton_method(:quit?){!!@quit}
51
+ account = WebAccount.new
52
+ account.instance_variable_set(:@driver, browser)
53
+ account.instance_variable_set(:@logged_in, logged_in)
54
+ [account, browser]
55
+ end
56
+
57
+ it "logs out, then quits the browser" do
58
+ account, browser = account_with_browser(logged_in: true)
59
+ account.define_singleton_method(:logout){@logged_out = true}
60
+ account.shutdown
61
+ _(account.instance_variable_get(:@logged_out)).must_equal(true)
62
+ _(browser.quit?).must_equal(true)
63
+ end
64
+
65
+ it "quits the browser even where logging out fails" do
66
+ account, browser = account_with_browser(logged_in: true)
67
+ account.define_singleton_method(:logout){raise Selenium::WebDriver::Error::TimeoutError}
68
+ _{account.shutdown}.must_raise(Selenium::WebDriver::Error::TimeoutError)
69
+ _(browser.quit?).must_equal(true)
70
+ end
71
+
72
+ it "doesn't log out where not logged in" do
73
+ account, browser = account_with_browser(logged_in: false)
74
+ account.define_singleton_method(:logout){raise 'logged out'}
75
+ account.shutdown
76
+ _(browser.quit?).must_equal(true)
77
+ end
78
+ end
79
+
80
+ describe "#still_logged_in?" do
81
+ def account_with_page(logout_button_present)
82
+ page = Object.new
83
+ page.define_singleton_method(:element_present?){|how, what| (@asked ||= []) << [how, what]; logout_button_present}
84
+ page.define_singleton_method(:asked){@asked}
85
+ account = WebAccount.new(logout_button_selector: {css: '#logout'})
86
+ account.instance_variable_set(:@driver, page)
87
+ [account, page]
88
+ end
89
+
90
+ it "is true, and makes logged_in? true, where the page has the logout button" do
91
+ account, page = account_with_page(true)
92
+ _(account.still_logged_in?).must_equal(true)
93
+ _(account.logged_in?).must_equal(true)
94
+ _(page.asked).must_equal([[:css, '#logout']])
95
+ end
96
+
97
+ it "is false, and makes logged_in? false, where the page has not" do
98
+ account, _page = account_with_page(false)
99
+ account.instance_variable_set(:@logged_in, true)
100
+ _(account.still_logged_in?).must_equal(false)
101
+ _(account.logged_in?).must_equal(false)
102
+ end
103
+
104
+ it "asks once rather than waiting for the button to appear" do
105
+ account, page = account_with_page(false)
106
+ account.still_logged_in?
107
+ _(page.asked.length).must_equal(1)
108
+ end
109
+ end
45
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webaccount
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  requirements: []
107
- rubygems_version: 4.0.22
107
+ rubygems_version: 4.0.23
108
108
  specification_version: 4
109
109
  summary: An abstract super-class for navigating a web-based user account via Selenium
110
110
  WebDriver.