awetestlib 0.1.30-x86-mingw32 → 1.2.4-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +101 -41
  3. data/awetestlib.gemspec +36 -47
  4. data/awetestlib_osx.gemspec +24 -18
  5. data/awetestlib_windows.gemspec +46 -0
  6. data/bin/awetestlib +130 -111
  7. data/bin/awetestlib-driver-setup.rb +0 -2
  8. data/bin/awetestlib-helpers.rb +43 -30
  9. data/lib/awetestlib.rb +196 -20
  10. data/lib/awetestlib/command_line.rb +44 -0
  11. data/lib/awetestlib/html_report.rb +57 -50
  12. data/lib/awetestlib/logging.rb +242 -171
  13. data/lib/awetestlib/regression/awetest_dsl.rb +4240 -0
  14. data/lib/awetestlib/regression/browser.rb +514 -397
  15. data/lib/awetestlib/regression/date_and_time.rb +280 -0
  16. data/lib/awetestlib/regression/drag_and_drop.rb +24 -0
  17. data/lib/awetestlib/regression/find.rb +70 -43
  18. data/lib/awetestlib/regression/legacy.rb +1 -1
  19. data/lib/awetestlib/regression/mobile.rb +293 -0
  20. data/lib/awetestlib/regression/reporting.rb +298 -0
  21. data/lib/awetestlib/regression/runner.rb +156 -200
  22. data/lib/awetestlib/regression/tables.rb +117 -7
  23. data/lib/awetestlib/regression/test_data.rb +354 -0
  24. data/lib/awetestlib/regression/user_input.rb +179 -93
  25. data/lib/awetestlib/regression/utilities.rb +755 -286
  26. data/lib/awetestlib/regression/validations.rb +325 -115
  27. data/lib/awetestlib/regression/waits.rb +60 -133
  28. data/lib/awetestlib/runner.rb +5 -2
  29. data/lib/version.rb +11 -2
  30. data/setup_samples/sample_cucumber/features/step_definitions/predefined_steps.rb +109 -49
  31. data/setup_samples/sample_mobile_app/features/support/env.rb +1 -1
  32. data/test/google_search2.rb +7 -6
  33. data/test/popup_child_0.rb +13 -0
  34. data/test/popup_child_1.rb +33 -0
  35. data/test/watir_no_require.rb +13 -0
  36. data/test/watir_with_require.rb +16 -0
  37. data/test/zoho_exercise.rb +8 -8
  38. metadata +216 -303
  39. data/AwetestLib Instructions.rtf +0 -0
  40. data/awetestlib.windows.gemspec +0 -42
  41. data/lib/patches/README +0 -2
  42. data/lib/patches/firewatir.rb +0 -106
  43. data/lib/patches/watir.rb +0 -175
@@ -1,40 +1,54 @@
1
- require 'awetestlib/regression/browser' #; load_time
2
- require 'awetestlib/regression/find' #; load_time
3
- require 'awetestlib/regression/user_input' #; load_time
4
- require 'awetestlib/regression/waits' #; load_time
5
- require 'awetestlib/regression/tables' #; load_time
6
- require 'awetestlib/regression/page_data' #; load_time
7
- require 'awetestlib/regression/drag_and_drop' #; load_time
8
- require 'awetestlib/regression/utilities' #; load_time
9
- require 'awetestlib/regression/legacy' #; load_time
10
- require 'awetestlib/logging' #; load_time
11
- require 'awetestlib/regression/validations' #; load_time
12
- require 'awetestlib/html_report' #; load_time
13
- #require 'rbconfig' #; load_time
14
- require 'ostruct' #; load_time
15
- require 'active_support' #; load_time
16
- require 'active_support/inflector' #; load_time
17
- #require 'sys/uname' #; load_time
1
+ require 'awetestlib/regression/browser'
2
+ require 'awetestlib/regression/mobile'
3
+ require 'awetestlib/regression/find'
4
+ require 'awetestlib/regression/user_input'
5
+ require 'awetestlib/regression/waits'
6
+ require 'awetestlib/regression/tables'
7
+ require 'awetestlib/regression/page_data'
8
+ require 'awetestlib/regression/drag_and_drop'
9
+ require 'awetestlib/regression/date_and_time'
10
+ require 'awetestlib/regression/test_data'
11
+ require 'awetestlib/regression/utilities'
12
+ require 'awetestlib/regression/reporting'
13
+ require 'awetestlib/regression/legacy'
14
+ require 'awetestlib/logging'
15
+ require 'awetestlib/regression/validations'
16
+ require 'awetestlib/html_report'
17
+ #require 'rbconfig'
18
+ require 'ostruct'
19
+ require 'csv'
20
+ require 'etc'
21
+ require 'yaml'
22
+ require 'active_support'
23
+ require 'active_support/inflector'
24
+ require 'sys/uname'
25
+
26
+ require 'watir-webdriver'
18
27
 
