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
@@ -0,0 +1,354 @@
1
+ module Awetestlib
2
+
3
+ module Regression
4
+
5
+ module TestData
6
+
7
+ def load_variables(file, key_type = :role, enabled_only = true, dbg = true, scripts = nil)
8
+ mark_test_level(build_message(file, "key:'#{key_type}'"))
9
+
10
+ # ok = true
11
+
12
+ debug_to_log("#{__method__}: file = #{file}")
13
+ debug_to_log("#{__method__}: key = #{key_type}")
14
+
15
+ workbook = file =~ /\.xlsx$/ ? Roo::Excelx.new(file) : Roo::Excel.new(file)
16
+
17
+ if @myName =~ /appium/i
18
+ ok = script_found_in_data = script_found_in_login = true
19
+ else
20
+ script_found_in_data = load_data_variables(workbook, dbg)
21
+ ok, script_found_in_login = load_login_variables(workbook, enabled_only, file, key_type, scripts, dbg)
22
+ end
23
+
24
+ unless @env_name =~ /^gen/
25
+ unless ok and script_found_in_login and script_found_in_data
26
+ ok = false
27
+ failed_to_log("Script found: in Login = #{script_found_in_login}; in Data = #{script_found_in_data}")
28
+ end
29
+ end
30
+
31
+ workbook.close
32
+
33
+ ok
34
+ rescue
35
+ failed_to_log(unable_to)
36
+ end
37
+
38
+ alias get_variables load_variables
39
+
40
+ def load_login_variables(workbook, enabled_only, file, key_type, scripts, dbg = nil)
41
+
42
+ ok = true
43
+ script_found_in_login = false
44
+ @login = Hash.new
45
+ enabled_cnt = 0
46
+ script_col = 0
47
+ role_col = 0
48
+ userid_col = 0
49
+ company_col = 0
50
+ password_col = 0
51
+ url_col = 0
52
+ env_col = 0
53
+ name_col = 0
54
+ appid_col = 0
55
+ ref_col = 0
56
+ node_col = 0
57
+ login_index = find_sheet_with_name(workbook, 'Login')
58
+ if login_index and login_index >= 0
59
+ workbook.default_sheet = workbook.sheets[login_index]
60
+
61
+ 1.upto(workbook.last_column) do |col|
62
+ column_name = workbook.cell(1, col).downcase
63
+ case column_name
64
+ when @myName.downcase
65
+ script_col = col
66
+ script_found_in_login = true
67
+ if scripts.is_a?(Array)
68
+ scripts << column_name
69
+ else
70
+ break
71
+ end
72
+ when 'role'
73
+ role_col = col
74
+ when 'userid', 'user_id'
75
+ userid_col = col
76
+ when 'companyid', 'company_id'
77
+ company_col = col
78
+ when 'password'
79
+ password_col = col
80
+ when 'url'
81
+ url_col = col
82
+ when 'environment'
83
+ env_col = col
84
+ when /reference/i
85
+ ref_col = col
86
+ when 'nodename'
87
+ node_col = col
88
+ when 'name'
89
+ name_col = col
90
+ when 'appid', 'app_id'
91
+ appid_col = col
92
+ else
93
+ scripts << column_name if scripts.is_a?(Array)
94
+ end
95
+ end
96
+
97
+ 2.upto(workbook.last_row) do |line|
98
+ role = workbook.cell(line, role_col)
99
+ userid = workbook.cell(line, userid_col)
100
+ password = workbook.cell(line, password_col)
101
+ url = workbook.cell(line, url_col)
102
+ env = workbook.cell(line, env_col)
103
+ username = workbook.cell(line, name_col)
104
+ nodename = workbook.cell(line, node_col)
105
+ companyid = workbook.cell(line, company_col)
106
+ appid = workbook.cell(line, appid_col)
107
+ enabled = workbook.cell(line, script_col).to_s
108
+ refs = workbook.cell(line, ref_col)
109
+
110
+ case key_type
111
+ when :id, :userid
112
+ key = userid
113
+ when :environment
114
+ key = env
115
+ when :role
116
+ key = role
117
+ else
118
+ key = userid
119
+ end
120
+
121
+ if enabled_only and enabled.length == 0
122
+ next
123
+ end
124
+
125
+ @login[key] = Hash.new
126
+ @login[key]['role'] = role
127
+ @login[key]['userid'] = userid
128
+ @login[key]['companyid'] = companyid
129
+ @login[key]['password'] = password
130
+ @login[key]['url'] = url
131
+ @login[key]['name'] = username
132
+ @login[key]['nodename'] = nodename
133
+ @login[key]['enabled'] = enabled
134
+ @login[key]['environment'] = env
135
+ @login[key]['appid'] = appid
136
+ @login[key]['references'] = refs
137
+
138
+ if enabled =~ /^y$/i
139
+ case key_type
140
+ when :environment
141
+ case env
142
+ when /^gen/i
143
+ enabled_cnt += 1
144
+ else
145
+ enabled_cnt += 1 if @env_name =~ /#{env}/
146
+ end
147
+ else
148
+ enabled_cnt += 1
149
+ end
150
+ end
151
+
152
+ end
153
+
154
+ @login.keys.sort.each do |key|
155
+ message_to_log("@login (by #{key_type}): #{key}='#{@login[key].to_yaml}'")
156
+ end if dbg
157
+
158
+ else
159
+ fail "'Login' worksheet not found in #{file}"
160
+ end
161
+
162
+ unless enabled_cnt > 0
163
+ ok = false
164
+ case key_type
165
+ when :environment
166
+ err_msg = "No enabled 'Login' entries for rows matching :#{key_type} => '#{@env_name}'"
167
+ else
168
+ err_msg = "No enabled 'Login' entries for rows matching :#{key_type}"
169
+ end
170
+ fail err_msg
171
+ end
172
+
173
+ return ok, script_found_in_login
174
+ rescue
175
+ failed_to_log(unable_to)
176
+ end
177
+
178
+ def load_data_variables(workbook, dbg = nil)
179
+
180
+ script_found_in_data = false
181
+
182
+ @var = Hash.new
183
+ data_index = find_sheet_with_name(workbook, 'Data')
184
+ workbook.default_sheet = workbook.sheets[data_index]
185
+ var_col = 0
186
+ default_col = 2
187
+
188
+ 2.upto(workbook.last_column) do |col|
189
+ script_name = workbook.cell(1, col)
190
+ if script_name == 'default'
191
+ default_col = col
192
+ end
193
+ if script_name == @myName
194
+ var_col = col
195
+ script_found_in_data = true
196
+ break
197
+ end
198
+ end
199
+
200
+ defaults = {}
201
+ 2.upto(workbook.last_row) do |line|
202
+ name = workbook.cell(line, 'A')
203
+ value = workbook.cell(line, default_col).to_s.strip
204
+ defaults[name] = value
205
+ end
206
+
207
+ 2.upto(workbook.last_row) do |line|
208
+ name = workbook.cell(line, 'A')
209
+ value = workbook.cell(line, var_col).to_s.strip
210
+ if value and value.length > 0
211
+ @var[name] = value
212
+ else
213
+ @var[name] = defaults[name]
214
+ end
215
+ end
216
+
217
+ @var.keys.sort.each do |name|
218
+ message_to_log("@var #{name}: '#{@var[name]}'")
219
+ end if dbg
220
+
221
+ script_found_in_data
222
+ rescue
223
+ failed_to_log(unable_to)
224
+ end
225
+
226
+ def load_html_validation_filters(file = @refs_spec)
227
+ sheet = 'HTML Validation Filters'
228
+ workbook = file =~ /\.xlsx$/ ? Roo::Excelx.new(file) : Roo::Excel.new(file)
229
+ @html_filters = Hash.new
230
+
231
+ sheet_index = find_sheet_with_name(workbook, "#{sheet}")
232
+ if sheet_index > -1
233
+ debug_to_log("Loading worksheet '#{sheet}'.")
234
+ workbook.default_sheet = workbook.sheets[sheet_index]
235
+
236
+ columns = Hash.new
237
+
238
+ 1.upto(workbook.last_column) do |col|
239
+ columns[workbook.cell(1, col).to_sym] = col
240
+ end
241
+
242
+ 2.upto(workbook.last_row) do |line|
243
+ identifier = workbook.cell(line, columns[:identifier])
244
+ validator = workbook.cell(line, columns[:validator])
245
+ pattern = workbook.cell(line, columns[:pattern])
246
+ action = workbook.cell(line, columns[:action])
247
+ alt_pattern = workbook.cell(line, columns[:alt_pattern])
248
+ alt_action = workbook.cell(line, columns[:alt_action])
249
+ script = workbook.cell(line, columns[:script])
250
+ head = workbook.cell(line, columns[:head])
251
+ meta = workbook.cell(line, columns[:meta])
252
+ body = workbook.cell(line, columns[:body])
253
+ frame = workbook.cell(line, columns[:frame])
254
+ fragment = workbook.cell(line, columns[:fragment])
255
+ report_more = workbook.cell(line, columns[:report_more])
256
+ description = workbook.cell(line, columns[:description])
257
+
258
+ # pattern = pattern ? Regexp.escape(pattern) : nil
259
+ # alt_pattern = alt_pattern ? Regexp.escape(alt_pattern) : nil
260
+
261
+ @html_filters[validator] = Hash.new unless @html_filters[validator]
262
+
263
+ @html_filters[validator][identifier] = {
264
+ :validator => validator,
265
+ :pattern => pattern,
266
+ :action => action,
267
+ :alt_pattern => alt_pattern,
268
+ :alt_action => alt_action,
269
+ :script => script,
270
+ :head => head,
271
+ :meta => meta,
272
+ :body => body,
273
+ :frame => frame,
274
+ :fragment => fragment,
275
+ :report_more => report_more,
276
+ :description => description }
277
+ end
278
+ else
279
+ failed_to_log("Worksheet '#{sheet}' not found #{file}")
280
+ end
281
+
282
+ @html_error_references = Hash.new
283
+
284
+ sheet = 'HTML Error References'
285
+ sheet_index = find_sheet_with_name(workbook, "#{sheet}")
286
+ if sheet_index > -1
287
+ debug_to_log("Loading worksheet '#{sheet}'.")
288
+ workbook.default_sheet = workbook.sheets[sheet_index]
289
+
290
+ columns = Hash.new
291
+
292
+ 1.upto(workbook.last_column) do |col|
293
+ columns[workbook.cell(1, col).to_sym] = col
294
+ end
295
+
296
+ 2.upto(workbook.last_row) do |line|
297
+ validator = workbook.cell(line, columns[:validator])
298
+ pattern = workbook.cell(line, columns[:pattern])
299
+ reference = workbook.cell(line, columns[:reference])
300
+ component = workbook.cell(line, columns[:component])
301
+ alm_df = workbook.cell(line, columns[:alm_df])
302
+ jira_ref = workbook.cell(line, columns[:jira_ref])
303
+ description = workbook.cell(line, columns[:description])
304
+
305
+ # pattern = pattern ? Regexp.escape(pattern) : nil
306
+
307
+ @html_error_references[pattern] = {
308
+ :validator => validator,
309
+ :reference => reference,
310
+ :component => component,
311
+ :alm_df => alm_df,
312
+ :jira_ref => jira_ref,
313
+ :description => description }
314
+ end
315
+ else
316
+ failed_to_log("Worksheet '#{sheet}' not found #{file}")
317
+ end
318
+
319
+ workbook.close
320
+
321
+ [@html_filters, @html_error_references]
322
+ rescue
323
+ failed_to_log(unable_to)
324
+ end
325
+
326
+ def parse_test_flag(string)
327
+ test = false
328
+ refs = nil
329
+ arr = string.is_a?(Array) ? string : string.to_s.split(/,\s*/)
330
+ ref_arr = []
331
+ arr.each { |r| ref_arr << format_reference(r) }
332
+ if string
333
+ if string == true or string == false
334
+ test = string
335
+ else
336
+ if string.length > 0
337
+ unless string =~ /^no$|^false$/i
338
+ test = true
339
+ unless string =~ /^yes$|^true$/i
340
+ refs = format_refs(string)
341
+ end
342
+ end
343
+ end
344
+ end
345
+ end
346
+ [test, refs, ref_arr]
347
+ rescue
348
+ failed_to_log(unable_to)
349
+ end
350
+
351
+
352
+ end
353
+ end
354
+ end
@@ -22,42 +22,73 @@ module Awetestlib
22
22
  # @param [String] desc Contains a message or description intended to appear in the log and/or report output
