Class: Bucky::TestEquipment::UserOperation::UserOperationHelper

Inherits:
Object
  • Object
show all
Includes:
SeleniumHandler::WaitHandler
Defined in:
lib/bucky/test_equipment/user_operation/user_operation_helper.rb

Instance Method Summary collapse

Methods included from SeleniumHandler::WaitHandler

wait_until_helper

Constructor Details

#initialize(args) ⇒ UserOperationHelper

Returns a new instance of UserOperationHelper.



11
12
13
14
15
16
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 11

def initialize(args)
  @app = args[:app]
  @device = args[:device]
  @driver = args[:driver]
  @pages  = args[:pages]
end

Instance Method Details

#accept_alert(_) ⇒ Object

Alert accept



104
105
106
107
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 104

def accept_alert(_)
  alert = wait_until_helper(5, 0.1, Selenium::WebDriver::Error::NoAlertPresentError) { @driver.switch_to.alert }
  alert.accept
end

#back(_) ⇒ Object



24
25
26
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 24

def back(_)
  @driver.navigate.back
end

#choose(args) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 86

def choose(args)
  option = wait_until_helper(5, 0.1, Selenium::WebDriver::Error::StaleElementReferenceError) { Selenium::WebDriver::Support::Select.new(@pages.get_part(args)) }
  if args.key?(:text)
    type = :text
    selected = args[type].to_s
  elsif args.key?(:value)
    type = :value
    selected = args[type].to_s
  elsif args.key?(:index)
    type = :index
    selected = args[type].to_i
  else
    raise StandardError, "Included invalid key #{args.keys}"
  end
  option.select_by(type, selected)
end

#clear(args) ⇒ Object

Clear textbox



34
35
36
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 34

def clear(args)
  @pages.get_part(args).clear
end

#click(args) ⇒ Object



38
39
40
41
42
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 38

def click(args)
  elem = @pages.get_part(args)
  # when click successfully, return of click is nil.
  wait_until_helper(5, 0.1, Selenium::WebDriver::Error::WebDriverError) { elem.click.nil? }
end

#close(_) ⇒ Object

Close window



75
76
77
78
79
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 75

def close(_)
  window_index = @driver.window_handles.index(@driver.window_handle)
  @driver.close
  @driver.switch_to.window(@driver.window_handles[window_index-1])
end

#go(args) ⇒ Object

Open url

Parameters:



20
21
22
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 20

def go(args)
  @driver.navigate.to args[:url]
end

#input(args) ⇒ Object



28
29
30
31
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 28

def input(args)
  # when input successfully, return of click is nil.
  wait_until_helper(5, 0.1, Selenium::WebDriver::Error::StaleElementReferenceError) { @pages.get_part(args).send_keys(args[:word]).nil? }
end

#refresh(_) ⇒ Object



44
45
46
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 44

def refresh(_)
  @driver.navigate.refresh
end

#stop(_) ⇒ Object



81
82
83
84
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 81

def stop(_)
  puts 'stop. press enter to continue'
  gets
end

#switch_to_newest_window(_) ⇒ Object



61
62
63
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 61

def switch_to_newest_window(_)
  @driver.switch_to.window(@driver.window_handles.last)
end

#switch_to_next_window(_) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 48

def switch_to_next_window(_)
  window_index = @driver.window_handles.index(@driver.window_handle)
  windows_number = @driver.window_handles.size
  unless window_index+1 == windows_number
    @driver.switch_to.window(@driver.window_handles[window_index+1])
  end
end

#switch_to_oldest_window(_) ⇒ Object



65
66
67
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 65

def switch_to_oldest_window(_)
  @driver.switch_to.window(@driver.window_handles.first)
end

#switch_to_previous_window(_) ⇒ Object



56
57
58
59
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 56

def switch_to_previous_window(_)
  window_index = @driver.window_handles.index(@driver.window_handle)
  @driver.switch_to.window(@driver.window_handles[window_index-1])
end

#switch_to_the_window(args) ⇒ Object



69
70
71
72
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 69

def switch_to_the_window(args)
  # when the window successfully switched, return of switch_to.window is nil.
  wait_until_helper(5, 0.1, Selenium::WebDriver::Error::NoSuchWindowError) { @driver.switch_to.window(args[:window_name]).nil? }
end

#wait(args) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/bucky/test_equipment/user_operation/user_operation_helper.rb', line 109

def wait(args)
  # Indent
  print ' ' * 6
  args[:sec].times do |count|
    print "#{count + 1} "
    sleep 1
  end
  puts ''
end