19
28
  module Awetestlib
20
29
  module Regression
21
30
  # Collects all the components needed to run the script and executes it.
22
31
  class Runner < Awetestlib::Runner
23
32
 
24
- # order matters here
25
- # include Sys #; load_time('include Sys')
26
- include ActiveSupport::Inflector #; load_time('include ActiveSupport::Inflector')
27
- include Awetestlib::Logging #; load_time('include Awetestlib::Logging')
28
- include Awetestlib::Regression::Utilities #; load_time('include Awetestlib::Regression::Utilities')
29
- include Awetestlib::Regression::Browser #; load_time('include Awetestlib::Regression::Browser')
30
- include Awetestlib::Regression::Find #; load_time('include Awetestlib::Regression::Find')
31
- include Awetestlib::Regression::UserInput #; load_time('include Awetestlib::Regression::UserInput')
32
- include Awetestlib::Regression::Waits #; load_time('include Awetestlib::Regression::Waits')
33
- include Awetestlib::Regression::Tables #; load_time('include Awetestlib::Regression::Tables')
34
- include Awetestlib::Regression::PageData #; load_time('include Awetestlib::Regression::PageData')
35
- include Awetestlib::Regression::DragAndDrop #; load_time('include Awetestlib::Regression::DragAndDrop')
36
- include Awetestlib::Regression::Validations #; load_time('include Awetestlib::Regression::Validations')
37
- include Awetestlib::Regression::Legacy #; load_time('include Awetestlib::Regression::Legacy')
33
+ # order matters here
34
+ # include Sys::Uname
35
+ include ActiveSupport::Inflector #; load_time('include ActiveSupport::Inflector')
36
+ include Awetestlib::Logging #; load_time('include Awetestlib::Logging')
37
+ include Awetestlib::Regression::Utilities #; load_time('include Awetestlib::Regression::Utilities')
38
+ include Awetestlib::Regression::Reporting
39
+ include Awetestlib::Regression::DateAndTime
40
+ include Awetestlib::Regression::TestData
41
+ include Awetestlib::Regression::Mobile
42
+ include Awetestlib::Regression::Browser #; load_time('include Awetestlib::Regression::Browser')
43
+ include Awetestlib::Regression::Find #; load_time('include Awetestlib::Regression::Find')
44
+ include Awetestlib::Regression::UserInput #; load_time('include Awetestlib::Regression::UserInput')
45
+ include Awetestlib::Regression::Waits #; load_time('include Awetestlib::Regression::Waits')
46
+ include Awetestlib::Regression::Tables #; load_time('include Awetestlib::Regression::Tables')
47
+ include Awetestlib::Regression::PageData #; load_time('include Awetestlib::Regression::PageData')
48
+ include Awetestlib::Regression::DragAndDrop #; load_time('include Awetestlib::Regression::DragAndDrop')
49
+ include Awetestlib::Regression::Validations #; load_time('include Awetestlib::Regression::Validations')
50
+ include Awetestlib::Regression::Legacy #; load_time('include Awetestlib::Regression::Legacy')
51
+ # load_time('includes')
38
52
 
39
53
  ::DEBUG = 0
40
54
  ::INFO = 1
@@ -43,44 +57,29 @@ module Awetestlib
43
57
  ::FATAL = 4
44
58
  ::UNKNOWN = 5
45
59
 
46
- ::TOP_LEVEL = 7
47
- ::SECOND_LEVEL = ::TOP_LEVEL - 1
60
+ # ::TOP_LEVEL = 7
61
+ # ::SECOND_LEVEL = ::TOP_LEVEL - 1
48
62
 
