Class: Awetestlib::Regression::Runner

Inherits:
Awetestlib::Runner show all
Includes:
ActiveSupport::Inflector, Logging, Browser, DragAndDrop, Find, Legacy, PageData, Tables, UserInput, Utilities, Validations, Waits
Defined in:
lib/awetestlib/regression/runner.rb

Overview

Collects all the components needed to run the script and executes it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Legacy

#check_element_is_disabled, #checkbox_is_disabled?, #checkbox_is_enabled?, #checkbox_not_checked?, #checked_by_id?, #clear_checkbox, #clear_checkbox_by_id, #clear_checkbox_by_name, #clear_radio, #click_button_by_class, #click_button_by_id, #click_button_by_index, #click_button_by_name, #click_button_by_text, #click_button_by_title, #click_button_by_value, #click_button_by_xpath_and_id, #click_button_no_wait_by_class, #click_button_no_wait_by_id, #click_button_no_wait_by_name, #click_button_no_wait_by_text, #click_button_no_wait_by_value, #click_file_field_by_id, #click_img_by_alt, #click_img_by_src, #click_img_by_title, #click_img_by_xpath_and_name, #click_img_no_wait_by_alt, #click_js, #click_link_by_class, #click_link_by_href, #click_link_by_id, #click_link_by_index, #click_link_by_name, #click_link_by_name_no_wait, #click_link_by_text, #click_link_by_text_no_wait, #click_link_by_title, #click_link_by_value, #click_link_by_xpath_and_id, #click_link_no_wait_by_href, #click_link_no_wait_by_id, #click_span_by_text, #click_table_row_with_text_by_id, #click_table_row_with_text_by_index, #click_title_no_wait, #double_click_table_row_with_text_by_id, #double_click_table_row_with_text_by_index, #fire_event_on_image_by_src, #fire_event_on_link_by_id, #fire_event_on_link_by_text, #get_div_by_class, #get_div_by_id, #get_div_by_text, #get_form_by_id, #get_frame_by_id, #get_frame_by_index, #get_frame_by_name, #get_select_options_by_id, #get_select_options_by_name, #get_selected_options_by_id, #get_selected_options_by_name, #get_span_by_id, #get_table, #get_table_by_id, #get_table_by_index, #get_table_by_text, #link_disabled?, #link_enabled?, #link_not_exist?, #radio_is_set?, #select_option_by_class_and_option_text, #select_option_by_id_and_index, #select_option_by_id_and_option_text, #select_option_by_id_and_option_value, #select_option_by_name_and_index, #select_option_by_name_and_option_text, #select_option_by_name_and_option_value, #select_option_by_title_and_option_text, #select_option_by_xpath_and_index, #set_checkbox, #set_checkbox_by_class, #set_checkbox_by_id, #set_checkbox_by_name, #set_checkbox_by_title, #set_checkbox_by_value, #set_file_field_by_id, #set_file_field_by_name, #set_radio, #set_radio_by_class, #set_radio_by_id, #set_radio_by_index, #set_radio_by_name, #set_radio_by_name_and_index, #set_radio_by_name_and_text, #set_radio_by_name_and_value, #set_radio_by_title, #set_radio_by_value, #set_radio_by_value_and_index, #set_textfield_by_class, #set_textfield_by_id, #set_textfield_by_name, #set_textfield_by_title, #span_contains_text?, #text_in_span_equals?, #validate_check_by_class, #validate_div_not_visible_by_id, #validate_div_visible_by_id, #validate_image, #validate_link_exist, #validate_list, #validate_no_list, #validate_radio_not_set, #validate_radioset_by_name, #validate_text_in_span_by_id, #validate_textfield_disabled_by_name, #validate_textfield_empty_by_id, #validate_textfield_empty_by_name, #validate_textfield_empty_by_title, #validate_textfield_enabled_by_name, #validate_textfield_not_value_by_id, #validate_textfield_not_value_by_name, #validate_textfield_not_visible_by_name, #validate_textfield_value_by_id, #validate_textfield_value_by_name, #validate_textfield_visible_by_name, #wait_for_exists, #wait_until_by_link_text, #wait_until_by_radio_value

