webaccount 0.8.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 +61 -20
- data/README.md +14 -13
- data/lib/WebAccount/VERSION.rb +1 -1
- data/lib/webaccount.rb +58 -65
- data/test/webaccount_test.rb +94 -41
- 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,7 +1,48 @@
|
|
|
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
|
|
|
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).
|
|
29
|
+
|
|
30
|
+
1. ~ WebAccount#login_page_url(), #login_page_username_field_selector(), #login_page_password_field_selector(), #login_page_submit_button_selector(), #logout_button_selector(): Public.
|
|
31
|
+
2. + WebAccount#login_page_url=(), #login_page_username_field_selector=(), #login_page_password_field_selector=(), #login_page_submit_button_selector=(), #logout_button_selector=(), #logged_out_selector=(), #logged_out_xpath=().
|
|
32
|
+
3. ~ WebAccount.new(): + logged_out_selector:.
|
|
33
|
+
4. + WebAccount#logged_out_selector(): The value given or set, else page_selectors' value. A logged_out_xpath is taken as {xpath: ...}, after a logged_out_selector given the same way.
|
|
34
|
+
5. ~ WebAccount#logged_out_xpath(): Public. Deprecated for logged_out_selector until 0.10.0.
|
|
35
|
+
6. ~ WebAccount#logged_out?(): Looks for logged_out_selector, and raises ArgumentError naming logged_out_selector: where there is none, rather than handing nil to the browser.
|
|
36
|
+
7. + WebAccount#required(): The named value, or ArgumentError naming it.
|
|
37
|
+
8. ~ WebAccount#login_page(): Uses required().
|
|
38
|
+
9. + WebAccount#xpath_selector().
|
|
39
|
+
10. - WebAccount#username_field_selector(), #password_field_selector(), #default_username_field_selector(), #default_password_field_selector(): Deprecated in 0.8.0.
|
|
40
|
+
11. ~ WebAccount#default_login_page_username_field_selector(), #default_login_page_password_field_selector(): The defaults themselves.
|
|
41
|
+
12. ~ test/webaccount_test.rb: Each of the six is public with a setter, and the value set wins over PAGE_SELECTORS; logged_out_xpath given as a keyword, in PAGE_SELECTORS or set, and giving way to logged_out_selector; the names before 0.8.0's are gone; logged_out? looks for logged_out_selector, and names it where there is none.
|
|
42
|
+
13. ~ README.md: logged_out_selector in place of logged_out_xpath. /Where each page value comes from/Where each page selector comes from/. The setters are shown, and the readers are public. logged_out_xpath's deprecation in place of the old names'.
|
|
43
|
+
14. ~ CHANGELOG: The markers and capitals of 0.4.1's to 0.8.0's entries are corrected.
|
|
44
|
+
15. ~ VERSION: /0.8.0/0.9.0/
|
|
45
|
+
|
|
5
46
|
0.8.0: WebAccount reads a sub-class's PAGE_SELECTORS, so that a sub-class needn't override initialize to pass them in.
|
|
6
47
|
|
|
7
48
|
1. + WebAccount::PAGE_SELECTORS: {}.
|
|
@@ -13,8 +54,8 @@
|
|
|
13
54
|
7. ~ WebAccount#login_page_username_field_selector(), #login_page_password_field_selector(), #login_page_submit_button_selector(), #logout_button_selector(): The keyword if given, else page_selectors' value, else the default.
|
|
14
55
|
8. ~ WebAccount#login_page(): Gets login_page_url, and raises ArgumentError naming login_page_url: where there is none, rather than handing nil to the browser.
|
|
15
56
|
9. ~ WebAccount#logged_out?(): Looks for logged_out_xpath.
|
|
16
|
-
10. ~ test/webaccount_test.rb:
|
|
17
|
-
11. ~ README.md: MyAccount.new() without PAGE_SELECTORS merged into it
|
|
57
|
+
10. ~ test/webaccount_test.rb: Each of the six is tested with neither, with a sub-class's PAGE_SELECTORS, and with the keyword winning over it; and so are page_selectors overridden, keeping a parent's values, the old names until 0.9.0, and login_page naming the missing login_page_url:.
|
|
58
|
+
11. ~ README.md: MyAccount.new() is called without PAGE_SELECTORS merged into it. The keywords are said to win over PAGE_SELECTORS. + Where each page value comes from, giving the order each reader takes, the old names until 0.9.0, and overriding PAGE_SELECTORS, page_selectors or a single reader.
|
|
18
59
|
12. ~ VERSION: /0.7.0/0.8.0/
|
|
19
60
|
|
|
20
61
|
|
|
@@ -22,18 +63,18 @@
|
|
|
22
63
|
|
|
23
64
|
0.7.0: Default browser options for Chrome and Firefox: a profile directory, if given, kept between runs, downloads into a download directory without asking, headless, a window size and a user agent; and waiting for a download to finish.
|
|
24
65
|
|
|
25
|
-
1.
|
|
66
|
+
1. ~ WebAccount.new(): + profile_directory:, + download_directory:, the latter defaulting to ~/Downloads, both expanded; + headless:, false by default; + window_size:, a width and a height; + user_agent:.
|
|
26
67
|
2. + WebAccount#download_directory.
|
|
27
|
-
3. ~ WebAccount#driver():
|
|
68
|
+
3. ~ WebAccount#driver(): The window is resized to window_size, if given, once the browser has started, so as it holds for any browser and whether or not driver_options are given.
|
|
28
69
|
4. ~ WebAccount#default_driver_options(): Chrome's or Firefox's options, by browser(); nil for other browsers, as before.
|
|
29
|
-
5. + WebAccount#default_chrome_options():
|
|
30
|
-
6. + WebAccount#default_firefox_options():
|
|
31
|
-
7. + WebAccount#wait_for_download(), #newest_download():
|
|
32
|
-
8. + WebAccount#download_wait(), #default_download_timeout():
|
|
33
|
-
9. + WebAccount#downloading?():
|
|
70
|
+
5. + WebAccount#default_chrome_options(): The profile directory, if given, as --user-data-dir; --headless=new, if headless; --user-agent, if given; the automation flags masked; no offer to save passwords; downloads into download_directory without asking, opening nothing, PDFs saved rather than shown.
|
|
71
|
+
6. + WebAccount#default_firefox_options(): The profile directory, if given, by -profile, which geckodriver uses in place; -headless, if headless; general.useragent.override, if a user agent is given; no offer to save passwords; downloads into download_directory without asking, PDFs saved rather than shown. Firefox has no preference which masks navigator.webdriver.
|
|
72
|
+
7. + WebAccount#wait_for_download(), #newest_download(): The newest finished file with the extension given, csv by default, changed in download_directory since the time given.
|
|
73
|
+
8. + WebAccount#download_wait(), #default_download_timeout(): A Wait of its own for downloads, at 120s; default_wait_timeout's 30s is for logging in, and would give up on a large file still arriving.
|
|
74
|
+
9. + WebAccount#downloading?(): Whether a file's partner is still beside it: Chrome's <name>.crdownload, or Firefox's <stem>.<random>.<extensions>.part, where Firefox has already made an empty file under the final name.
|
|
34
75
|
10. + WebAccount#click(), #stale?(), #wait_for(), #set_value(), private.
|
|
35
|
-
11. ~ test/webaccount_test.rb:
|
|
36
|
-
12. ~ README.md:
|
|
76
|
+
11. ~ test/webaccount_test.rb: Tests of the options for each browser, with and without a profile, a download directory, headless and a user agent; the window sized or not; driver_options: over-riding them; finding a download, past one with its .crdownload or .part still there and one older than since; click() and stale?().
|
|
77
|
+
12. ~ README.md: Describes Chrome and Firefox, profile and download directories, headless, window size, user agent, waiting for downloads, and the page helpers.
|
|
37
78
|
13. ~ VERSION: /0.6.1/0.7.0/
|
|
38
79
|
|
|
39
80
|
|
|
@@ -43,9 +84,9 @@
|
|
|
43
84
|
|
|
44
85
|
A logout which raised, its button not found or the logged-out marker not appearing, left the browser open and still logged in.
|
|
45
86
|
|
|
46
|
-
1. ~ WebAccount#shutdown(): driver
|
|
47
|
-
2. ~ test/webaccount_test.rb:
|
|
48
|
-
3. ~ README.md: shutdown kills the session even if logging out fails.
|
|
87
|
+
1. ~ WebAccount#shutdown(): Quits the driver in an ensure.
|
|
88
|
+
2. ~ test/webaccount_test.rb: Tests that 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.
|
|
89
|
+
3. ~ README.md: Says that shutdown kills the session even if logging out fails.
|
|
49
90
|
4. ~ VERSION: /0.6.0/0.6.1/
|
|
50
91
|
|
|
51
92
|
|
|
@@ -55,8 +96,8 @@ A logout which raised, its button not found or the logged-out marker not appeari
|
|
|
55
96
|
|
|
56
97
|
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.
|
|
57
98
|
|
|
58
|
-
1. + WebAccount#still_logged_in?():
|
|
59
|
-
2. ~ test/webaccount_test.rb:
|
|
99
|
+
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.
|
|
100
|
+
2. ~ test/webaccount_test.rb: Tests of true and false, with logged_in? following, and of a single look rather than a wait, with a stand-in for the browser. All three fail against 0.5.0.
|
|
60
101
|
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.
|
|
61
102
|
4. ~ CHANGELOG: /# CHANGELOG/# webaccount\/CHANGELOG/, after the repository.
|
|
62
103
|
5. ~ VERSION: /0.5.0/0.6.0/
|
|
@@ -65,8 +106,8 @@ logged_in? answers from what login() found, and is not told when a session expir
|
|
|
65
106
|
|
|
66
107
|
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.
|
|
67
108
|
|
|
68
|
-
1. ~ WebAccount#driver():
|
|
69
|
-
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.
|
|
109
|
+
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.
|
|
110
|
+
2. + test/webaccount_test.rb: Tests that driver is 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.
|
|
70
111
|
3. ~ README.md: + Driving the browser once logged in.
|
|
71
112
|
4. ~ VERSION: /0.4.1/0.5.0/
|
|
72
113
|
|
|
@@ -75,9 +116,9 @@ driver was private, so once login() had done its work the session it made could
|
|
|
75
116
|
|
|
76
117
|
0.4.1: + LICENSE, which the gemspec has claimed without one being present.
|
|
77
118
|
|
|
78
|
-
1. + LICENSE:
|
|
119
|
+
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.
|
|
79
120
|
2. ~ webaccount.gemspec: + 'LICENSE' to spec.files, without which the file sits in the repository and still does not ship.
|
|
80
|
-
3.
|
|
121
|
+
3. ~ README.md: + A License section, saying MIT, last.
|
|
81
122
|
4. ~ VERSION: /0.4.0/0.4.1/
|
|
82
123
|
|
|
83
124
|
|
data/README.md
CHANGED
|
@@ -33,7 +33,7 @@ $ gem install webaccount
|
|
|
33
33
|
# => #<MyAccount @username=username, @password=password, @login_page_url=nil,
|
|
34
34
|
# @login_page_password_field_selector=nil, @login_page_username_field_selector=nil,
|
|
35
35
|
# @login_page_submit_button_selector=nil,
|
|
36
|
-
# @logout_button_selector=nil, @
|
|
36
|
+
# @logout_button_selector=nil, @logged_out_selector=nil>
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
#### 2. With explicit defaults, then in the comment the ultimate defaults if those values remain nil
|
|
@@ -47,7 +47,7 @@ $ gem install webaccount
|
|
|
47
47
|
login_page_password_field_selector: nil, # Will default to: {name: 'password'}
|
|
48
48
|
login_page_submit_button_selector: nil, # Will default to: {xpath: '//input[@type="submit" and @value="Login"]'}
|
|
49
49
|
logout_button_selector: nil, # Will default to: {xpath: '//input[@type="submit" and @value="Logout"]'}
|
|
50
|
-
|
|
50
|
+
logged_out_selector: nil, # No default value for this, and logout and shutdown require it.
|
|
51
51
|
}
|
|
52
52
|
end
|
|
53
53
|
|
|
@@ -66,7 +66,7 @@ $ gem install webaccount
|
|
|
66
66
|
login_page_password_field_selector: {id: 'password'},
|
|
67
67
|
login_page_submit_button_selector: {xpath: '//button[@type="submit" and @value="Login"]'},
|
|
68
68
|
logout_button_selector: {css: '#button-logout'},
|
|
69
|
-
|
|
69
|
+
logged_out_selector: {xpath: '//div[@class="logged-out"]'},
|
|
70
70
|
}
|
|
71
71
|
end
|
|
72
72
|
|
|
@@ -74,21 +74,23 @@ $ gem install webaccount
|
|
|
74
74
|
# => #<MyAccount @username=username, @password=password...>
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
WebAccount reads a sub-class's `PAGE_SELECTORS` itself, so the sub-class needn't override `initialize`. Each key is also a keyword of `new`, which wins over the sub-class's value:
|
|
77
|
+
WebAccount reads a sub-class's `PAGE_SELECTORS` itself, so the sub-class needn't override `initialize`. Each key is also a keyword of `new`, and has a setter, either of which wins over the sub-class's value:
|
|
78
78
|
```ruby
|
|
79
79
|
MyAccount.new(username: username, password: password, login_page_url: 'https://test.mysite.com/login')
|
|
80
|
+
|
|
81
|
+
my_account = MyAccount.new(username: username, password: password)
|
|
82
|
+
my_account.login_page_url = 'https://test.mysite.com/login'
|
|
80
83
|
```
|
|
81
|
-
`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.
|
|
82
85
|
|
|
83
|
-
### Where each page
|
|
86
|
+
### Where each page selector comes from
|
|
84
87
|
|
|
85
|
-
Each value is found by a
|
|
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:
|
|
86
89
|
|
|
87
|
-
1. the
|
|
88
|
-
2. that key of `page_selectors`, which is the class's `PAGE_SELECTORS
|
|
89
|
-
3. for the four selectors, `default_` and the same name, as `default_logout_button_selector`. The login page URL and the logged-out XPath have no default.
|
|
90
|
+
1. the value given to `new` or set;
|
|
91
|
+
2. that key of `page_selectors`, which is the sub-class's `PAGE_SELECTORS` merged over WebAccount's.
|
|
90
92
|
|
|
91
|
-
|
|
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.
|
|
92
94
|
|
|
93
95
|
So a sub-class can give its values at any of three levels, from the coarsest to the finest.
|
|
94
96
|
|
|
@@ -110,8 +112,6 @@ A single reader, for one value which has to be worked out. Starting with `super
|
|
|
110
112
|
class MyAccount < WebAccount
|
|
111
113
|
PAGE_SELECTORS = {...}
|
|
112
114
|
|
|
113
|
-
private
|
|
114
|
-
|
|
115
115
|
def login_page_url
|
|
116
116
|
super || "https://mysite.com/login?t=#{Time.now.to_i}"
|
|
117
117
|
end
|
|
@@ -274,6 +274,7 @@ These are private, for use in a sub-class:
|
|
|
274
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. |
|
|
275
275
|
| `stale?(element)` | Whether the element has gone from the page, for waiting out a page being redrawn. |
|
|
276
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.` |
|
|
277
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. |
|
|
278
279
|
|
|
279
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,7 +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
|
-
|
|
30
|
+
logged_out_selector: nil
|
|
26
31
|
)
|
|
27
32
|
@username, @password = username, password
|
|
28
33
|
@browser, @driver_options = browser, driver_options
|
|
@@ -33,13 +38,14 @@ class WebAccount
|
|
|
33
38
|
@login_page_username_field_selector, @login_page_password_field_selector = login_page_username_field_selector, login_page_password_field_selector
|
|
34
39
|
@login_page_submit_button_selector = login_page_submit_button_selector
|
|
35
40
|
@logout_button_selector = logout_button_selector
|
|
36
|
-
@
|
|
41
|
+
@logged_out_selector = logged_out_selector
|
|
37
42
|
end
|
|
38
43
|
|
|
39
44
|
def login(username: nil, password: nil)
|
|
40
45
|
@logged_in = false
|
|
41
46
|
username ||= self.username
|
|
42
47
|
password ||= self.password
|
|
48
|
+
validate_args(login_page_url: login_page_url, username: username, password: password)
|
|
43
49
|
driver.attempt do
|
|
44
50
|
get_login_page
|
|
45
51
|
enter_username(username)
|
|
@@ -53,6 +59,7 @@ class WebAccount
|
|
|
53
59
|
alias_method :logon, :login
|
|
54
60
|
|
|
55
61
|
def logout
|
|
62
|
+
validate_args(logged_out_selector: logged_out_selector)
|
|
56
63
|
logout_button.click
|
|
57
64
|
if logged_out?
|
|
58
65
|
@logged_in = false
|
|
@@ -82,7 +89,7 @@ class WebAccount
|
|
|
82
89
|
|
|
83
90
|
def logged_out?
|
|
84
91
|
driver_wait.until do
|
|
85
|
-
driver.element_present?(
|
|
92
|
+
driver.element_present?(logged_out_selector.keys.first, logged_out_selector.values.first)
|
|
86
93
|
end
|
|
87
94
|
end
|
|
88
95
|
|
|
@@ -90,8 +97,52 @@ class WebAccount
|
|
|
90
97
|
@logged_in = driver.element_present?(logout_button_selector.keys.first, logout_button_selector.values.first)
|
|
91
98
|
end
|
|
92
99
|
|
|
100
|
+
# page selectors
|
|
101
|
+
|
|
102
|
+
attr_writer :login_page_url
|
|
103
|
+
attr_writer :login_page_username_field_selector
|
|
104
|
+
attr_writer :login_page_password_field_selector
|
|
105
|
+
attr_writer :login_page_submit_button_selector
|
|
106
|
+
attr_writer :logout_button_selector
|
|
107
|
+
attr_writer :logged_out_selector
|
|
108
|
+
|
|
109
|
+
def login_page_url
|
|
110
|
+
@login_page_url || page_selectors[:login_page_url]
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def login_page_username_field_selector
|
|
114
|
+
@login_page_username_field_selector || page_selectors[:login_page_username_field_selector]
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def login_page_password_field_selector
|
|
118
|
+
@login_page_password_field_selector || page_selectors[:login_page_password_field_selector]
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def login_page_submit_button_selector
|
|
122
|
+
@login_page_submit_button_selector || page_selectors[:login_page_submit_button_selector]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def logout_button_selector
|
|
126
|
+
@logout_button_selector || page_selectors[:logout_button_selector]
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def logged_out_selector
|
|
130
|
+
@logged_out_selector || page_selectors[:logged_out_selector]
|
|
131
|
+
end
|
|
132
|
+
|
|
93
133
|
private
|
|
94
134
|
|
|
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."
|
|
144
|
+
end
|
|
145
|
+
|
|
95
146
|
# driver construction
|
|
96
147
|
|
|
97
148
|
def default_browser
|
|
@@ -231,17 +282,13 @@ class WebAccount
|
|
|
231
282
|
end
|
|
232
283
|
|
|
233
284
|
def page_selectors
|
|
234
|
-
self.class::PAGE_SELECTORS
|
|
285
|
+
PAGE_SELECTORS.merge(self.class::PAGE_SELECTORS.compact)
|
|
235
286
|
end
|
|
236
287
|
|
|
237
288
|
# logging in
|
|
238
289
|
|
|
239
|
-
def login_page_url
|
|
240
|
-
@login_page_url || page_selectors[:login_page_url]
|
|
241
|
-
end
|
|
242
|
-
|
|
243
290
|
def login_page
|
|
244
|
-
driver.get(login_page_url
|
|
291
|
+
driver.get(login_page_url)
|
|
245
292
|
end
|
|
246
293
|
alias_method :get_login_page, :login_page
|
|
247
294
|
|
|
@@ -250,14 +297,6 @@ class WebAccount
|
|
|
250
297
|
username_field.send_keys(username)
|
|
251
298
|
end
|
|
252
299
|
|
|
253
|
-
def default_login_page_username_field_selector
|
|
254
|
-
default_username_field_selector
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
def login_page_username_field_selector
|
|
258
|
-
@login_page_username_field_selector || page_selectors[:login_page_username_field_selector] || default_login_page_username_field_selector
|
|
259
|
-
end
|
|
260
|
-
|
|
261
300
|
def username_field
|
|
262
301
|
find(login_page_username_field_selector)
|
|
263
302
|
end
|
|
@@ -267,63 +306,17 @@ class WebAccount
|
|
|
267
306
|
password_field.send_keys(password)
|
|
268
307
|
end
|
|
269
308
|
|
|
270
|
-
def default_login_page_password_field_selector
|
|
271
|
-
default_password_field_selector
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
def login_page_password_field_selector
|
|
275
|
-
@login_page_password_field_selector || page_selectors[:login_page_password_field_selector] || default_login_page_password_field_selector
|
|
276
|
-
end
|
|
277
|
-
|
|
278
309
|
def password_field
|
|
279
310
|
find(login_page_password_field_selector)
|
|
280
311
|
end
|
|
281
312
|
|
|
282
|
-
def default_login_page_submit_button_selector
|
|
283
|
-
{xpath: '//input[@type="submit" and @value="Login"]'}
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
def login_page_submit_button_selector
|
|
287
|
-
@login_page_submit_button_selector || page_selectors[:login_page_submit_button_selector] || default_login_page_submit_button_selector
|
|
288
|
-
end
|
|
289
|
-
|
|
290
313
|
def login_page_submit_button
|
|
291
314
|
find(login_page_submit_button_selector)
|
|
292
315
|
end
|
|
293
316
|
|
|
294
317
|
# logging out
|
|
295
318
|
|
|
296
|
-
def default_logout_button_selector
|
|
297
|
-
{xpath: '//input[@type="submit" and @value="Logout"]'}
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
def logout_button_selector
|
|
301
|
-
@logout_button_selector || page_selectors[:logout_button_selector] || default_logout_button_selector
|
|
302
|
-
end
|
|
303
|
-
|
|
304
319
|
def logout_button
|
|
305
320
|
find(logout_button_selector)
|
|
306
321
|
end
|
|
307
|
-
|
|
308
|
-
def logged_out_xpath
|
|
309
|
-
@logged_out_xpath || page_selectors[:logged_out_xpath]
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
# Until 0.9.0, the names before 0.8.0's, by which a sub-class may still override the defaults. The defaults themselves move into default_login_page_username_field_selector and default_login_page_password_field_selector then.
|
|
313
|
-
|
|
314
|
-
def default_username_field_selector
|
|
315
|
-
{name: 'username'}
|
|
316
|
-
end
|
|
317
|
-
|
|
318
|
-
def default_password_field_selector
|
|
319
|
-
{name: 'password'}
|
|
320
|
-
end
|
|
321
|
-
|
|
322
|
-
def username_field_selector
|
|
323
|
-
login_page_username_field_selector
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
def password_field_selector
|
|
327
|
-
login_page_password_field_selector
|
|
328
|
-
end
|
|
329
322
|
end
|
data/test/webaccount_test.rb
CHANGED
|
@@ -137,58 +137,105 @@ describe WebAccount do
|
|
|
137
137
|
end
|
|
138
138
|
|
|
139
139
|
{
|
|
140
|
-
login_page_url:
|
|
141
|
-
login_page_username_field_selector:
|
|
142
|
-
login_page_password_field_selector:
|
|
143
|
-
login_page_submit_button_selector:
|
|
144
|
-
logout_button_selector:
|
|
145
|
-
|
|
146
|
-
}.each do |
|
|
147
|
-
describe "##{
|
|
148
|
-
it "is
|
|
149
|
-
|
|
140
|
+
login_page_url: nil,
|
|
141
|
+
login_page_username_field_selector: {name: 'username'},
|
|
142
|
+
login_page_password_field_selector: {name: 'password'},
|
|
143
|
+
login_page_submit_button_selector: {xpath: '//input[@type="submit" and @value="Login"]'},
|
|
144
|
+
logout_button_selector: {xpath: '//input[@type="submit" and @value="Logout"]'},
|
|
145
|
+
logged_out_selector: nil,
|
|
146
|
+
}.each do |name, default|
|
|
147
|
+
describe "##{name}" do
|
|
148
|
+
it "is public, as is its setter" do
|
|
149
|
+
_(WebAccount.public_method_defined?(name)).must_equal(true)
|
|
150
|
+
_(WebAccount.public_method_defined?(:"#{name}=")).must_equal(true)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it "is WebAccount's own where neither #{name}: nor PAGE_SELECTORS gives one" do
|
|
154
|
+
value = WebAccount.new.public_send(name)
|
|
150
155
|
default ? _(value).must_equal(default) : _(value).must_be_nil
|
|
151
156
|
end
|
|
152
157
|
|
|
153
|
-
it "is a sub-class's PAGE_SELECTORS[:#{
|
|
154
|
-
_(account_class(
|
|
158
|
+
it "is a sub-class's PAGE_SELECTORS[:#{name}]" do
|
|
159
|
+
_(account_class(name => 'from the sub-class').new.public_send(name)).must_equal('from the sub-class')
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "is #{name}: over a sub-class's PAGE_SELECTORS" do
|
|
163
|
+
_(account_class(name => 'from the sub-class').new(name => 'given').public_send(name)).must_equal('given')
|
|
155
164
|
end
|
|
156
165
|
|
|
157
|
-
it "is
|
|
158
|
-
|
|
166
|
+
it "is the value set, over a sub-class's PAGE_SELECTORS" do
|
|
167
|
+
account = account_class(name => 'from the sub-class').new
|
|
168
|
+
account.public_send(:"#{name}=", 'set')
|
|
169
|
+
_(account.public_send(name)).must_equal('set')
|
|
159
170
|
end
|
|
160
171
|
end
|
|
161
172
|
end
|
|
162
173
|
end
|
|
163
174
|
|
|
164
|
-
describe "the names before 0.
|
|
165
|
-
it "are
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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)
|
|
169
185
|
end
|
|
170
|
-
_(account_class.new.send(:login_page_username_field_selector)).must_equal({id: 'old-username'})
|
|
171
|
-
_(account_class.new.send(:login_page_password_field_selector)).must_equal({id: 'old-password'})
|
|
172
186
|
end
|
|
173
187
|
|
|
174
|
-
it "are
|
|
175
|
-
|
|
176
|
-
_(account.send(:username_field_selector)).must_equal({id: 'u'})
|
|
177
|
-
_(account.send(:password_field_selector)).must_equal({id: 'p'})
|
|
188
|
+
it "are logged_out_xpath:, no longer a keyword" do
|
|
189
|
+
_{WebAccount.new(logged_out_xpath: '//div')}.must_raise(ArgumentError)
|
|
178
190
|
end
|
|
179
191
|
end
|
|
180
192
|
|
|
181
193
|
describe "#page_selectors" do
|
|
182
|
-
it "is the class
|
|
183
|
-
|
|
184
|
-
|
|
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)
|
|
196
|
+
end
|
|
197
|
+
|
|
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'})
|
|
204
|
+
end
|
|
205
|
+
|
|
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'})
|
|
185
209
|
end
|
|
186
210
|
|
|
187
211
|
it "is overridden for every reader, and can keep a parent's values" do
|
|
188
|
-
parent = Class.new(WebAccount){const_set(:PAGE_SELECTORS, {login_page_url: 'https://parent.example/login',
|
|
212
|
+
parent = Class.new(WebAccount){const_set(:PAGE_SELECTORS, {login_page_url: 'https://parent.example/login', logged_out_selector: {id: 'parent'}})}
|
|
189
213
|
child = Class.new(parent){private def page_selectors = super.merge(login_page_url: 'https://child.example/login')}
|
|
190
|
-
_(child.new.
|
|
191
|
-
_(child.new.
|
|
214
|
+
_(child.new.login_page_url).must_equal('https://child.example/login')
|
|
215
|
+
_(child.new.logged_out_selector).must_equal({id: 'parent'})
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
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
|
|
224
|
+
end
|
|
225
|
+
|
|
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.')
|
|
229
|
+
end
|
|
230
|
+
|
|
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')
|
|
192
239
|
end
|
|
193
240
|
end
|
|
194
241
|
|
|
@@ -206,24 +253,30 @@ describe WebAccount do
|
|
|
206
253
|
account.send(:login_page)
|
|
207
254
|
_(browser.got).must_equal(['https://given.example/login'])
|
|
208
255
|
end
|
|
209
|
-
|
|
210
|
-
it "names login_page_url: where there is none" do
|
|
211
|
-
account, browser = account_with_browser(WebAccount.new)
|
|
212
|
-
error = _{account.send(:login_page)}.must_raise(ArgumentError)
|
|
213
|
-
_(error.message).must_equal('missing keyword: :login_page_url')
|
|
214
|
-
_(browser.got).must_be_nil
|
|
215
|
-
end
|
|
216
256
|
end
|
|
217
257
|
|
|
218
258
|
describe "#logged_out?" do
|
|
219
|
-
|
|
259
|
+
def account_with_page(account)
|
|
220
260
|
page = Object.new
|
|
221
261
|
page.define_singleton_method(:element_present?){|how, what| (@asked ||= []) << [how, what]; true}
|
|
222
262
|
page.define_singleton_method(:asked){@asked}
|
|
223
|
-
account = WebAccount.new(logged_out_xpath: '//div[@id="given"]')
|
|
224
263
|
account.instance_variable_set(:@driver, page)
|
|
264
|
+
[account, page]
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
it "looks for logged_out_selector" do
|
|
268
|
+
account, page = account_with_page(WebAccount.new(logged_out_selector: {css: '#given'}))
|
|
225
269
|
_(account.logged_out?).must_equal(true)
|
|
226
|
-
_(page.asked).must_equal([[:
|
|
270
|
+
_(page.asked).must_equal([[:css, '#given']])
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
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.')
|
|
227
280
|
end
|
|
228
281
|
end
|
|
229
282
|
|