23
23
  # @return [Boolean] True if the Watir or Watir-webdriver function does not throw an exception.
24
24
  #
25
- def click(browser, element, how, what, desc = '')
26
- #debug_to_log("#{__method__}: #{element}, #{how}, #{what}")
27
- msg = build_message("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc)
28
- case element
29
- when :link
30
- browser.link(how, what).click
31
- when :button
32
- browser.button(how, what).click
33
- when :image
34
- browser.image(how, what).click
35
- when :radio
36
- case how
37
- when :index
38
- set_radio_by_index(browser, what, desc)
39
- else
40
- browser.radio(how, what).set
41
- end
42
- when :span
43
- browser.span(how, what).click
44
- when :div
45
- browser.div(how, what).click
46
- when :cell
47
- browser.cell(how, what).click
48
- else
49
- browser.element(how, what).click
25
+ def click(container, element, how, what, desc = '', wait = 10)
26
+ msg = build_message("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc, wait.to_s)
27
+ code = build_webdriver_fetch(element, how, what)
28
+ begin
29
+ eval("#{code}.when_present(#{wait}).click")
30
+ rescue => e
31
+ unless rescue_me(e, __method__, rescue_me_command(element, how, what, __method__.to_s), "#{container.class}")
32
+ raise e
33
+ end
50
34
  end
51
35
  passed_to_log(msg)
52
36
  true
53
37
  rescue
54
- failed_to_log("Unable to #{msg}. '#{$!}'")
38
+ if desc =~ /second try/i
39
+ passed_to_log(unable_to(msg))
40
+ else
41
+ failed_to_log(unable_to(msg))
42
+ end
43
+ end
44
+
45
+ alias click_js click
46
+
47
+ def click_as_needed(browser, target_container, target_elem, target_how, target_what, confirm_container, confirm_elem, confirm_how, confirm_what, desc = '', neg = false)
48
+ rtrn = true
49
+ nope = neg ? 'not ' : ''
50
+ debug_to_log("#{__method__.to_s.titleize}: Target: :#{target_elem} :#{target_how}=>'#{target_what}' in #{target_container}")
51
+ debug_to_log("#{__method__.to_s.titleize}: Confirm: :#{confirm_elem} :#{confirm_how}=>'#{confirm_what}' in #{confirm_container}")
52
+ windows_to_log(browser)
53
+ click(target_container, target_elem, target_how, target_what, desc)
54
+
55
+ if confirm_elem == :window
56
+ query = 'current?'
57
+ else
58
+ query = 'present?'
59
+ end
60
+
61
+ if confirm_what.is_a?(Regexp)
62
+ code = "#{nope}confirm_container.#{confirm_elem.to_s}(:#{confirm_how}, /#{confirm_what}/).#{query}"
63
+ else
64
+ code = "#{nope}confirm_container.#{confirm_elem.to_s}(:#{confirm_how}, '#{confirm_what}').#{query}"
65
+ end
66
+ debug_to_log("#{__method__}: code=[#{code}]")
67
+ limit = 30.0
68
+ increment = 0.5
69
+ seconds = 0.0
70
+ until eval(code) do
71
+ debug_to_log("#{__method__}: seconds=[#{seconds}] [#{code}]")
72
+ sleep(increment)
73
+ seconds += increment
74
+ if seconds.modulo(3.0) == 0.0
75
+ click(target_container, target_elem, target_how, target_what, "#{desc} (#{seconds} seconds)")
76
+ end
77
+ if seconds > limit
78
+ rtrn = false
79
+ break
80
+ end
81
+ end
82
+ rtrn
83
+ rescue
84
+ failed_to_log(unable_to)
55
85
  end
56
86
 
57
87
  # Click a specific DOM element by one of its attributes (*how) and that attribute's value (*what) and
58
88
  # do not wait for the browser to finish reloading. Used when a modal popup or alert is expected. Allows the script
59
89
  # to keep running so the popup can be handled.
60
- # @todo handle using Watir Webdriver which does not need no_wait.
90
+ #
91
+ # Call is passed to click() if using watir-webdriver as it does not recognize click_no_wait.
61
92
  #
62
93
  # @example
63
94
  # # html for a link element:
@@ -71,40 +102,44 @@ module Awetestlib
71
102
  # @return (see #click)
72
103
  #
73
104
  def click_no_wait(browser, element, how, what, desc = '')
74
- msg = build_message("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc)
75
- begin
76
- case element
77
- when :link
78
- browser.link(how, what).click_no_wait
79
- when :button
80
- browser.button(how, what).click_no_wait
81
- when :image
82
- browser.image(how, what).click_no_wait
83
- when :radio
84
- case how
85
- when :index
86
- set_radio_no_wait_by_index(browser, what, desc)
87
- else
88
- browser.radio(how, what).click_no_wait
89
- end
90
- when :span
91
- browser.span(how, what).click_no_wait
92
- when :div
93
- browser.div(how, what).click_no_wait
94
- when :checkbox
95
- browser.checkbox(how, what).click_no_wait
96
- when :cell
97
- browser.cell(how, what).click_no_wait
98
- else
99
- browser.element(how, what).click_no_wait
100
- end
101
- rescue => e
102
- unless rescue_me(e, __method__, rescue_me_command(element, how, what, :click_no_wait), "#{browser.class}")
103
- raise e
105
+ if $using_webdriver
106
+ click(browser, element, how, what, "#{desc} (called from click_no_wait)") # [#50300875]
107
+ else
108
+ msg = build_message("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc)
109
+ begin
110
+ case element
111
+ when :link
112
+ browser.link(how, what).click_no_wait
113
+ when :button
114
+ browser.button(how, what).click_no_wait
115
+ when :image
116
+ browser.image(how, what).click_no_wait
117
+ when :radio
118
+ case how
119
+ when :index
120
+ set_radio_no_wait_by_index(browser, what, desc)
121
+ else
122
+ browser.radio(how, what).click_no_wait
123
+ end
124
+ when :span
125
+ browser.span(how, what).click_no_wait
126
+ when :div
127
+ browser.div(how, what).click_no_wait
128
+ when :checkbox
129
+ browser.checkbox(how, what).click_no_wait
130
+ when :cell
131
+ browser.cell(how, what).click_no_wait
132
+ else
133
+ browser.element(how, what).click_no_wait
134
+ end
135
+ rescue => e
136
+ unless rescue_me(e, __method__, rescue_me_command(element, how, what, :click_no_wait), "#{browser.class}")
137
+ raise e
138
+ end
104
139
  end
140
+ passed_to_log(msg)
141
+ true
105
142
  end
106
- passed_to_log(msg)
107
- true
108
143
  rescue
109
144
  failed_to_log("Unable to #{msg} '#{$!}'")
110
145
  sleep_for(1)
@@ -270,9 +305,11 @@ module Awetestlib
270
305
  # @param [Boolean] nofail If true do not log a failed message if the option is not found in the select list.
271
306
  # @return (see #click)
272
307
  def select_option(browser, how, what, which, option, desc = '', nofail = false)
273
- list = browser.select_list(how, what)
308
+ list = browser.select_list(how, what).when_present
274
309
  msg = build_message("from list with :#{how}=>'#{what}", desc)
275
310
  select_option_from_list(list, which, option, msg, nofail)
311
+ rescue
312
+ failed_to_log(unable_to)
276
313
  end
277
314
 
278
315
  # Set radio button or checkbox to selected.
@@ -410,26 +447,21 @@ module Awetestlib
410
447
  def set_text_field(browser, how, what, value, desc = '', skip_value_check = false)
411
448
  #TODO: fix this to handle Safari password field
412
449
  msg = build_message("#{__method__.to_s.humanize} #{how}='#{what}' to '#{value}'", desc)
413
- msg << " (Skip value check)" if skip_value_check
414
- if browser.text_field(how, what).exists?
415
- tf = browser.text_field(how, what)
416
- tf.set(value)
417
- if skip_value_check
450
+ msg << ' (Skip value check)' if skip_value_check
451
+ browser.text_field(how, what).when_present.set(value)
452
+ if skip_value_check
453
+ passed_to_log(msg)
454
+ true
455
+ else
456
+ if browser.text_field(how, what).value == value
418
457
  passed_to_log(msg)
419
458
  true
420
459
  else
421
- if tf.value == value
422
- passed_to_log(msg)
423
- true
424
- else
425
- failed_to_log("#{msg}: Found:'#{tf.value}'.")
426
- end
460
+ failed_to_log("#{msg}: Found:'#{browser.text_field(how, what).value}'.")
427
461
  end
428
- else
429
- failed_to_log("#{msg}: Textfield not found")
430
462
  end
431
463
  rescue
432
- failed_to_log("Unable to '#{msg}': '#{$!}'")
464
+ failed_to_log(unable_to(msg))
433
465
  end
434
466
 
435
467
  alias set_textfield set_text_field
@@ -542,33 +574,87 @@ module Awetestlib
542
574
  # @param [String] desc Contains a message or description intended to appear in the log and/or report output
543
575
  # @return (see #click)
544
576
  #
545
- def fire_event(browser, element, how, what, event, desc = '')
546
- msg = build_message("#{element.to_s.titlecase}: #{how}=>'#{what}' event:'#{event}'", desc)
577
+ def fire_event(container, element, how, what, event, desc = '', wait = 10)
578
+ msg = build_message("#{element.to_s.titlecase}: #{how}=>'#{what}' event:'#{event}'", desc)
579
+ code = build_webdriver_fetch(element, how, what)
547
580
  begin
548
- case element
549
- when :link
550
- browser.link(how, what).fire_event(event)
551
- when :button
552
- browser.button(how, what).fire_event(event)
553
- when :image
554
- browser.image(how, what).fire_event(event)
555
- when :span
556
- browser.span(how, what).fire_event(event)
557
- when :div
558
- browser.div(how, what).fire_event(event)
559
- else
560
- browser.element(how, what).fire_event(event)
561
- end
581
+ eval("#{code}.when_present(#{wait}).fire_event('#{event}')")
562
582
  rescue => e
563
- unless rescue_me(e, __method__, rescue_me_command(element, how, what, __method__.to_s, event), "#{browser.class}")
583
+ unless rescue_me(e, __method__, rescue_me_command(element, how, what, __method__.to_s, event), "#{container.class}")
564
584
  raise e
565
585
  end
566
586
  end
567
- passed_to_log("Fire event: #{msg}. #{desc}")
587
+ passed_to_log(msg)
568
588
  true
569
589
  rescue
570
- failed_to_log("Unable to fire event: #{msg}. '#{$!}' #{desc}")
590
+ failed_to_log(unable_to(msg))
591
+ end
592
+
593
+ def resize_browser_window(browser, width, height, move_to_origin = true)
594
+ browser.driver.manage.window.resize_to(width, height)
595
+ message_to_report("Browser window resized to (#{width}, #{height}).")
596
+ sleep_for(0.5)
597
+ if move_to_origin
598
+ browser.driver.manage.window.move_to(0, 0)
599
+ message_to_report('Browser window moved to origin (0, 0).')
600
+ end
601
+ scroll_to_top(browser)
602
+ rescue
603
+ failed_to_log(unable_to)
604
+ end
605
+ alias resize_window resize_browser_window
606
+
607
+ #TODO: does this really scroll all the way to the bottom?
608
+ def send_page_down(browser)
609
+ browser.send_keys :page_down
610
+ debug_to_log('Sent page down')
611
+ end
612
+ alias scroll_to_bottom send_page_down
613
+ alias press_page_down send_page_down
614
+
615
+ #TODO: does this really scroll all the way to the top?
616
+ def sent_page_up(browser)
617
+ browser.send_keys :page_up
618
+ debug_to_log('Sent page up')
619
+ end
620
+ alias scroll_to_top sent_page_up
621
+ alias press_page_up sent_page_up
622
+
623
+ def send_spacebar(browser)
624
+ browser.send_keys :space
625
+ debug_to_log('Sent space')
626
+ end
627
+ alias press_spacebar send_spacebar
628
+
629
+ def send_enter(browser)
630
+ browser.send_keys :enter
631
+ debug_to_log('Sent enter')
632
+ end
633
+ alias press_enter send_enter
634
+
635
+ def send_tab(browser)
636
+ browser.send_keys :tab
637
+ debug_to_log('Sent tab')
638
+ end
639
+ alias press_tab send_tab
640
+
641
+ def send_right_arrow(browser)
642
+ browser.send_keys :arrow_right
643
+ debug_to_log('Sent right arrow')
644
+ end
645
+ alias press_right_arrow send_right_arrow
646
+
647
+ def send_left_arrow(browser)
648
+ browser.send_keys :arrow_left
649
+ debug_to_log('Sent left arrow')
650
+ end
651
+ alias press_left_arrow send_left_arrow
652
+
653
+ def send_escape(browser)
654
+ browser.send_keys :escape
655
+ debug_to_log('Sent Esc key')
571
656
  end
657
+ alias press_escape send_escape
572
658
 
573
659
  end
574
660
  end