Methods included from Validations

#arrays_match?, #checked?, #date_string_equals?, #disabled?, #does_not_exist?, #element_contains_text?, #enabled?, #exists?, included, #not_checked?, #not_read_only?, #not_set?, #not_visible?, #popup_is_browser?, #radio_with_value_set?, #read_only?, #ready?, #select_list_does_not_include?, #select_list_includes?, #set?, #string_contains?, #string_does_not_contain?, #string_does_not_equal?, #string_equals?, #text_in_element_equals?, #textfield_contains?, #textfield_does_not_equal?, #textfield_empty?, #textfield_equals?, #validate_list_by_id, #validate_list_by_name, #validate_message, #validate_no_text, #validate_select_list, #validate_select_list_contents, #validate_selected_options, #validate_style_greater_than_value, #validate_style_less_than_value, #validate_style_value, #validate_text, #validate_textfield_dollar_value, #validate_url, #verify_class, #visible?, #window_does_not_exist?, #window_exists?

Methods included from DragAndDrop

#adjust_dimensions_by_percent, #drag_and_drop, #drag_and_drop_div, #drag_and_drop_element, #get_browser_coord, #get_element_coordinates, #get_resize_handle_by_class, #get_resize_handle_by_id, #hover, #left_click, #move_element_with_handle, #overlay?, #resize_element_with_handle, #right_click, #screen_center, #screen_lower_right, #screen_offset, #validate_drag_drop, #verify_element_inside, #verify_no_element_overlap, #verify_resize

Methods included from PageData

#capture_page_data, #compare_page_data, #fetch_page_data, #get_element_text, #get_textfield_value, #get_textfield_value_by_id, #get_textfield_value_by_name, #parse_elements

Methods included from Tables

#count_data_rows, #count_rows_with_string, #exercise_sorting, #fetch_array_for_table_column, #fetch_hash_for_table_column, #get_cell_count, #get_cell_text_from_row_with_string, #get_column_index, #get_index_for_column_head, #get_index_for_table_containing_text, #get_index_of_last_row, #get_index_of_last_row_with_text, #get_index_of_row_with_text, #get_index_of_row_with_textfield_value, #get_row_cells_text_as_array, #get_table_containing_text, #get_table_headers, #text_in_table?, #text_in_table_row_with_text?, #verify_column_order, #verify_column_sort, #verify_column_sort_temp_ff

Methods included from Waits

#hold_for_text, #sleep_for, #wait_for, #wait_for_element_to_reappear, #wait_for_exists, #wait_the_hard_way, #wait_until, #wait_until_enabled, #wait_until_exists, #wait_until_ready, #wait_until_ready_quiet, #wait_until_text, #wait_until_visible, #wait_while

Methods included from UserInput

#clear, #clear_textfield, #click, #click_img_by_src_and_index, #click_no_wait, #click_popup_button, #click_table_row_with_text, #double_click_table_row_with_text, #fire_event, #select_option, #select_option_from_list, #set, #set_file_field, #set_radio_two_attributes, #set_text_field, #set_text_field_and_validate

Methods included from Find

#find_all_links_with_exact_href, #find_index_for_element, #find_link_with_exact_href, #get_attribute_value, #get_div, #get_element, #get_element_collection, #get_form, #get_frame, #get_ole, #get_select_list, #get_select_options, #get_selected_options, #get_span

Methods included from Browser

#attach_browser, #attach_browser_by_url, #attach_popup, #attach_popup_by_title, #attach_popup_by_url, #bail_out, #basic_auth, #check_for_and_clear_other_browsers, #check_for_other_browsers, #close_browser, #close_modal, #close_modal_c, #close_modal_ff, #close_modal_ie, #close_modal_s, #close_new_window_popup, #close_panel_by_text, #close_popup, #close_popup_by_button_title, #close_popup_by_text, #close_window_by_title, #find_other_browsers, #find_popup, #go_to_url, #go_to_wd_url, #handle_popup, #is_browser?, #kill_browser, #login, #modal_exists?, #open_browser, #open_chrome, #open_ff, #open_ie, #open_popup_through_link_title, #open_safari, #token_auth, #translate_popup_title, #validate

