Class: WebAccount
- Inherits:
-
Object
- Object
- WebAccount
- Defined in:
- lib/WebAccount.rb,
lib/WebAccount/VERSION.rb
Constant Summary collapse
- VERSION =
'0.3.1'
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#user_agent_alias ⇒ Object
writeonly
Sets the attribute user_agent_alias.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(username: nil, password: nil, login_page_url: nil, login_page_username_field_selector: nil, login_page_password_field_selector: nil, login_page_submit_button_selector: nil, logout_button_selector: nil, logged_out_xpath: nil) ⇒ WebAccount
constructor
A new instance of WebAccount.
-
#logged_in? ⇒ Boolean
predicate methods.
- #logged_out? ⇒ Boolean
- #login(username: nil, password: nil) ⇒ Object (also: #logon)
- #logout ⇒ Object (also: #logoff)
- #shutdown ⇒ Object
Constructor Details
#initialize(username: nil, password: nil, login_page_url: nil, login_page_username_field_selector: nil, login_page_password_field_selector: nil, login_page_submit_button_selector: nil, logout_button_selector: nil, logged_out_xpath: nil) ⇒ WebAccount
Returns a new instance of WebAccount.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/WebAccount.rb', line 13 def initialize( username: nil, password: nil, login_page_url: nil, login_page_username_field_selector: nil, login_page_password_field_selector: nil, login_page_submit_button_selector: nil, logout_button_selector: nil, logged_out_xpath: nil ) @username, @password = username, password @login_page_url = login_page_url @login_page_username_field_selector, @login_page_password_field_selector = login_page_username_field_selector, login_page_password_field_selector @login_page_submit_button_selector = @logout_button_selector = @logged_out_xpath = logged_out_xpath end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
10 11 12 |
# File 'lib/WebAccount.rb', line 10 def password @password end |
#user_agent_alias=(value) ⇒ Object
Sets the attribute user_agent_alias
11 12 13 |
# File 'lib/WebAccount.rb', line 11 def user_agent_alias=(value) @user_agent_alias = value end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/WebAccount.rb', line 9 def username @username end |
Instance Method Details
#logged_in? ⇒ Boolean
predicate methods
61 62 63 |
# File 'lib/WebAccount.rb', line 61 def logged_in? @logged_in end |
#logged_out? ⇒ Boolean
65 66 67 68 69 |
# File 'lib/WebAccount.rb', line 65 def logged_out? driver_wait.until do driver.element_present?(:xpath, @logged_out_xpath) end end |
#login(username: nil, password: nil) ⇒ Object Also known as: logon
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/WebAccount.rb', line 29 def login(username: nil, password: nil) @logged_in = false username ||= self.username password ||= self.password attempts = 0 driver.attempt do get_login_page enter_username(username) enter_password(password) .click end @logged_in = driver_wait.until do driver.element_present?(@logout_button_selector.keys.first, @logout_button_selector.values.first) end end |
#logout ⇒ Object Also known as: logoff
46 47 48 49 50 51 |
# File 'lib/WebAccount.rb', line 46 def logout .click if logged_out? @logged_in = false end end |
#shutdown ⇒ Object
54 55 56 57 |
# File 'lib/WebAccount.rb', line 54 def shutdown logout if logged_in? driver.quit end |