Class: Taf::TestSteps::Handlers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/taf/test_steps/handlers/base.rb

Overview

All Login functions function.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step_attributes) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
# File 'lib/taf/test_steps/handlers/base.rb', line 9

def initialize(step_attributes)
  @value =  step_attributes[:testvalue]
  @value2 = step_attributes[:testvalue2]
  @locate = step_attributes[:locate]
  @locate2 = step_attributes[:locate2]
end

Class Method Details

.perform(*args) ⇒ Object



20
21
22
# File 'lib/taf/test_steps/handlers/base.rb', line 20

def self.perform(*args)
  new(*args).perform
end

.register(name) ⇒ Object



16
17
18
# File 'lib/taf/test_steps/handlers/base.rb', line 16

def self.register(name)
  TestSteps.handlers[name.to_s] = self
end

Instance Method Details

#login_check(b_title_sucess, user) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/taf/test_steps/handlers/base.rb', line 37

def (b_title_sucess, user)
  if Taf::Browser.b.title.eql?(b_title_sucess)
    Taf::MyLog.log.info("User: #{user} has logged in successful.")
    true
  else
    Taf::MyLog.log.warn("User: #{user} has failed to log in.")
    false
  end
end

#login_process(b_title, user_elm, pass_elm, user, pass) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/taf/test_steps/handlers/base.rb', line 24

def (b_title, user_elm, pass_elm, user, pass)
  if Taf::Browser.b.title.eql?(b_title)
    Taf::Browser.b.text_field(id: user_elm).wait_until(&:exists?)
                .set user
    Taf::Browser.b.text_field(id: pass_elm).set pass
    button = 'Sign in' || 'Log in'
    Taf::Browser.b.button(value: button).wait_until(&:exists?).click
    sleep 1
  else
    Taf::MyLog.log.warn("User: #{user} has failed to log in.")
  end
end

#mem_word_check(user, b_title_sucess) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/taf/test_steps/handlers/base.rb', line 47

def mem_word_check(user, b_title_sucess)
  if Taf::Browser.b.title.eql?('Memorable word Portal')
    portal_mem_word(user, b_title_sucess)
  elsif Taf::Browser.b.title.eql?(b_title_sucess)
    Taf::MyLog.log.info("User: #{user} has logged in successful.")
    true
  else
    Taf::MyLog.log.warn("User: #{user} has failed to log in.")
    false
  end
end

#portal_mem_word(user, b_title_sucess) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/taf/test_steps/handlers/base.rb', line 59

def portal_mem_word(user, b_title_sucess)
  password = ENV['PORTAL_MEM']
  nums = (1..256).to_a
  found_mem_nums = nums.each_with_object([]) do |num_val, mem_word|
    elm_id = "user_memorable_parts_#{num_val}"
    mem_word.push(num_val) if Taf::Browser.b.select(id: elm_id).exist?
  end.compact

  array_password = password.split('')
  array_password.map!(&:upcase)

  found_mem_nums.each do |mem_num|
    char = array_password[(mem_num - 1)]
    elm_id = "user_memorable_parts_#{mem_num}"
    Taf::Browser.b.select_list(id: elm_id).option(value: char.to_s)
                .select
  end

  Taf::Browser.b.button(value: 'Sign in').wait_until(&:exists?).click
  if Taf::Browser.b.title.eql?(b_title_sucess)
    Taf::MyLog.log.info("User: #{user} has logged in successful.")
    return true
  else
    Taf::MyLog.log.warn("User: #{user} has failed to log in.")
    return false
  end
end