Methods included from Utilities

#awetestlib?, #build_message, #calc_index, #capture_screen, #close_print, #debug_call_list, #do_taskkill, #dump_all_tables, #dump_array, #dump_ole_get_methods, #dump_ole_help, #dump_ole_methods, #dump_row_cells, #dump_select_list_options, #dump_table_and_rows, #dump_table_rows_and_cells, #file_download, #file_upload, #find_sheet_with_name, #flash, #flash_id, #flash_text, #focus_on_textfield_by_id, #get_call_array, #get_call_list, #get_call_list_new, #get_caller_line, #get_date_names, #get_debug_list, #get_mdyy, #get_os, #get_prefix, #get_save_file_path, #get_test_level, #get_timestamp, #get_trace, #get_variables, #grab_window_list, #method_to_title, #nice_array, #nice_number, #pad_date, #parse_caller, #parse_cookies, #pdf_to_text, #rescue_me, #rescue_me_command, #save_file, #save_file1, #save_file2, #save_file_orig, #sec2hms, #set_script_variables, #setup, #string_count_in_string, #strip_regex_mix, #translate_var_list, #unable_to, #upload_file

Methods included from Logging

#debug_to_log, #debug_to_report, #error_to_log, #failed_to_log, #fatal_to_log, included, #info_to_log, #mark_test_level, #message_to_report, #passed_to_log

Methods inherited from Awetestlib::Runner

#check_script_type

Constructor Details

#initialize(options) ⇒ Runner

def self.runner_class(options)

script_file = options[:script_file]
load script_file # force a load

runner_module = self.module_for script_file
klass_name    = "#{runner_module.to_s}::Runner"

# Define a Runner class in the test script's module inheriting from AwetestLegacy::Runner
runner_module.module_eval do
  eval <<-RUBY
class #{klass_name} < Awetestlib::Runner
  def initialize(options)
    #super(options)
    setup_global_test_vars(options)
  end
end
  RUBY
end

runner = runner_module::Runner.new(options)

if options[:library]
  lib_file = options[:library]
  load lib_file
  lib_module = self.module_for lib_file
  runner.extend(lib_module)
end

# Add in the methods defined in the script's module
runner.extend(runner_module)
runner

end



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/awetestlib/regression/runner.rb', line 167

def initialize(options)

  options.each_pair do |k, v|
    self.send("#{k}=", v)
  end
  script_file = options[:script_file]
  load script_file
  setup_global_test_vars(options)

  # load and extend with library module if it exists
  if options[:library]
    lib_file = options[:library]
    load lib_file # force a fresh load
    lib_module = module_for lib_file
    self.extend(lib_module)
  end

  # load and extend with script
  script_file = options[:script_file]
  load script_file # force a fresh load
  runner_module = module_for script_file
  self.extend(runner_module)

end

Instance Attribute Details

#browserObject

Returns the value of attribute browser.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def browser
  @browser
end

#browser_abbrevObject

Returns the value of attribute browser_abbrev.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def browser_abbrev
  @browser_abbrev
end

#browser_sequenceObject

Returns the value of attribute browser_sequence.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def browser_sequence
  @browser_sequence
end

#capture_load_timesObject

Returns the value of attribute capture_load_times.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def capture_load_times
  @capture_load_times
end

#classic_watirObject

Returns the value of attribute classic_watir.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def classic_watir
  @classic_watir
end

#cycleObject

Returns the value of attribute cycle.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def cycle
  @cycle
end

#debug_on_failObject

Returns the value of attribute debug_on_fail.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def debug_on_fail
  @debug_on_fail
end

#envObject

Returns the value of attribute env.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def env
  @env
end

#environmentObject

Returns the value of attribute environment.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def environment
  @environment
end

#environment_nameObject

Returns the value of attribute environment_name.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def environment_name
  @environment_name
end

#environment_nodenameObject

