Class: WebAccount

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

Overview

WebAccount/VERSION.rb WebAccount::VERSION

Constant Summary collapse

VERSION =
'0.4.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username: nil, password: nil, browser: nil, driver_options: 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.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/webaccount.rb', line 12

def initialize(
  username: nil, password: nil,
  browser: nil, driver_options: 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
  @browser, @driver_options = browser, driver_options
  @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

#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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/webaccount.rb', line 30

def (username: nil, password: nil)
  @logged_in = false
  username ||= self.username
  password ||= self.password
  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