Class: Avmtrf1::CheckPoint::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/avmtrf1/check_point/session.rb,
lib/avmtrf1/check_point/session/login.rb

Defined Under Namespace

Classes: Login

Constant Summary collapse

ROOT_URL =
'https://cp.trf1.jus.br'
LOGIN_URL =
"#{ROOT_URL}/connect/PortalMain"
LOGGED_TITLE_TEXT =
'Network Access Granted'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, driver_options = {}) ⇒ Session

Returns a new instance of Session.



29
30
31
32
33
34
35
# File 'lib/avmtrf1/check_point/session.rb', line 29

def initialize(username, password, driver_options = {})
  @username = username
  @password = password
  @session = ::Aranha::Selenium::Session.new(
    driver_options.merge(accept_insecure_certs: true)
  )
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



27
28
29
# File 'lib/avmtrf1/check_point/session.rb', line 27

def password
  @password
end

#sessionObject (readonly)

Returns the value of attribute session.



27
28
29
# File 'lib/avmtrf1/check_point/session.rb', line 27

def session
  @session
end

#usernameObject (readonly)

Returns the value of attribute username.



27
28
29
# File 'lib/avmtrf1/check_point/session.rb', line 27

def username
  @username
end

Class Method Details

.by_ad_user(ad_user, driver_options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/avmtrf1/check_point/session.rb', line 14

def by_ad_user(ad_user, driver_options = {})
  new(
    ad_user.username_with_domain,
    ad_user.password,
    driver_options
  )
end

.by_default_ad_user(driver_options = {}) ⇒ Object



22
23
24
# File 'lib/avmtrf1/check_point/session.rb', line 22

def by_default_ad_user(driver_options = {})
  by_ad_user(::Avmtrf1.ad_user, driver_options)
end

Instance Method Details

#logged?Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/avmtrf1/check_point/session.rb', line 37

def logged?
  session.navigate.to LOGIN_URL
  title_text == LOGGED_TITLE_TEXT
end

#loginObject



42
43
44
# File 'lib/avmtrf1/check_point/session.rb', line 42

def 
  ::Avmtrf1::CheckPoint::Session::Login.new(self)
end

#title_textObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/avmtrf1/check_point/session.rb', line 46

def title_text
  result_text = nil
  session.wait.until do
    element = session.find_element(id: 'usercheck_title_div')
    return false unless element

    result_text = element.text.strip
    result_text.present?
  end
  result_text
end