webaccount 0.9.0 → 0.10.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 +23 -0
- data/README.md +4 -4
- data/lib/WebAccount/VERSION.rb +1 -1
- data/lib/webaccount.rb +27 -44
- data/test/webaccount_test.rb +54 -44
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 429f149a1b147c010525384e4378eeaa6f7a40ae2d63af374a19aefb9d01999a
|
|
4
|
+
data.tar.gz: c62767fed5a2286082e11be10f0ab33dc66695e4c88fd63cb30720b417affb2f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e8488c0edcc9435e62e1c56ed1ea2cba77cfd867a76f982fb726eb1f3c3ad6534cb5e30fb3d97a77ac1cd74c5d898e81195e50cb3e7806b58f6427cf61115258
|
|
7
|
+
data.tar.gz: e1277cdf619a347fdba2264f98454760f9378dc7380e907735a9d4c903fefe81f430bf1b792b1cff7971a0a3475399b8e60e7bfab6481f21459d8e2cf4385485
|
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# webaccount/CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 20261116
|
|
4
|
+
|
|
5
|
+
0.10.0: WebAccount's PAGE_SELECTORS holds the defaults; login and logout name every missing value at once; and logged_out_xpath is gone.
|
|
6
|
+
|
|
7
|
+
1. ~ WebAccount::PAGE_SELECTORS: The defaults for the four selectors on the login page and the logout button.
|
|
8
|
+
2. ~ WebAccount#page_selectors(): WebAccount's PAGE_SELECTORS, with the sub-class's merged over it, less its nil values.
|
|
9
|
+
3. ~ WebAccount#login_page_username_field_selector(), #login_page_password_field_selector(), #login_page_submit_button_selector(), #logout_button_selector(): The value given or set, else page_selectors' value.
|
|
10
|
+
4. - WebAccount#default_login_page_username_field_selector(), #default_login_page_password_field_selector(), #default_login_page_submit_button_selector(), #default_logout_button_selector(): Their values are in PAGE_SELECTORS.
|
|
11
|
+
5. + WebAccount#validate_args(): Raises ArgumentError naming every key whose value is nil.
|
|
12
|
+
6. ~ WebAccount#login(): Validates login_page_url, username and password before starting the browser.
|
|
13
|
+
7. ~ WebAccount#login_page(): - The check of login_page_url, which login() makes.
|
|
14
|
+
8. ~ WebAccount#logout(): Validates logged_out_selector before clicking the logout button.
|
|
15
|
+
9. ~ WebAccount#logged_out?(): - The check of logged_out_selector, which logout() makes.
|
|
16
|
+
10. - WebAccount#required(): Replaced by validate_args().
|
|
17
|
+
11. ~ WebAccount.new(): - logged_out_xpath:.
|
|
18
|
+
12. ~ WebAccount#logged_out_selector(): The value given or set, else page_selectors' value.
|
|
19
|
+
13. - WebAccount#logged_out_xpath(), #logged_out_xpath=(): Deprecated in 0.9.0.
|
|
20
|
+
14. - WebAccount#xpath_selector(): Used only for logged_out_xpath.
|
|
21
|
+
15. ~ test/webaccount_test.rb: Tests that page_selectors merges a sub-class's values over the defaults, keeping a default where the sub-class's value is nil; that login names every missing value before a browser is wanted; that logout names a missing logged_out_selector before clicking the logout button; and that the names removed in 0.9.0 and 0.10.0 are gone.
|
|
22
|
+
16. ~ README.md: The defaults are said to be in WebAccount's PAGE_SELECTORS, and each reader's order to have two steps. Missing values are said to be named all at once. + validate_args, under Page helpers. - logged_out_xpath.
|
|
23
|
+
17. ~ VERSION: /0.9.0/0.10.0/
|
|
24
|
+
|
|
25
|
+
|
|
3
26
|
## 20261115
|
|
4
27
|
|
|
5
28
|
0.9.0: WebAccount page selectors are now public, each with a setter; and the logged-out page is found by a selector (logged_out_selector).
|
data/README.md
CHANGED
|
@@ -81,17 +81,16 @@ WebAccount reads a sub-class's `PAGE_SELECTORS` itself, so the sub-class needn't
|
|
|
81
81
|
my_account = MyAccount.new(username: username, password: password)
|
|
82
82
|
my_account.login_page_url = 'https://test.mysite.com/login'
|
|
83
83
|
```
|
|
84
|
-
`login` raises `ArgumentError
|
|
84
|
+
`login` raises `ArgumentError` before starting the browser, naming whichever of the login page URL, the username and the password are missing. `logout` likewise names a missing logged-out selector.
|
|
85
85
|
|
|
86
86
|
### Where each page selector comes from
|
|
87
87
|
|
|
88
88
|
Each value is found by a public reader of the same name as its keyword, as `login_page_url` or `logout_button_selector`, which takes the first of:
|
|
89
89
|
|
|
90
90
|
1. the value given to `new` or set;
|
|
91
|
-
2. that key of `page_selectors`, which is the class's `PAGE_SELECTORS
|
|
92
|
-
3. for the four selectors on the login page and the logout button, `default_` and the same name, as `default_logout_button_selector`. The login page URL and the logged-out selector have no default.
|
|
91
|
+
2. that key of `page_selectors`, which is the sub-class's `PAGE_SELECTORS` merged over WebAccount's.
|
|
93
92
|
|
|
94
|
-
|
|
93
|
+
WebAccount's `PAGE_SELECTORS` holds the defaults for the four selectors on the login page and the logout button. A key the sub-class leaves out, or gives as `nil`, keeps WebAccount's default. The login page URL and the logged-out selector have no default.
|
|
95
94
|
|
|
96
95
|
So a sub-class can give its values at any of three levels, from the coarsest to the finest.
|
|
97
96
|
|
|
@@ -275,6 +274,7 @@ These are private, for use in a sub-class:
|
|
|
275
274
|
| `click(selector)` | Finds the element afresh on each attempt of `driver.attempt`, so an element replaced by a redrawn page is retried. If the element isn't displayed, for instance a link in a closed menu, it's clicked by JavaScript. |
|
|
276
275
|
| `stale?(element)` | Whether the element has gone from the page, for waiting out a page being redrawn. |
|
|
277
276
|
| `wait_for(selector)` | Waits up to `default_wait_timeout` for any displayed match. |
|
|
277
|
+
| `validate_args(args)` | Raises `ArgumentError` naming every key of `args` whose value is nil, as `username, password are missing.` |
|
|
278
278
|
| `set_value(element, value)` | Sets the value by JavaScript, so that a date picker or the like doesn't open, and then dispatches a bubbling change event. |
|
|
279
279
|
|
|
280
280
|
## Contributing
|
data/lib/WebAccount/VERSION.rb
CHANGED
data/lib/webaccount.rb
CHANGED
|
@@ -6,8 +6,13 @@ require_relative './Thoran/Selenium'
|
|
|
6
6
|
require_relative './WebAccount/VERSION'
|
|
7
7
|
|
|
8
8
|
class WebAccount
|
|
9
|
-
#
|
|
10
|
-
PAGE_SELECTORS = {
|
|
9
|
+
# The defaults, which a sub-class's own PAGE_SELECTORS overrides key by key.
|
|
10
|
+
PAGE_SELECTORS = {
|
|
11
|
+
login_page_username_field_selector: {name: 'username'},
|
|
12
|
+
login_page_password_field_selector: {name: 'password'},
|
|
13
|
+
login_page_submit_button_selector: {xpath: '//input[@type="submit" and @value="Login"]'},
|
|
14
|
+
logout_button_selector: {xpath: '//input[@type="submit" and @value="Logout"]'},
|
|
15
|
+
}
|
|
11
16
|
|
|
12
17
|
attr_accessor :username
|
|
13
18
|
attr_accessor :password
|
|
@@ -22,8 +27,7 @@ class WebAccount
|
|
|
22
27
|
login_page_username_field_selector: nil, login_page_password_field_selector: nil,
|
|
23
28
|
login_page_submit_button_selector: nil,
|
|
24
29
|
logout_button_selector: nil,
|
|
25
|
-
logged_out_selector: nil
|
|
26
|
-
logged_out_xpath: nil
|
|
30
|
+
logged_out_selector: nil
|
|
27
31
|
)
|
|
28
32
|
@username, @password = username, password
|
|
29
33
|
@browser, @driver_options = browser, driver_options
|
|
@@ -35,13 +39,13 @@ class WebAccount
|
|
|
35
39
|
@login_page_submit_button_selector = login_page_submit_button_selector
|
|
36
40
|
@logout_button_selector = logout_button_selector
|
|
37
41
|
@logged_out_selector = logged_out_selector
|
|
38
|
-
@logged_out_xpath = logged_out_xpath
|
|
39
42
|
end
|
|
40
43
|
|
|
41
44
|
def login(username: nil, password: nil)
|
|
42
45
|
@logged_in = false
|
|
43
46
|
username ||= self.username
|
|
44
47
|
password ||= self.password
|
|
48
|
+
validate_args(login_page_url: login_page_url, username: username, password: password)
|
|
45
49
|
driver.attempt do
|
|
46
50
|
get_login_page
|
|
47
51
|
enter_username(username)
|
|
@@ -55,6 +59,7 @@ class WebAccount
|
|
|
55
59
|
alias_method :logon, :login
|
|
56
60
|
|
|
57
61
|
def logout
|
|
62
|
+
validate_args(logged_out_selector: logged_out_selector)
|
|
58
63
|
logout_button.click
|
|
59
64
|
if logged_out?
|
|
60
65
|
@logged_in = false
|
|
@@ -83,9 +88,8 @@ class WebAccount
|
|
|
83
88
|
end
|
|
84
89
|
|
|
85
90
|
def logged_out?
|
|
86
|
-
selector = required(:logged_out_selector)
|
|
87
91
|
driver_wait.until do
|
|
88
|
-
driver.element_present?(
|
|
92
|
+
driver.element_present?(logged_out_selector.keys.first, logged_out_selector.values.first)
|
|
89
93
|
end
|
|
90
94
|
end
|
|
91
95
|
|
|
@@ -107,41 +111,36 @@ class WebAccount
|
|
|
107
111
|
end
|
|
108
112
|
|
|
109
113
|
def login_page_username_field_selector
|
|
110
|
-
@login_page_username_field_selector || page_selectors[:login_page_username_field_selector]
|
|
114
|
+
@login_page_username_field_selector || page_selectors[:login_page_username_field_selector]
|
|
111
115
|
end
|
|
112
116
|
|
|
113
117
|
def login_page_password_field_selector
|
|
114
|
-
@login_page_password_field_selector || page_selectors[:login_page_password_field_selector]
|
|
118
|
+
@login_page_password_field_selector || page_selectors[:login_page_password_field_selector]
|
|
115
119
|
end
|
|
116
120
|
|
|
117
121
|
def login_page_submit_button_selector
|
|
118
|
-
@login_page_submit_button_selector || page_selectors[:login_page_submit_button_selector]
|
|
122
|
+
@login_page_submit_button_selector || page_selectors[:login_page_submit_button_selector]
|
|
119
123
|
end
|
|
120
124
|
|
|
121
125
|
def logout_button_selector
|
|
122
|
-
@logout_button_selector || page_selectors[:logout_button_selector]
|
|
126
|
+
@logout_button_selector || page_selectors[:logout_button_selector]
|
|
123
127
|
end
|
|
124
128
|
|
|
125
129
|
def logged_out_selector
|
|
126
|
-
@logged_out_selector ||
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
# logged_out_xpath deprecated for logged_out_selector. Keep till 0.10.0.
|
|
130
|
-
|
|
131
|
-
attr_writer :logged_out_xpath
|
|
132
|
-
|
|
133
|
-
def logged_out_xpath
|
|
134
|
-
@logged_out_xpath || page_selectors[:logged_out_xpath]
|
|
130
|
+
@logged_out_selector || page_selectors[:logged_out_selector]
|
|
135
131
|
end
|
|
136
132
|
|
|
137
133
|
private
|
|
138
134
|
|
|
139
|
-
def
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
135
|
+
def validate_args(args)
|
|
136
|
+
missing_args = []
|
|
137
|
+
args.each do |arg_name, value|
|
|
138
|
+
missing_args << arg_name unless value
|
|
139
|
+
end
|
|
140
|
+
return if missing_args.empty?
|
|
141
|
+
aggregate_error = missing_args.join(', ')
|
|
142
|
+
copula = missing_args.count > 1 ? 'are' : 'is'
|
|
143
|
+
raise ArgumentError, "#{aggregate_error} #{copula} missing."
|
|
145
144
|
end
|
|
146
145
|
|
|
147
146
|
# driver construction
|
|
@@ -283,13 +282,13 @@ class WebAccount
|
|
|
283
282
|
end
|
|
284
283
|
|
|
285
284
|
def page_selectors
|
|
286
|
-
self.class::PAGE_SELECTORS
|
|
285
|
+
PAGE_SELECTORS.merge(self.class::PAGE_SELECTORS.compact)
|
|
287
286
|
end
|
|
288
287
|
|
|
289
288
|
# logging in
|
|
290
289
|
|
|
291
290
|
def login_page
|
|
292
|
-
driver.get(
|
|
291
|
+
driver.get(login_page_url)
|
|
293
292
|
end
|
|
294
293
|
alias_method :get_login_page, :login_page
|
|
295
294
|
|
|
@@ -298,10 +297,6 @@ class WebAccount
|
|
|
298
297
|
username_field.send_keys(username)
|
|
299
298
|
end
|
|
300
299
|
|
|
301
|
-
def default_login_page_username_field_selector
|
|
302
|
-
{name: 'username'}
|
|
303
|
-
end
|
|
304
|
-
|
|
305
300
|
def username_field
|
|
306
301
|
find(login_page_username_field_selector)
|
|
307
302
|
end
|
|
@@ -311,28 +306,16 @@ class WebAccount
|
|
|
311
306
|
password_field.send_keys(password)
|
|
312
307
|
end
|
|
313
308
|
|
|
314
|
-
def default_login_page_password_field_selector
|
|
315
|
-
{name: 'password'}
|
|
316
|
-
end
|
|
317
|
-
|
|
318
309
|
def password_field
|
|
319
310
|
find(login_page_password_field_selector)
|
|
320
311
|
end
|
|
321
312
|
|
|
322
|
-
def default_login_page_submit_button_selector
|
|
323
|
-
{xpath: '//input[@type="submit" and @value="Login"]'}
|
|
324
|
-
end
|
|
325
|
-
|
|
326
313
|
def login_page_submit_button
|
|
327
314
|
find(login_page_submit_button_selector)
|
|
328
315
|
end
|
|
329
316
|
|
|
330
317
|
# logging out
|
|
331
318
|
|
|
332
|
-
def default_logout_button_selector
|
|
333
|
-
{xpath: '//input[@type="submit" and @value="Logout"]'}
|
|
334
|
-
end
|
|
335
|
-
|
|
336
319
|
def logout_button
|
|
337
320
|
find(logout_button_selector)
|
|
338
321
|
end
|
data/test/webaccount_test.rb
CHANGED
|
@@ -172,55 +172,70 @@ describe WebAccount do
|
|
|
172
172
|
end
|
|
173
173
|
end
|
|
174
174
|
|
|
175
|
-
describe "
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
describe "the names before 0.10.0's" do
|
|
176
|
+
it "are gone" do
|
|
177
|
+
%i{
|
|
178
|
+
username_field_selector password_field_selector
|
|
179
|
+
default_username_field_selector default_password_field_selector
|
|
180
|
+
default_login_page_username_field_selector default_login_page_password_field_selector
|
|
181
|
+
default_login_page_submit_button_selector default_logout_button_selector
|
|
182
|
+
logged_out_xpath logged_out_xpath=
|
|
183
|
+
}.each do |name|
|
|
184
|
+
_(WebAccount.method_defined?(name) || WebAccount.private_method_defined?(name)).must_equal(false)
|
|
185
|
+
end
|
|
178
186
|
end
|
|
179
187
|
|
|
180
|
-
it "
|
|
181
|
-
_
|
|
188
|
+
it "are logged_out_xpath:, no longer a keyword" do
|
|
189
|
+
_{WebAccount.new(logged_out_xpath: '//div')}.must_raise(ArgumentError)
|
|
182
190
|
end
|
|
191
|
+
end
|
|
183
192
|
|
|
184
|
-
|
|
185
|
-
|
|
193
|
+
describe "#page_selectors" do
|
|
194
|
+
it "is WebAccount's PAGE_SELECTORS, the defaults, where a sub-class gives none" do
|
|
195
|
+
_(WebAccount.new.send(:page_selectors)).must_equal(WebAccount::PAGE_SELECTORS)
|
|
186
196
|
end
|
|
187
197
|
|
|
188
|
-
it "is
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
_(
|
|
192
|
-
_(
|
|
198
|
+
it "is a sub-class's PAGE_SELECTORS merged over WebAccount's, key by key" do
|
|
199
|
+
account_class = Class.new(WebAccount){const_set(:PAGE_SELECTORS, {login_page_url: 'https://subclass.example/login', logout_button_selector: {css: '#logout'}})}
|
|
200
|
+
page_selectors = account_class.new.send(:page_selectors)
|
|
201
|
+
_(page_selectors[:login_page_url]).must_equal('https://subclass.example/login')
|
|
202
|
+
_(page_selectors[:logout_button_selector]).must_equal({css: '#logout'})
|
|
203
|
+
_(page_selectors[:login_page_username_field_selector]).must_equal({name: 'username'})
|
|
193
204
|
end
|
|
194
205
|
|
|
195
|
-
it "
|
|
196
|
-
|
|
197
|
-
_(account_class
|
|
206
|
+
it "keeps WebAccount's default where a sub-class's value is nil" do
|
|
207
|
+
account_class = Class.new(WebAccount){const_set(:PAGE_SELECTORS, {login_page_username_field_selector: nil})}
|
|
208
|
+
_(account_class.new.login_page_username_field_selector).must_equal({name: 'username'})
|
|
198
209
|
end
|
|
199
210
|
|
|
200
|
-
it "
|
|
201
|
-
|
|
211
|
+
it "is overridden for every reader, and can keep a parent's values" do
|
|
212
|
+
parent = Class.new(WebAccount){const_set(:PAGE_SELECTORS, {login_page_url: 'https://parent.example/login', logged_out_selector: {id: 'parent'}})}
|
|
213
|
+
child = Class.new(parent){private def page_selectors = super.merge(login_page_url: 'https://child.example/login')}
|
|
214
|
+
_(child.new.login_page_url).must_equal('https://child.example/login')
|
|
215
|
+
_(child.new.logged_out_selector).must_equal({id: 'parent'})
|
|
202
216
|
end
|
|
203
217
|
end
|
|
204
218
|
|
|
205
|
-
describe "
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
219
|
+
describe "#login" do
|
|
220
|
+
def account_without_browser(**args)
|
|
221
|
+
account = WebAccount.new(**args)
|
|
222
|
+
account.define_singleton_method(:driver){raise 'a browser was wanted'}
|
|
223
|
+
account
|
|
210
224
|
end
|
|
211
|
-
end
|
|
212
225
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
_(account_class.new.send(:page_selectors)).must_equal({login_page_url: 'https://subclass.example/login'})
|
|
226
|
+
it "names every missing value at once, before a browser is wanted" do
|
|
227
|
+
error = _{account_without_browser.login}.must_raise(ArgumentError)
|
|
228
|
+
_(error.message).must_equal('login_page_url, username, password are missing.')
|
|
217
229
|
end
|
|
218
230
|
|
|
219
|
-
it "
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
231
|
+
it "names the one missing value" do
|
|
232
|
+
error = _{account_without_browser(login_page_url: 'https://given.example/login', username: 'user').login}.must_raise(ArgumentError)
|
|
233
|
+
_(error.message).must_equal('password is missing.')
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
it "takes the username and password given to it as well as to new" do
|
|
237
|
+
error = _{account_without_browser(login_page_url: 'https://given.example/login', username: 'user').login(password: 'secret')}.must_raise(RuntimeError)
|
|
238
|
+
_(error.message).must_equal('a browser was wanted')
|
|
224
239
|
end
|
|
225
240
|
end
|
|
226
241
|
|
|
@@ -238,13 +253,6 @@ describe WebAccount do
|
|
|
238
253
|
account.send(:login_page)
|
|
239
254
|
_(browser.got).must_equal(['https://given.example/login'])
|
|
240
255
|
end
|
|
241
|
-
|
|
242
|
-
it "names login_page_url: where there is none" do
|
|
243
|
-
account, browser = account_with_browser(WebAccount.new)
|
|
244
|
-
error = _{account.send(:login_page)}.must_raise(ArgumentError)
|
|
245
|
-
_(error.message).must_equal('missing keyword: :login_page_url')
|
|
246
|
-
_(browser.got).must_be_nil
|
|
247
|
-
end
|
|
248
256
|
end
|
|
249
257
|
|
|
250
258
|
describe "#logged_out?" do
|
|
@@ -261,12 +269,14 @@ describe WebAccount do
|
|
|
261
269
|
_(account.logged_out?).must_equal(true)
|
|
262
270
|
_(page.asked).must_equal([[:css, '#given']])
|
|
263
271
|
end
|
|
272
|
+
end
|
|
264
273
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
_(
|
|
274
|
+
describe "#logout" do
|
|
275
|
+
it "names logged_out_selector where there is none, before clicking the logout button" do
|
|
276
|
+
account = WebAccount.new
|
|
277
|
+
account.define_singleton_method(:logout_button){raise 'the logout button was wanted'}
|
|
278
|
+
error = _{account.logout}.must_raise(ArgumentError)
|
|
279
|
+
_(error.message).must_equal('logged_out_selector is missing.')
|
|
270
280
|
end
|
|
271
281
|
end
|
|
272
282
|
|