webaccount 0.4.0 → 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 +4 -4
- data/CHANGELOG +33 -1
- data/LICENSE +21 -0
- data/README.md +24 -1
- data/lib/{WebAccount → webaccount}/VERSION.rb +1 -1
- data/lib/webaccount.rb +8 -4
- data/test/webaccount_test.rb +76 -0
- data/webaccount.gemspec +2 -1
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6a94193d490acdd37702fbd4d09835e2a54ef201f5d214713e60bae26845c954
|
|
4
|
+
data.tar.gz: 15aff8916367524214eb14a2979b3f9d7695557272f2fe44aa035a59aaccc12a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 04a678d61437fba7d075eea20c1259786ecbfcb47d701305dac1ff8d362231be7f0a6c474a8497b5a3d8f86ec28e99d5a20267744d4bc32bdcf474322e09bc25
|
|
7
|
+
data.tar.gz: 67e7b968e7fcab39c8696c087232cb0b020a60e049bfd5279d1a67653293a868553aac0c7cfc7f9ac05ecb4dc5b339d646c1d286dbb2271a6189bd5747a8ed8d
|
data/CHANGELOG
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
# CHANGELOG
|
|
1
|
+
# webaccount/CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 20261011
|
|
4
|
+
|
|
5
|
+
0.6.0: + WebAccount#still_logged_in?, which says at once whether the page now showing still has the logout button.
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
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.
|
|
11
|
+
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.
|
|
12
|
+
4. ~ CHANGELOG: /# CHANGELOG/# webaccount\/CHANGELOG/, after the repository.
|
|
13
|
+
5. ~ VERSION: /0.5.0/0.6.0/
|
|
14
|
+
|
|
15
|
+
0.5.0: + WebAccount#driver, public, so that the logged-in browser can be driven from outside.
|
|
16
|
+
|
|
17
|
+
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.
|
|
18
|
+
|
|
19
|
+
1. ~ WebAccount#driver(): public, after shutdown(); what it does is unchanged, the browser being made once, with browser() and driver_options(), upon first being asked for.
|
|
20
|
+
2. + test/webaccount_test.rb: driver public, made once, and made with the browser and driver options given, with Selenium::WebDriver.for swapped for a stand-in so that no browser is wanted. All three fail against 0.4.1.
|
|
21
|
+
3. ~ README.md: + Driving the browser once logged in.
|
|
22
|
+
4. ~ VERSION: /0.4.1/0.5.0/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## 20260822
|
|
26
|
+
|
|
27
|
+
0.4.1: + LICENSE, which the gemspec has claimed without one being present.
|
|
28
|
+
|
|
29
|
+
1. + LICENSE: the MIT text, copyright 2020-2026 thoran. spec.license has named MIT with no licence text in the repository, so the gem shipped a licence nobody could read.
|
|
30
|
+
2. ~ webaccount.gemspec: + 'LICENSE' to spec.files, without which the file sits in the repository and still does not ship.
|
|
31
|
+
3. + README.md: a License section, saying MIT, last.
|
|
32
|
+
4. ~ VERSION: /0.4.0/0.4.1/
|
|
33
|
+
|
|
2
34
|
|
|
3
35
|
## 20260717
|
|
4
36
|
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-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
CHANGED
|
@@ -140,6 +140,24 @@ There are two, both overridable in a sub-class:
|
|
|
140
140
|
my_account.shutdown # If necessary it logs out and then kills the selenium session.
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
+
### Driving the browser once logged in
|
|
144
|
+
|
|
145
|
+
`driver` is the logged-in browser, a `Selenium::WebDriver::Driver`, for whatever WebAccount doesn't do itself: fetching pages behind the login, reading them, or taking screenshots of them.
|
|
146
|
+
```ruby
|
|
147
|
+
my_account = MyAccount.new(username: username, password: password)
|
|
148
|
+
my_account.login
|
|
149
|
+
my_account.driver.get('https://mysite.com/members/page')
|
|
150
|
+
my_account.driver.page_source
|
|
151
|
+
my_account.driver.save_screenshot('page.png')
|
|
152
|
+
my_account.shutdown
|
|
153
|
+
```
|
|
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
|
+
|
|
143
161
|
### Overriding the login method to customise logins
|
|
144
162
|
```ruby
|
|
145
163
|
require 'webaccount'
|
|
@@ -174,8 +192,13 @@ Prefer `find` over `driver.find_element`: it waits up to `default_find_timeout`
|
|
|
174
192
|
|
|
175
193
|
## Contributing
|
|
176
194
|
|
|
177
|
-
1. Fork it: https://github.com/thoran/
|
|
195
|
+
1. Fork it: https://github.com/thoran/webaccount/fork
|
|
178
196
|
2. Create your feature branch: `git checkout -b my-new-feature`
|
|
179
197
|
3. Commit your changes: `git commit -am 'Add some feature'`
|
|
180
198
|
4. Push to the branch: `git push origin my-new-feature`
|
|
181
199
|
5. Create a new pull request
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
MIT
|
data/lib/webaccount.rb
CHANGED
|
@@ -56,6 +56,10 @@ class WebAccount
|
|
|
56
56
|
driver.quit
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
+
def driver
|
|
60
|
+
@driver ||= Selenium::WebDriver.for(browser, options: driver_options)
|
|
61
|
+
end
|
|
62
|
+
|
|
59
63
|
# predicate methods
|
|
60
64
|
|
|
61
65
|
def logged_in?
|
|
@@ -68,6 +72,10 @@ class WebAccount
|
|
|
68
72
|
end
|
|
69
73
|
end
|
|
70
74
|
|
|
75
|
+
def still_logged_in?
|
|
76
|
+
@logged_in = driver.element_present?(logout_button_selector.keys.first, logout_button_selector.values.first)
|
|
77
|
+
end
|
|
78
|
+
|
|
71
79
|
private
|
|
72
80
|
|
|
73
81
|
# driver construction
|
|
@@ -88,10 +96,6 @@ class WebAccount
|
|
|
88
96
|
@driver_options || default_driver_options
|
|
89
97
|
end
|
|
90
98
|
|
|
91
|
-
def driver
|
|
92
|
-
@driver ||= Selenium::WebDriver.for(browser, options: driver_options)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
99
|
# waiting
|
|
96
100
|
|
|
97
101
|
# For navigation: a submit, the authentication behind it, and the redirect.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# test/webaccount_test.rb
|
|
2
|
+
|
|
3
|
+
# Notes:
|
|
4
|
+
# 1. No browser: Selenium::WebDriver.for is swapped for a stand-in for the length of
|
|
5
|
+
# each example and put back afterwards, so what is asserted is what WebAccount asks
|
|
6
|
+
# of Selenium and what it hands back.
|
|
7
|
+
|
|
8
|
+
require_relative '../lib/webaccount'
|
|
9
|
+
|
|
10
|
+
require 'minitest/autorun'
|
|
11
|
+
require 'minitest-spec-context'
|
|
12
|
+
|
|
13
|
+
describe WebAccount do
|
|
14
|
+
def with_driver_factory(&block)
|
|
15
|
+
calls = []
|
|
16
|
+
stand_in = Object.new
|
|
17
|
+
original = Selenium::WebDriver.method(:for)
|
|
18
|
+
Selenium::WebDriver.define_singleton_method(:for){|browser, options: nil| calls << [browser, options]; stand_in}
|
|
19
|
+
block.call(stand_in, calls)
|
|
20
|
+
ensure
|
|
21
|
+
Selenium::WebDriver.define_singleton_method(:for, original)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "#driver" do
|
|
25
|
+
it "is public, so that the logged-in browser can be driven from outside" do
|
|
26
|
+
_(WebAccount.public_method_defined?(:driver)).must_equal(true)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "is the browser Selenium made, made once" do
|
|
30
|
+
with_driver_factory do |stand_in, calls|
|
|
31
|
+
account = WebAccount.new
|
|
32
|
+
_(account.driver).must_be_same_as(stand_in)
|
|
33
|
+
_(account.driver).must_be_same_as(stand_in)
|
|
34
|
+
_(calls.length).must_equal(1)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "is made with the browser and driver options given" do
|
|
39
|
+
with_driver_factory do |stand_in, calls|
|
|
40
|
+
WebAccount.new(browser: 'Firefox', driver_options: :options).driver
|
|
41
|
+
_(calls).must_equal([[:firefox, :options]])
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "#still_logged_in?" do
|
|
47
|
+
def account_with_page(logout_button_present)
|
|
48
|
+
page = Object.new
|
|
49
|
+
page.define_singleton_method(:element_present?){|how, what| (@asked ||= []) << [how, what]; logout_button_present}
|
|
50
|
+
page.define_singleton_method(:asked){@asked}
|
|
51
|
+
account = WebAccount.new(logout_button_selector: {css: '#logout'})
|
|
52
|
+
account.instance_variable_set(:@driver, page)
|
|
53
|
+
[account, page]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "is true, and makes logged_in? true, where the page has the logout button" do
|
|
57
|
+
account, page = account_with_page(true)
|
|
58
|
+
_(account.still_logged_in?).must_equal(true)
|
|
59
|
+
_(account.logged_in?).must_equal(true)
|
|
60
|
+
_(page.asked).must_equal([[:css, '#logout']])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "is false, and makes logged_in? false, where the page has not" do
|
|
64
|
+
account, _page = account_with_page(false)
|
|
65
|
+
account.instance_variable_set(:@logged_in, true)
|
|
66
|
+
_(account.still_logged_in?).must_equal(false)
|
|
67
|
+
_(account.logged_in?).must_equal(false)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "asks once rather than waiting for the button to appear" do
|
|
71
|
+
account, page = account_with_page(false)
|
|
72
|
+
account.still_logged_in?
|
|
73
|
+
_(page.asked.length).must_equal(1)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
data/webaccount.gemspec
CHANGED
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
|
|
20
20
|
spec.author = 'thoran'
|
|
21
21
|
spec.email = 'code@thoran.com'
|
|
22
|
-
spec.homepage = '
|
|
22
|
+
spec.homepage = 'https://github.com/thoran/webaccount'
|
|
23
23
|
spec.license = 'MIT'
|
|
24
24
|
|
|
25
25
|
spec.require_paths = ['lib']
|
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
|
|
28
28
|
spec.files = [
|
|
29
29
|
'CHANGELOG',
|
|
30
|
+
'LICENSE',
|
|
30
31
|
'Gemfile',
|
|
31
32
|
Dir['lib/**/*.rb'],
|
|
32
33
|
'Rakefile',
|
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.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
@@ -74,17 +74,19 @@ extra_rdoc_files: []
|
|
|
74
74
|
files:
|
|
75
75
|
- CHANGELOG
|
|
76
76
|
- Gemfile
|
|
77
|
+
- LICENSE
|
|
77
78
|
- README.md
|
|
78
79
|
- Rakefile
|
|
79
80
|
- lib/Thoran/Selenium.rb
|
|
80
81
|
- lib/Thoran/Selenium/WebDriver/Driver/Attempt/attempt.rb
|
|
81
82
|
- lib/Thoran/Selenium/WebDriver/Driver/ElementPresentQ/element_presentQ.rb
|
|
82
|
-
- lib/WebAccount/VERSION.rb
|
|
83
83
|
- lib/web_account.rb
|
|
84
84
|
- lib/webaccount.rb
|
|
85
|
+
- lib/webaccount/VERSION.rb
|
|
85
86
|
- test/Thoran/Selenium/WebDriver/Driver/Attempt_test.rb
|
|
87
|
+
- test/webaccount_test.rb
|
|
86
88
|
- webaccount.gemspec
|
|
87
|
-
homepage:
|
|
89
|
+
homepage: https://github.com/thoran/webaccount
|
|
88
90
|
licenses:
|
|
89
91
|
- MIT
|
|
90
92
|
metadata: {}
|
|
@@ -102,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
102
104
|
- !ruby/object:Gem::Version
|
|
103
105
|
version: '0'
|
|
104
106
|
requirements: []
|
|
105
|
-
rubygems_version: 4.0.
|
|
107
|
+
rubygems_version: 4.0.22
|
|
106
108
|
specification_version: 4
|
|
107
109
|
summary: An abstract super-class for navigating a web-based user account via Selenium
|
|
108
110
|
WebDriver.
|