49
- ::WAIT = 20
50
- ::PASS = '-PASS'
51
- ::FAIL = '-FAIL'
63
+ ::WAIT = 20
64
+ ::PASS = '-PASS'
65
+ ::FAIL = '-FAIL'
52
66
 
53
67
  attr_accessor :browser, :browser_abbrev, :version, :env,
54
- :library, :script_type, :script_file,
55
- :log_properties, :log_queue, :log_class,
56
- :notify_queue, :notify_class, :notify_id,
68
+ :library, :script_type, :script_file, :script_name,
57
69
  :screencap_path, :xls_path, :script_path, :user_token, :root_path,
58
- :debug_on_fail,
70
+ :debug_dsl, :global_debug,
59
71
  :environment, :environment_name, :environment_url, :environment_nodename,
60
- :cycle, :browser_sequence,
61
72
  :output_to_log, :log_path_subdir, :report_all_test_refs,
62
- :timeout, :classic_watir, :capture_load_times
63
-
64
- #def self.build(options)
65
- # #build_class = "Awetestlib::#{script_module_for options[:script_type]}::Runner".constantize
66
- # build_class = "Awetestlib::Runner".constantize
67
- # #options = options.merge(:script_file => options[:script_file])
68
- # #if build_class.respond_to?(:runner_class)
69
- # # build_class.runner_class(options)
70
- # #else
71
- # build_class.new(options)
72
- # #end
73
- #end
73
+ :timeout, :classic_watir, :capture_load_times, :platform, :pry,
74
+ :emulator, :device_type, :device_id, :sdk, :options
74
75
 
75
76
  # TODO: Encapsulate in some kind of config
76
77
  ###################################
77
78
  def setup_global_test_vars(options)
78
- @my_failed_count = 0
79
- @my_passed_count = 0
80
- @my_error_references = Hash.new
81
- @my_error_hits = Hash.new
82
-
83
- @report_all_refs = options[:report_all_test_refs]
79
+ @my_failed_count = 0
80
+ @my_passed_count = 0
81
+ @my_error_references = Hash.new
82
+ @my_error_hits = Hash.new
84
83
 
85
84
  if options[:environment]