Returns the value of attribute environment_nodename.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def environment_nodename
  @environment_nodename
end

#environment_urlObject

Returns the value of attribute environment_url.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def environment_url
  @environment_url
end

#libraryObject

Returns the value of attribute library.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def library
  @library
end

#log_classObject

Returns the value of attribute log_class.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def log_class
  @log_class
end

#log_path_subdirObject

Returns the value of attribute log_path_subdir.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def log_path_subdir
  @log_path_subdir
end

#log_propertiesObject

Returns the value of attribute log_properties.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def log_properties
  @log_properties
end

#log_queueObject

Returns the value of attribute log_queue.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def log_queue
  @log_queue
end

#notify_classObject

Returns the value of attribute notify_class.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def notify_class
  @notify_class
end

#notify_idObject

Returns the value of attribute notify_id.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def notify_id
  @notify_id
end

#notify_queueObject

Returns the value of attribute notify_queue.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def notify_queue
  @notify_queue
end

#output_to_logObject

Returns the value of attribute output_to_log.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def output_to_log
  @output_to_log
end

#report_all_test_refsObject

Returns the value of attribute report_all_test_refs.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def report_all_test_refs
  @report_all_test_refs
end

#root_pathObject

Returns the value of attribute root_path.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def root_path
  @root_path
end

#screencap_pathObject

Returns the value of attribute screencap_path.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def screencap_path
  @screencap_path
end

#script_fileObject

Returns the value of attribute script_file.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def script_file
  @script_file
end

#script_pathObject

Returns the value of attribute script_path.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def script_path
  @script_path
end

#script_typeObject

Returns the value of attribute script_type.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def script_type
  @script_type
end

#timeoutObject

Returns the value of attribute timeout.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def timeout
  @timeout
end

#user_tokenObject

Returns the value of attribute user_token.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def user_token
  @user_token
end

#versionObject

Returns the value of attribute version.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def version
  @version
end

#xls_pathObject

Returns the value of attribute xls_path.



53
54
55
# File 'lib/awetestlib/regression/runner.rb', line 53

def xls_path
  @xls_path
end

Instance Method Details

#after_runObject



281
282
283
284
285
286
# File 'lib/awetestlib/regression/runner.rb', line 281

def after_run
  finish_run
  @report_class.finish_report(@html_report_file)
  open_report_file
  @myLog.close if @myLog
end

#before_runObject



266
267
268
269
# File 'lib/awetestlib/regression/runner.rb', line 266

def before_run
  initiate_html_report
  start_run
end

#browser_to_use(browser, browser_version = nil) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/awetestlib/regression/runner.rb', line 192

def browser_to_use(browser, browser_version = nil)
  platform = ''
  platform = 'Windows' if !!((RUBY_PLATFORM =~ /(win|w)(32|64)$/) || (RUBY_PLATFORM =~ /mswin|mingw/))
  platform = 'OSX' if RUBY_PLATFORM =~ /darwin/

  browser_abbrev =
      Awetestlib::BROWSER_ALTERNATES[platform][browser] ?
          Awetestlib::BROWSER_ALTERNATES[platform][browser] : browser
  if not browser_version
    case browser_abbrev
      when 'IE'
        browser_version = 8
      when 'FF'
        browser_version = 11
      when 'C', 'GC'
        browser_version = 10
      when 'S'
        browser_version = 10
    end
  end
  return OpenStruct.new(
        :name => (Awetestlib::BROWSER_MAP[browser_abbrev]),
        :abbrev => browser_abbrev,
        :version => browser_version
  )
end

#initiate_html_reportObject



288
289
290
291
292
293
294
# File 'lib/awetestlib/regression/runner.rb', line 288

def initiate_html_report
  @html_report_name = File.join(FileUtils.pwd, 'awetest_reports', @myName)
  @html_report_dir = File.dirname(@html_report_name)
  FileUtils.mkdir @html_report_dir unless File.directory? @html_report_dir
  @report_class = Awetestlib::HtmlReport.new(@myName)
  @html_report_file = @report_class.create_report(@html_report_name)
end

#module_for(script_file) ⇒ Object



