webaccount 0.8.0 → 0.9.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 +38 -20
- data/README.md +13 -12
- data/lib/WebAccount/VERSION.rb +1 -1
- data/lib/webaccount.rb +56 -46
- data/test/webaccount_test.rb +75 -32
- 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: 6bfe32e37ba437205c4ec943500e4a0c819eff7c9f3bf6adb27c5b37e1d729ee
|
|
4
|
+
data.tar.gz: 100ddd0d21d047b45bfa2c95b030cb0dbabf4740fa7e2045c9c3793ae1c338da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1184c9709bdbda58b943e27e73c1ad7ef70bf8010a6cb7f47b24da63568182946726cc95da2b26597df272a8f8e9e0543b516e1a61b8ca201f02b4a52568d995
|
|
7
|
+
data.tar.gz: eeef9cb683e28e4be6611c6872851f39f6c1e628dc7b35e7e15dfc6f9ef7c7d2068b111afb50d5b59df28b3c367d152340142a750235607c7601b7def3c3fa88
|
data/CHANGELOG
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
## 20261115
|
|
4
4
|
|
|
5
|
+
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).
|
|
6
|
+
|
|
7
|
+
1. ~ WebAccount#login_page_url(), #login_page_username_field_selector(), #login_page_password_field_selector(), #login_page_submit_button_selector(), #logout_button_selector(): Public.
|
|
8
|
+
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=().
|
|
9
|
+
3. ~ WebAccount.new(): + logged_out_selector:.
|
|
10
|
+
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.
|
|
11
|
+
5. ~ WebAccount#logged_out_xpath(): Public. Deprecated for logged_out_selector until 0.10.0.
|
|
12
|
+
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.
|
|
13
|
+
7. + WebAccount#required(): The named value, or ArgumentError naming it.
|
|
14
|
+
8. ~ WebAccount#login_page(): Uses required().
|
|
15
|
+
9. + WebAccount#xpath_selector().
|
|
16
|
+
10. - WebAccount#username_field_selector(), #password_field_selector(), #default_username_field_selector(), #default_password_field_selector(): Deprecated in 0.8.0.
|
|
17
|
+
11. ~ WebAccount#default_login_page_username_field_selector(), #default_login_page_password_field_selector(): The defaults themselves.
|
|
18
|
+
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.
|
|
19
|
+
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'.
|
|
20
|
+
14. ~ CHANGELOG: The markers and capitals of 0.4.1's to 0.8.0's entries are corrected.
|
|
21
|
+
15. ~ VERSION: /0.8.0/0.9.0/
|
|
22
|
+
|
|
5
23
|
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
24
|
|
|
7
25
|
1. + WebAccount::PAGE_SELECTORS: {}.
|
|
@@ -13,8 +31,8 @@
|
|
|
13
31
|
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
32
|
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
33
|
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
|
|
34
|
+
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:.
|
|
35
|
+
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
36
|
12. ~ VERSION: /0.7.0/0.8.0/
|
|
19
37
|
|
|
20
38
|
|
|
@@ -22,18 +40,18 @@
|
|
|
22
40
|
|
|
23
41
|
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
42
|
|
|
25
|
-
1.
|
|
43
|
+
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
44
|
2. + WebAccount#download_directory.
|
|
27
|
-
3. ~ WebAccount#driver():
|
|
45
|
+
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
46
|
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?():
|
|
47
|
+
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.
|
|
48
|
+
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.
|
|
49
|
+
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.
|
|
50
|
+
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.
|
|
51
|
+
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
52
|
10. + WebAccount#click(), #stale?(), #wait_for(), #set_value(), private.
|
|
35
|
-
11. ~ test/webaccount_test.rb:
|
|
36
|
-
12. ~ README.md:
|
|
53
|
+
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?().
|
|
54
|
+
12. ~ README.md: Describes Chrome and Firefox, profile and download directories, headless, window size, user agent, waiting for downloads, and the page helpers.
|
|
37
55
|
13. ~ VERSION: /0.6.1/0.7.0/
|
|
38
56
|
|
|
39
57
|
|
|
@@ -43,9 +61,9 @@
|
|
|
43
61
|
|
|
44
62
|
A logout which raised, its button not found or the logged-out marker not appearing, left the browser open and still logged in.
|
|
45
63
|
|
|
46
|
-
1. ~ WebAccount#shutdown(): driver
|
|
47
|
-
2. ~ test/webaccount_test.rb:
|
|
48
|
-
3. ~ README.md: shutdown kills the session even if logging out fails.
|
|
64
|
+
1. ~ WebAccount#shutdown(): Quits the driver in an ensure.
|
|
65
|
+
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.
|
|
66
|
+
3. ~ README.md: Says that shutdown kills the session even if logging out fails.
|
|
49
67
|
4. ~ VERSION: /0.6.0/0.6.1/
|
|
50
68
|
|
|
51
69
|
|
|
@@ -55,8 +73,8 @@ A logout which raised, its button not found or the logged-out marker not appeari
|
|
|
55
73
|
|
|
56
74
|
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
75
|
|
|
58
|
-
1. + WebAccount#still_logged_in?():
|
|
59
|
-
2. ~ test/webaccount_test.rb:
|
|
76
|
+
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.
|
|
77
|
+
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
78
|
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
79
|
4. ~ CHANGELOG: /# CHANGELOG/# webaccount\/CHANGELOG/, after the repository.
|
|
62
80
|
5. ~ VERSION: /0.5.0/0.6.0/
|
|
@@ -65,8 +83,8 @@ logged_in? answers from what login() found, and is not told when a session expir
|
|
|
65
83
|
|
|
66
84
|
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
85
|
|
|
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.
|
|
86
|
+
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.
|
|
87
|
+
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
88
|
3. ~ README.md: + Driving the browser once logged in.
|
|
71
89
|
4. ~ VERSION: /0.4.1/0.5.0/
|
|
72
90
|
|
|
@@ -75,9 +93,9 @@ driver was private, so once login() had done its work the session it made could
|
|
|
75
93
|
|
|
76
94
|
0.4.1: + LICENSE, which the gemspec has claimed without one being present.
|
|
77
95
|
|
|
78
|
-
1. + LICENSE:
|
|
96
|
+
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
97
|
2. ~ webaccount.gemspec: + 'LICENSE' to spec.files, without which the file sits in the repository and still does not ship.
|
|
80
|
-
3.
|
|
98
|
+
3. ~ README.md: + A License section, saying MIT, last.
|
|
81
99
|
4. ~ VERSION: /0.4.0/0.4.1/
|
|
82
100
|
|
|
83
101
|
|
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,24 @@ $ 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`, naming `login_page_url:`, if there's no login page URL.
|
|
84
|
+
`login` raises `ArgumentError`, naming `login_page_url:`, if there's no login page URL, and `logout` likewise, naming `logged_out_selector:`, if there's no 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
|
|
90
|
+
1. the value given to `new` or set;
|
|
88
91
|
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
|
|
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.
|
|
90
93
|
|
|
91
|
-
The
|
|
94
|
+
The logged-out selector was a bare XPath named `logged_out_xpath` before 0.9.0. That name stays until 0.10.0, as a keyword, a key of `PAGE_SELECTORS` and an accessor, its XPath being taken as `{xpath: ...}`, and `logged_out_selector` given the same way winning over it.
|
|
92
95
|
|
|
93
96
|
So a sub-class can give its values at any of three levels, from the coarsest to the finest.
|
|
94
97
|
|
|
@@ -110,8 +113,6 @@ A single reader, for one value which has to be worked out. Starting with `super
|
|
|
110
113
|
class MyAccount < WebAccount
|
|
111
114
|
PAGE_SELECTORS = {...}
|
|
112
115
|
|
|
113
|
-
private
|
|
114
|
-
|
|
115
116
|
def login_page_url
|
|
116
117
|
super || "https://mysite.com/login?t=#{Time.now.to_i}"
|
|
117
118
|
end
|
data/lib/WebAccount/VERSION.rb
CHANGED
data/lib/webaccount.rb
CHANGED
|
@@ -22,6 +22,7 @@ class WebAccount
|
|
|
22
22
|
login_page_username_field_selector: nil, login_page_password_field_selector: nil,
|
|
23
23
|
login_page_submit_button_selector: nil,
|
|
24
24
|
logout_button_selector: nil,
|
|
25
|
+
logged_out_selector: nil,
|
|
25
26
|
logged_out_xpath: nil
|
|
26
27
|
)
|
|
27
28
|
@username, @password = username, password
|
|
@@ -33,6 +34,7 @@ class WebAccount
|
|
|
33
34
|
@login_page_username_field_selector, @login_page_password_field_selector = login_page_username_field_selector, login_page_password_field_selector
|
|
34
35
|
@login_page_submit_button_selector = login_page_submit_button_selector
|
|
35
36
|
@logout_button_selector = logout_button_selector
|
|
37
|
+
@logged_out_selector = logged_out_selector
|
|
36
38
|
@logged_out_xpath = logged_out_xpath
|
|
37
39
|
end
|
|
38
40
|
|
|
@@ -81,8 +83,9 @@ class WebAccount
|
|
|
81
83
|
end
|
|
82
84
|
|
|
83
85
|
def logged_out?
|
|
86
|
+
selector = required(:logged_out_selector)
|
|
84
87
|
driver_wait.until do
|
|
85
|
-
driver.element_present?(
|
|
88
|
+
driver.element_present?(selector.keys.first, selector.values.first)
|
|
86
89
|
end
|
|
87
90
|
end
|
|
88
91
|
|
|
@@ -90,8 +93,57 @@ class WebAccount
|
|
|
90
93
|
@logged_in = driver.element_present?(logout_button_selector.keys.first, logout_button_selector.values.first)
|
|
91
94
|
end
|
|
92
95
|
|
|
96
|
+
# page selectors
|
|
97
|
+
|
|
98
|
+
attr_writer :login_page_url
|
|
99
|
+
attr_writer :login_page_username_field_selector
|
|
100
|
+
attr_writer :login_page_password_field_selector
|
|
101
|
+
attr_writer :login_page_submit_button_selector
|
|
102
|
+
attr_writer :logout_button_selector
|
|
103
|
+
attr_writer :logged_out_selector
|
|
104
|
+
|
|
105
|
+
def login_page_url
|
|
106
|
+
@login_page_url || page_selectors[:login_page_url]
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def login_page_username_field_selector
|
|
110
|
+
@login_page_username_field_selector || page_selectors[:login_page_username_field_selector] || default_login_page_username_field_selector
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def login_page_password_field_selector
|
|
114
|
+
@login_page_password_field_selector || page_selectors[:login_page_password_field_selector] || default_login_page_password_field_selector
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def login_page_submit_button_selector
|
|
118
|
+
@login_page_submit_button_selector || page_selectors[:login_page_submit_button_selector] || default_login_page_submit_button_selector
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def logout_button_selector
|
|
122
|
+
@logout_button_selector || page_selectors[:logout_button_selector] || default_logout_button_selector
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def logged_out_selector
|
|
126
|
+
@logged_out_selector || xpath_selector(@logged_out_xpath) || page_selectors[:logged_out_selector] || xpath_selector(page_selectors[:logged_out_xpath])
|
|
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]
|
|
135
|
+
end
|
|
136
|
+
|
|
93
137
|
private
|
|
94
138
|
|
|
139
|
+
def required(name)
|
|
140
|
+
send(name) || raise(ArgumentError, "missing keyword: :#{name}")
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def xpath_selector(xpath)
|
|
144
|
+
xpath && {xpath: xpath}
|
|
145
|
+
end
|
|
146
|
+
|
|
95
147
|
# driver construction
|
|
96
148
|
|
|
97
149
|
def default_browser
|
|
@@ -236,12 +288,8 @@ class WebAccount
|
|
|
236
288
|
|
|
237
289
|
# logging in
|
|
238
290
|
|
|
239
|
-
def login_page_url
|
|
240
|
-
@login_page_url || page_selectors[:login_page_url]
|
|
241
|
-
end
|
|
242
|
-
|
|
243
291
|
def login_page
|
|
244
|
-
driver.get(
|
|
292
|
+
driver.get(required(:login_page_url))
|
|
245
293
|
end
|
|
246
294
|
alias_method :get_login_page, :login_page
|
|
247
295
|
|
|
@@ -251,11 +299,7 @@ class WebAccount
|
|
|
251
299
|
end
|
|
252
300
|
|
|
253
301
|
def default_login_page_username_field_selector
|
|
254
|
-
|
|
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
|
|
302
|
+
{name: 'username'}
|
|
259
303
|
end
|
|
260
304
|
|
|
261
305
|
def username_field
|
|
@@ -268,11 +312,7 @@ class WebAccount
|
|
|
268
312
|
end
|
|
269
313
|
|
|
270
314
|
def default_login_page_password_field_selector
|
|
271
|
-
|
|
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
|
|
315
|
+
{name: 'password'}
|
|
276
316
|
end
|
|
277
317
|
|
|
278
318
|
def password_field
|
|
@@ -283,10 +323,6 @@ class WebAccount
|
|
|
283
323
|
{xpath: '//input[@type="submit" and @value="Login"]'}
|
|
284
324
|
end
|
|
285
325
|
|
|
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
326
|
def login_page_submit_button
|
|
291
327
|
find(login_page_submit_button_selector)
|
|
292
328
|
end
|
|
@@ -297,33 +333,7 @@ class WebAccount
|
|
|
297
333
|
{xpath: '//input[@type="submit" and @value="Logout"]'}
|
|
298
334
|
end
|
|
299
335
|
|
|
300
|
-
def logout_button_selector
|
|
301
|
-
@logout_button_selector || page_selectors[:logout_button_selector] || default_logout_button_selector
|
|
302
|
-
end
|
|
303
|
-
|
|
304
336
|
def logout_button
|
|
305
337
|
find(logout_button_selector)
|
|
306
338
|
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
339
|
end
|
data/test/webaccount_test.rb
CHANGED
|
@@ -137,44 +137,76 @@ 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 "
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
private def default_username_field_selector = {id: 'old-username'}
|
|
168
|
-
private def default_password_field_selector = {id: 'old-password'}
|
|
169
|
-
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'})
|
|
175
|
+
describe "logged_out_xpath, until 0.10.0" do
|
|
176
|
+
def account_class(page_selectors)
|
|
177
|
+
Class.new(WebAccount){const_set(:PAGE_SELECTORS, page_selectors)}
|
|
172
178
|
end
|
|
173
179
|
|
|
174
|
-
it "
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
180
|
+
it "is given as a keyword, as the XPath of logged_out_selector" do
|
|
181
|
+
_(WebAccount.new(logged_out_xpath: '//div[@id="given"]').logged_out_selector).must_equal({xpath: '//div[@id="given"]'})
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it "is given in PAGE_SELECTORS, as the XPath of logged_out_selector" do
|
|
185
|
+
_(account_class(logged_out_xpath: '//div[@id="sub-class"]').new.logged_out_selector).must_equal({xpath: '//div[@id="sub-class"]'})
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it "is set, as the XPath of logged_out_selector" do
|
|
189
|
+
account = WebAccount.new
|
|
190
|
+
account.logged_out_xpath = '//div[@id="set"]'
|
|
191
|
+
_(account.logged_out_selector).must_equal({xpath: '//div[@id="set"]'})
|
|
192
|
+
_(account.logged_out_xpath).must_equal('//div[@id="set"]')
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
it "gives way to logged_out_selector, given the same way" do
|
|
196
|
+
_(WebAccount.new(logged_out_selector: {css: '#given'}, logged_out_xpath: '//div').logged_out_selector).must_equal({css: '#given'})
|
|
197
|
+
_(account_class(logged_out_selector: {css: '#sub-class'}, logged_out_xpath: '//div').new.logged_out_selector).must_equal({css: '#sub-class'})
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it "as a keyword, wins over a sub-class's PAGE_SELECTORS[:logged_out_selector]" do
|
|
201
|
+
_(account_class(logged_out_selector: {css: '#sub-class'}).new(logged_out_xpath: '//div').logged_out_selector).must_equal({xpath: '//div'})
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
describe "the names before 0.8.0's" do
|
|
206
|
+
it "are gone" do
|
|
207
|
+
%i{username_field_selector password_field_selector default_username_field_selector default_password_field_selector}.each do |name|
|
|
208
|
+
_(WebAccount.method_defined?(name) || WebAccount.private_method_defined?(name)).must_equal(false)
|
|
209
|
+
end
|
|
178
210
|
end
|
|
179
211
|
end
|
|
180
212
|
|
|
@@ -185,10 +217,10 @@ describe WebAccount do
|
|
|
185
217
|
end
|
|
186
218
|
|
|
187
219
|
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',
|
|
220
|
+
parent = Class.new(WebAccount){const_set(:PAGE_SELECTORS, {login_page_url: 'https://parent.example/login', logged_out_selector: {id: 'parent'}})}
|
|
189
221
|
child = Class.new(parent){private def page_selectors = super.merge(login_page_url: 'https://child.example/login')}
|
|
190
|
-
_(child.new.
|
|
191
|
-
_(child.new.
|
|
222
|
+
_(child.new.login_page_url).must_equal('https://child.example/login')
|
|
223
|
+
_(child.new.logged_out_selector).must_equal({id: 'parent'})
|
|
192
224
|
end
|
|
193
225
|
end
|
|
194
226
|
|
|
@@ -216,14 +248,25 @@ describe WebAccount do
|
|
|
216
248
|
end
|
|
217
249
|
|
|
218
250
|
describe "#logged_out?" do
|
|
219
|
-
|
|
251
|
+
def account_with_page(account)
|
|
220
252
|
page = Object.new
|
|
221
253
|
page.define_singleton_method(:element_present?){|how, what| (@asked ||= []) << [how, what]; true}
|
|
222
254
|
page.define_singleton_method(:asked){@asked}
|
|
223
|
-
account = WebAccount.new(logged_out_xpath: '//div[@id="given"]')
|
|
224
255
|
account.instance_variable_set(:@driver, page)
|
|
256
|
+
[account, page]
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "looks for logged_out_selector" do
|
|
260
|
+
account, page = account_with_page(WebAccount.new(logged_out_selector: {css: '#given'}))
|
|
225
261
|
_(account.logged_out?).must_equal(true)
|
|
226
|
-
_(page.asked).must_equal([[:
|
|
262
|
+
_(page.asked).must_equal([[:css, '#given']])
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
it "names logged_out_selector: where there is none" do
|
|
266
|
+
account, page = account_with_page(WebAccount.new)
|
|
267
|
+
error = _{account.logged_out?}.must_raise(ArgumentError)
|
|
268
|
+
_(error.message).must_equal('missing keyword: :logged_out_selector')
|
|
269
|
+
_(page.asked).must_be_nil
|
|
227
270
|
end
|
|
228
271
|
end
|
|
229
272
|
|