86
85
  @myAppEnv = OpenStruct.new(
@@ -94,11 +93,11 @@ module Awetestlib
94
93
  @runenv = options[:environment_name]
95
94
  end
96
95
 
97
- @targetBrowser = browser_to_use(options[:browser], options[:version])
98
- @targetVersion = @targetBrowser.version
99
- @browserAbbrev = @targetBrowser.abbrev
100
- @myRoot = options[:root_path] || Dir.pwd # NOTE: bug fix pmn 05dec2012
101
- @myName = File.basename(options[:script_file]).sub(/\.rb$/, '')
96
+ @targetBrowser, @actualBrowser = browser_to_use(options[:browser], options[:version])
97
+ @targetVersion = @targetBrowser.version
98
+ @browserAbbrev = @targetBrowser.abbrev
99
+ @myRoot = options[:root_path] || Dir.pwd # NOTE: bug fix pmn 05dec2012
100
+ self.script_name = File.basename(options[:script_file]).sub(/\.rb$/, '')
102
101
 
103
102
  if options[:output_to_log]
104
103
  log_name = "#{@myName}_#{Time.now.strftime("%Y%m%d%H%M%S")}.log"
@@ -109,154 +108,111 @@ module Awetestlib
109
108
  else
110
109
  log_spec = log_name
111
110
  end
112
- @myLog = init_logger(log_spec, @myName)
111
+ @logger = init_logger(log_spec, @myName)
113
112
  end
114
113
 
115
114
  if options[:xls_path]
116
115
  @xls_path = options[:xls_path]
117
116
  end
118
117
 
119
- #TODO need to find way to calculate these on the fly
120
- # window top border 30
121
- # IE toolbars 86
122
- @vertical_hack_ie = 117
123
- # FF toolbars 114
124
- @vertical_hack_ff = 144
125
- # window left border 4
126
- @horizontal_hack_ie = 5
127
- @horizontal_hack_ff = 4
128
- #
129
- # @x_tolerance = 12
130
- # @y_tolerance = 12
131
- require_gems
132
118
  end
133
119
 
134
- #def self.runner_class(options)
135
- # script_file = options[:script_file]
136
- # load script_file # force a load
137
- #
138
- # runner_module = self.module_for script_file
139
- # klass_name = "#{runner_module.to_s}::Runner"
140
- #
141
- # # Define a Runner class in the test script's module inheriting from AwetestLegacy::Runner
142
- # runner_module.module_eval do
143
- # eval <<-RUBY
144
- # class #{klass_name} < Awetestlib::Runner
145
- # def initialize(options)
146
- # #super(options)
147
- # setup_global_test_vars(options)
148
- # end
149
- # end
150
- # RUBY
151
- # end
152
- #
153
- # runner = runner_module::Runner.new(options)
154
- #
155
- # if options[:library]
156
- # lib_file = options[:library]
157
- # load lib_file
158
- # lib_module = self.module_for lib_file
159
- # runner.extend(lib_module)
160
- # end
161
- #
162
- # # Add in the methods defined in the script's module
163
- # runner.extend(runner_module)
164
- # runner
165
- #end
166
-
167
120
  def initialize(options)
168
121
 
122
+ self.options = options
123
+
124
+ @myName = File.basename(options[:script_file]).sub(/\.rb$/, '')
125
+ self.script_name = File.basename(options[:script_file]).sub(/\.rb$/, '')
126
+
127
+ if options[:debug_dsl]
128
+ $debug = true
129
+ end
130
+
131
+ log_message(DEBUG, with_caller("#{__LINE__}\n#{options.to_yaml}")) if $debug
132
+
169
133
  options.each_pair do |k, v|
170
134
  self.send("#{k}=", v)
171
135
  end
172
- script_file = options[:script_file]
173
- load script_file
136
+
137
+ if options[:pry]
138
+ require 'pry'
139
+ end
140
+
141
+ $mobile, $emulator, $simulator, $platform = mobile_browser?(options)
142
+
143
+ # load script file
144
+ # script_file = options[:script_file]
145
+ load options[:script_file] # ; load_time('Load script file', Time.now)
146
+
174
147
  setup_global_test_vars(options)
148
+ # require_gems
149
+
150
+ if USING_WINDOWS
151
+ require 'win32ole'
152
+ @ai = ::WIN32OLE.new('AutoItX3.Control')
153
+ else
154
+ # TODO: Need alternative for Mac?
155
+ @ai = ''
156
+ end
157
+
158
+ if @xls_path
159
+ require 'roo'
160
+ end
175
161
 
176
162
  # load and extend with library module if it exists
177
163
  if options[:library]
178
164
  lib_file = options[:library]
179
- load lib_file # force a fresh load
165
+ load lib_file # ; load_time('Load library file', Time.now) # force a fresh load
180
166
  lib_module = module_for lib_file
181
167
  self.extend(lib_module)
182
168
  end
183
169
 
184
- # load and extend with script
170
+ # load and extend with script to allow overrides in script
185
171
  script_file = options[:script_file]
186
- load script_file # force a fresh load
187
- runner_module = module_for script_file
188
- self.extend(runner_module)
189
-
172
+ load script_file # ; load_time('Reload script file', Time.now) # force a fresh load
173
+ script_module = module_for script_file
174
+ self.extend(script_module)
190
175
  end
191
176
 
192
- def browser_to_use(browser, browser_version = nil)
193
- platform = ''
194
- platform = 'Windows' if !!((RUBY_PLATFORM =~ /(win|w)(32|64)$/) || (RUBY_PLATFORM =~ /mswin|mingw/))
195
- platform = 'OSX' if RUBY_PLATFORM =~ /darwin/
196
-
197
- browser_abbrev =
198
- Awetestlib::BROWSER_ALTERNATES[platform][browser] ?
199
- Awetestlib::BROWSER_ALTERNATES[platform][browser] : browser
200
- if not browser_version
201
- case browser_abbrev
202
- when 'IE'
203
- browser_version = 8
204
- when 'FF'
205
- browser_version = 11
206
- when 'C', 'GC'
207
- browser_version = 10
208
- when 'S'
209
- browser_version = 10
210
- end
211
- end
212
- return OpenStruct.new(
213
- :name => (Awetestlib::BROWSER_MAP[browser_abbrev]),
214
- :abbrev => browser_abbrev,
215
- :version => browser_version
216
- )
217
- end
218
-
219
- def require_gems
220
-
221
- case @targetBrowser.abbrev
222
-
223
- when 'IE'
224
- if $watir_script
225
- require 'watir/ie' #; load_time
226
- require 'watir' #; load_time
227
- require 'watir/process' #; load_time
228
- require 'watirloo' #; load_time
229
- require 'patches/watir' #; load_time
230
- Watir::IE.visible = true
231
- else
232
- require 'watir-webdriver' #; load_time
233
- end
234
- when 'FF'
235
- require 'watir-webdriver' #; load_time
236
- when 'S'
237
- require 'watir-webdriver' #; load_time
238
-
239
- when 'C', 'GC'
240
- require 'watir-webdriver' #; load_time
241
-
242
- # when 'CL'
243
- # require 'celerity' #; load_time
244
- # require 'watir-webdriver' #; load_timerequi
177
+ def mobile_browser?(options)
178
+ debug_to_log(with_caller("#{__LINE__}\n#{self.options.to_yaml}"))
179
+ mobile = false
180
+ android_emulator = false
181
+ ios_simulator = false
245
182
 
183
+ if options[:emulator] or options[:sdk] or options[:device_id] or
184
+ options[:device_type] or options[:environment_nodename] =~ /W:|E:|T:|K:|I:/
185
+ require 'appium_lib'
186
+ mobile = true
246
187
  end
247
188
 
248
- if USING_WINDOWS
249
- require 'watir/win32ole' #; load_time
250
- @ai = ::WIN32OLE.new('AutoItX3.Control')
251
- else
252
- # TODO: Need alternative for Mac?
253
- @ai = ''
189
+ if options[:emulator]
190
+ android_emulator = true
191
+ options[:platform] ||= :android
192
+ elsif options[:sdk]
193
+ ios_simulator = true
194
+ options[:platform] ||= :ios
254
195
  end
255
196
 
256
- if @xls_path
257
- require 'roo' #; load_time
258
- end
197
+ [mobile, android_emulator, ios_simulator, options[:platform]]
198
+ end
199
+
200
+ def browser_to_use(target_abbrev, target_version = nil)
201
+
202
+ target = OpenStruct.new(
203
+ :name => (Awetestlib::BROWSER_MAP[target_abbrev]),
204
+ :abbrev => target_abbrev,
205
+ :version => target_version
206
+ )
207
+
208
+ actual = OpenStruct.new(
209
+ :name => (Awetestlib::BROWSER_MAP[target_abbrev]),
210
+ :abbrev => target_abbrev,
211
+ :version => '',
212
+ :driver => ''
213
+ )
259
214
 
215
+ [target, actual]
260
216
  end
261
217
 
262
218
  def module_for(script_file)
@@ -264,43 +220,43 @@ module Awetestlib
264
220
  end
265
221
 
266
222
  def before_run
267
- initiate_html_report
268
- start_run
223
+ get_os
224
+ get_awetestlib_metadata
225
+ initiate_html_report($begin_time)
226
+ load_time('Total load time', $begin_time)
227
+ log_begin_run($begin_time)
269
228
  end
270
229
 
271
230
  def start
272
- #get_os
273
231
  before_run
274
232
  run
275
233
  rescue Exception => e
276
- failed_to_log(e.to_s)
234
+ failed_to_log(e.to_s, nil, e)
277
235
  ensure
278
236
  after_run
279
237
  end
280
238
 
281
239
  def after_run
282
- finish_run
283
- @report_class.finish_report(@html_report_file)
284
- open_report_file
285
- @myLog.close if @myLog
240
+ log_finish_run
241
+ full_html_path = @report_class.finish_report
242
+ open_report_file(full_html_path) unless Dir.pwd.include?("shamisen/tmp")
243
+ @logger.close if @logger
286
244
  end
287
245
 
288
- def initiate_html_report
289
- @html_report_name = File.join(FileUtils.pwd, 'awetest_reports', @myName)
290
- @html_report_dir = File.dirname(@html_report_name)
291
- FileUtils.mkdir @html_report_dir unless File.directory? @html_report_dir
292
- @report_class = Awetestlib::HtmlReport.new(@myName)
293
- @html_report_file = @report_class.create_report(@html_report_name)
246
+ def initiate_html_report(ts)
247
+ html_report_dir = File.join(FileUtils.pwd, 'awetest_report')
248
+ FileUtils.mkdir html_report_dir unless File.directory? html_report_dir
249
+ @report_class = Awetestlib::HtmlReport.new(@myName, html_report_dir, ts)
250
+ @report_class.create_report(@myName)
294
251
  end
295
252
 
296
- def open_report_file
297
- full_report_file = File.expand_path(@html_report_file)
253
+ def open_report_file(full_html_path)
298
254
  if USING_WINDOWS
299
- system("explorer file:///#{full_report_file}")
255
+ system("start file:///#{full_html_path}")
300
256
  elsif USING_OSX
301
- system("open #{full_report_file}")
257
+ system("open #{full_html_path}")
302
258
  else
303
- puts "Can find report in #{full_report_file}"
259
+ log_message(DEBUG, "Report can be found in #{full_html_path}")
304
260
  end
305
261
 
306
262
  end
@@ -5,6 +5,75 @@ module Awetestlib
5
5
  module Tables
6
6
 
7
7
 
8
+ def dump_all_tables(browser, to_report = false)
9
+ tables = browser.tables
10
+ msg = ''
11
+ tbl_cnt = 0
12
+ tables.each do |tbl|
13
+ tbl_cnt += 1
14
+ row_cnt = 0
15
+ msg << "\n=================\ntable: #{tbl_cnt}\n=================\n#{tbl}\ntext:\n#{tbl.text}"
16
+ tbl.rows.each do |row|
17
+ row_cnt += 1
18
+ cell_cnt = 0
19
+ msg << "\n=================\ntable: #{tbl_cnt} row: #{row_cnt}\n#{row.inspect}\n#{row}\ntext:'#{row.text}'"
20
+ row.each do |cell|
21
+ cell_cnt += 1
22
+ msg << " \ncell: #{cell_cnt}\n#{cell.inspect}\n#{row}\ntext: '#{cell.text}'"
23
+ end
24
+ end
25
+ end
26
+ if to_report
27
+ debug_to_report(msg)
28
+ else
29
+ debug_to_log(msg)
30
+ end
31
+ end
32
+
33
+ def dump_table_and_rows(table, to_report = false)
34
+ msg = "\n=================\ntable\n=================\nn#{table}\n#{table.to_yaml}\nrows:"
35
+ cnt = 0
36
+ table.rows.each do |r|
37
+ cnt += 1
38
+ msg << "\n#{cnt}: #{r.text}"
39
+ end
40
+ msg << "\n=================\n================="
41
+ if to_report
42
+ debug_to_report(msg)
43
+ else
44
+ debug_to_log(msg)
45
+ end
46
+ end
47
+
48
+ def dump_table_rows_and_cells(tbl)
49
+ msg = ''
50
+ row_cnt = 0
51
+ msg << "\n=================\ntable: #{tbl.inspect}\n=================\n#{tbl}\ntext:\n#{tbl.text}"
52
+ tbl.rows.each do |row|
53
+ row_cnt += 1
54
+ cell_cnt = 0
55
+ msg << "\n=================\nrow: #{row_cnt}\n#{row.inspect}\n#{row}\ntext:'#{row.text}'"
56
+ row.each do |cell|
57
+ cell_cnt += 1
58
+ msg << "\ncell: #{cell_cnt}\n#{cell.inspect}\n#{row}\ntext: '#{cell.text}'"
59
+ end
60
+ end
61
+ debug_to_log(msg)
62
+ end
63
+
64
+ alias dump_table_rows dump_table_rows_and_cells
65
+
66
+ def dump_row_cells(row)
67
+ msg = ''
68
+ cell_cnt = 0
69
+ msg << "\n=================\nrow: #{row.inspect}\n#{row}\ntext:'#{row.text}'"
70
+ row.each do |cell|
71
+ cell_cnt += 1
72
+ msg << "\ncell: #{cell_cnt}\n#{cell.inspect}\n#{row}\ntext: '#{cell.text}'"
73
+ end
74
+ debug_to_log(msg)
75
+ end
76
+
8
77
  def get_index_for_column_head(panel, table_index, strg, desc = '')
9
78
  table = panel.tables[table_index]
10
79
  get_column_index(table, strg, desc, true)
@@ -43,7 +112,48 @@ module Awetestlib
43
112
  failed_to_log("Unable to #{msg} '#{$!}'")
44
113
  end
45
114
 
46
- # Return the index of the last row of the specified table.
115
+ def get_parent_row(container, element, how, what, limit = 5)
116
+ msg = "#{__method__}: #{element.to_s.upcase} :#{how}='#{what}'"
117
+ target = nil
118
+ parent = nil
119
+ case element
120
+ when :link
121
+ target = container.link(how, what)
122
+ when :select_list
123
+ target = container.select_list(how, what)
124
+ when :text_field
125
+ target = container.text_field(how, what)
126
+ when :checkbox
127
+ target = container.checkbox(how, what)
128
+ when :radio
129
+ target = container.radio(how, what)
130
+ else
131
+ fail "#{element.to_s.upcase} not supported."
132
+ end
133
+ if target
134
+ count = 0
135
+ parent = target.parent
136
+ until parent.is_a?(Watir::TableRow) do
137
+ parent = parent.parent
138
+ count += 1
139
+ if count > limit
140
+ failed_to_log("Parent row not within #{limit} ancestors.")
141
+ end
142
+ end
143
+ else
144
+ failed_to_log(msg)
145
+ end
146
+ if parent.is_a?(Watir::TableRow)
147
+ passed_to_log(msg)
148
+ parent
149
+ else
150
+ failed_to_log(msg)
151
+ end
152
+ rescue
153
+ failed_to_log(unable_to)
154
+ end
155
+
156
+ # Return the index of the last row of the specified table.
47
157
  # @param [Watir::Table] table A reference to the table in question.
48
158
  # @param [Fixnum] pad The number of zeroes to prefix the index to allow correct sorting.
49
159
  # @param [Fixnum] every A number indicating which rows in the table actually carry data if
@@ -116,7 +226,7 @@ module Awetestlib
116
226
  # after the row indicated by this argument. When omitted, the first hit is accepted.
117
227
  # @return [Fixnum] the index of the row containing *strg*
118
228
  def get_index_of_row_with_text(table, strg, column_index = nil, fail_if_found = false, after_index = nil)
119
- debug_to_log("#{__method__}: #{get_callers(5)}")
229
+ debug_to_log(with_caller("#{get_callers(5)}")) if $debug
120
230
  if fail_if_found
121
231
  msg = 'No '
122
232
  else
@@ -298,14 +408,14 @@ module Awetestlib
298
408
  # @param [Fixnum] header_index The index of the row containing the header names.
299
409
  # @return [Hash] Two level hash of hashes. Internal hashes are 'name' which allows look-up of a column index
300
410
  # by the header name, and 'index' which allows look-up of the name by the column index.
301
- def get_table_headers(table, header_index = 1)
411
+ def get_table_headers(table, header_index = 0)
302
412
  headers = Hash.new
303
413
  headers['index'] = Hash.new
304
414
  headers['name'] = Hash.new
305
- count = 1
306
- table[header_index].each do |cell|
415
+ count = 0
416
+ table[header_index].cells.each do |cell|
307
417
  if cell.text.length > 0
308
- name = cell.text.gsub(/\s+/, ' ')
418
+ name = cell.text.strip.gsub(/\s+/, ' ')
309
419
  headers['index'][count] = name
310
420
  headers['name'][name] = count
311
421
  end
@@ -314,7 +424,7 @@ module Awetestlib
314
424
  #debug_to_log("#{__method__}: headers:\n#{headers.to_yaml}")
315
425
  headers
316
426
  rescue
317
- failed_to_log("Unable to get content headers. '#{$!}'")
427
+ failed_to_log(unable_to)
318
428
  end
319
429
 
320
430
  # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.