262
263
264
# File 'lib/awetestlib/regression/runner.rb', line 262

def module_for(script_file)
  File.read(script_file).match(/^module\s+(\w+)/)[1].constantize
end

#open_report_fileObject



296
297
298
299
300
301
302
303
304
305
306
# File 'lib/awetestlib/regression/runner.rb', line 296

def open_report_file
  full_report_file = File.expand_path(@html_report_file)
  if USING_WINDOWS
    system("explorer file:///#{full_report_file}")
  elsif USING_OSX
    system("open #{full_report_file}")
  else
    puts "Can find report in #{full_report_file}"
  end

end

#require_gemsObject



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/awetestlib/regression/runner.rb', line 219

def require_gems

  case @targetBrowser.abbrev

    when 'IE'
      if $watir_script
        require 'watir/ie'  #; load_time
        require 'watir'  #; load_time
        require 'watir/process'  #; load_time
        require 'watirloo'  #; load_time
        require 'patches/watir'  #; load_time
        Watir::IE.visible = true
      else
        require 'watir-webdriver'  #; load_time
      end
    when 'FF'
      require 'watir-webdriver'  #; load_time
    when 'S'
      require 'watir-webdriver'  #; load_time

    when 'C', 'GC'
      require 'watir-webdriver'  #; load_time

    # when 'CL'
    #   require 'celerity'  #; load_time
    #   require 'watir-webdriver'  #; load_timerequi

  end

  if USING_WINDOWS
    require 'watir/win32ole'  #; load_time
    @ai = ::WIN32OLE.new('AutoItX3.Control')
  else
    # TODO: Need alternative for Mac?
    @ai = ''
  end

  if @xls_path
    require 'roo'  #; load_time
  end

end

#setup_global_test_vars(options) ⇒ Object

TODO: Encapsulate in some kind of config



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/awetestlib/regression/runner.rb', line 77

def setup_global_test_vars(options)
  @my_failed_count = 0
  @my_passed_count = 0
  @my_error_references         = Hash.new
  @my_error_hits     = Hash.new

  @report_all_refs  = options[:report_all_test_refs]

  if options[:environment]
    @myAppEnv = OpenStruct.new(
        :name     => options[:environment]['name'],
        :url      => options[:environment]['url'],
        :nodename => options[:environment]['nodename']
    )
    @runenv   = options[:environment]['nodename'] || options[:environment]['name']
    @myURL    = options[:environment]['url']
  else
    @runenv = options[:environment_name]
  end

  @targetBrowser  = browser_to_use(options[:browser], options[:version])
  @targetVersion  = @targetBrowser.version
  @browserAbbrev  = @targetBrowser.abbrev
  @myRoot         = options[:root_path] || Dir.pwd  # NOTE: bug fix pmn 05dec2012
  @myName         = File.basename(options[:script_file]).sub(/\.rb$/, '')

  if options[:output_to_log]
    log_name = "#{@myName}_#{Time.now.strftime("%Y%m%d%H%M%S")}.log"
    if options[:log_path_subdir]
      FileUtils.mkdir options[:log_path_subdir] unless File.directory? options[:log_path_subdir]
      log_path = options[:log_path_subdir]
      log_spec = File.join(log_path, log_name)
    else
      log_spec = log_name
    end
    @myLog = init_logger(log_spec, @myName)
  end

  if options[:xls_path]
    @xls_path = options[:xls_path]
  end

  #TODO need to find way to calculate these on the fly
  # window top border 30
  # IE toolbars 86
  @vertical_hack_ie   = 117
  # FF toolbars 114
  @vertical_hack_ff   = 144
  # window left border 4
  @horizontal_hack_ie = 5
  @horizontal_hack_ff = 4
  #
  # @x_tolerance = 12
  # @y_tolerance = 12
  require_gems
end

#startObject



271
272
273
274
275
276
277
278
279
# File 'lib/awetestlib/regression/runner.rb', line 271

def start
  #get_os
  before_run
  run
rescue Exception => e
  failed_to_log(e.to_s)
ensure
  after_run
end