Class: WebAccount

Inherits:
Object
  • Object
show all
Defined in:
lib/WebAccount.rb,
lib/WebAccount/VERSION.rb

Constant Summary collapse

VERSION =
'0.3.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

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_username_field_selector, @login_page_password_field_selector = , 
  @login_page_submit_button_selector = 
  @logout_button_selector = logout_button_selector
  @logged_out_xpath = logged_out_xpath
end

Instance Attribute Details

#passwordObject

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

Parameters:

  • value

    the value to set the attribute user_agent_alias to.



11
12
13
# File 'lib/WebAccount.rb', line 11

def user_agent_alias=(value)
  @user_agent_alias = value
end

#usernameObject

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

Returns:

  • (Boolean)


61
62
63
# File 'lib/WebAccount.rb', line 61

def logged_in?
  @logged_in
end

#logged_out?Boolean

Returns:

  • (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 (username: nil, password: nil)
  @logged_in = false
  username ||= self.username
  password ||= self.password
  attempts = 0
  driver.attempt do
    
    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

#logoutObject Also known as: logoff



46
47
48
49
50
51
# File 'lib/WebAccount.rb', line 46

def logout
  logout_button.click
  if logged_out?
    @logged_in = false
  end
end

#shutdownObject



54
55
56
57
# File 'lib/WebAccount.rb', line 54

def shutdown
  logout if logged_in?
  driver.quit
end