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,280 @@
1
+ module Awetestlib
2
+
3
+ module Regression
4
+
5
+ module DateAndTime
6
+
7
+ def get_date_names(date = Date.today, language = 'English')
8
+ this_month = date.month
9
+ next_month = this_month == 12 ? 1 : this_month + 1
10
+ prev_month = this_month == 1 ? 12 : this_month - 1
11
+
12
+ month_arr = get_months(language)
13
+
14
+ this_month_name = month_arr[this_month]
15
+ next_month_name = month_arr[next_month]
16
+ prev_month_name = month_arr[prev_month]
17
+
18
+ arr = [date.year.to_s, date.day.to_s, this_month_name, next_month_name, prev_month_name]
19
+ debug_to_log("#{__method__} #{nice_array(arr)}")
20
+ arr
21
+ end
22
+
23
+ def get_days(language = 'English', abbrev = 0)
24
+ case language
25
+ when /english/i
26
+ full_arr = Date::DAYNAMES
27
+
28
+ # TODO: commented words with diacriticals until we can fix encoding confusion with mac/safari
29
+ when /french/i, /francais/i #, /fran�ais/i
30
+ full_arr = ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"]
31
+
32
+ else
33
+ failed_to_log(with_caller("Language #{language} not yet supported."))
34
+ full_arr = nil
35
+ end
36
+
37
+ if abbrev > 0
38
+ rtrn_arr = []
39
+ full_arr.each do |m|
40
+ rtrn_arr << m.slice(0, abbrev)
41
+ end
42
+ else
43
+ rtrn_arr = full_arr
44
+ end
45
+
46
+ rtrn_arr
47
+ rescue
48
+ failed_to_log(unable_to)
49
+ end
50
+
51
+ def next_day(yr, mo, dy, diff = 1)
52
+ tdy = DateTime.new(yr.to_i, mo.to_i, dy.to_i, 0, 0, 0)
53
+ tdy.advance(:days => diff).strftime("%Y-%m-%d")
54
+ end
55
+
56
+ def next_month(this)
57
+ unless this.is_a?(Fixnum)
58
+ this = this.to_i
59
+ end
60
+ nxt = this == 12 ? 1 : this + 1
61
+ nxt.to_s.rjust(2, '0')
62
+ end
63
+
64
+ def next_month_name(this, language = 'English')
65
+ unless this.is_a?(Fixnum)
66
+ this = get_months(language).index(this)
67
+ end
68
+ nxt = this == 12 ? 1 : this + 1
69
+ get_months(language)[nxt]
70
+ end
71
+
72
+ def prev_day(yr, mo, dy, diff = -1)
73
+ diff = diff > 0 ? -diff : diff
74
+ tdy = DateTime.new(yr.to_i, mo.to_i, dy.to_i, 0, 0, 0)
75
+ tdy.advance(:days => diff).strftime("%Y-%m-%d")
76
+ end
77
+
78
+ def prev_month(this)
79
+ prev = this.to_i == 1 ? 12 : this.to_i - 1
80
+ prev.to_s.rjust(2, '0')
81
+ end
82
+
83
+ def prev_month_name(this, language = 'English')
84
+ unless this.is_a?(Fixnum)
85
+ this = get_months(language).index(this)
86
+ end
87
+ prev = this == 1 ? 12 : this - 1
88
+ get_months(language)[prev]
89
+ end
90
+
91
+ def get_mdyy(t = Time.now)
92
+ "#{t.month}/#{t.day}/#{t.year}"
93
+ end
94
+
95
+ def get_month_name(this, language = 'English')
96
+ unless this.is_a?(Fixnum)
97
+ this = get_months(language).index(this)
98
+ end
99
+ get_months(language)[this]
100
+ end
101
+
102
+ def get_month_names(date = Date.today)
103
+ this_month = date.month
104
+ if this_month == 12
105
+ next_month = 1
106
+ else
107
+ next_month = this_month + 1
108
+ end
109
+ if this_month == 1
110
+ prev_month = 12
111
+ else
112
+ prev_month = this_month - 1
113
+ end
114
+
115
+ month_arr = Date::MONTHNAMES
116
+
117
+ this_month_name = month_arr[this_month]
118
+ next_month_name = month_arr[next_month]
119
+ prev_month_name = month_arr[prev_month]
120
+
121
+ arr = [date.year, date.day, this_month_name, next_month_name, prev_month_name]
122
+ debug_to_log("#{__method__} #{nice_array(arr)}")
123
+ arr
124
+
125
+ end
126
+
127
+ def get_months(language = 'English', abbrev = 0)
128
+ case language
129
+ when /english/i
130
+ full_arr = Date::MONTHNAMES
131
+
132
+ # TODO: commented words with diacriticals until we can fix encoding confusion with mac/safari
133
+ when /french/i, /francais/i #, /fran�ais/i
134
+ full_arr = [nil, 'janvier', 'fevrier', 'mars', 'avril', 'mai', 'juin',
135
+ 'juillet', 'aout', 'septembre', 'octobre', 'novembre', 'decembre']
136
+ # full_arr = [nil, 'janvier', 'f�vrier', 'mars', 'avril', 'mai', 'juin',
137
+ # 'juillet', 'ao�t', 'septembre', 'octobre', 'novembre', 'd�cembre']
138
+ else
139
+ failed_to_log(with_caller("Language #{language} not yet supported."))
140
+ full_arr = nil
141
+ end
142
+
143
+ if abbrev > 0
144
+ rtrn_arr = []
145
+ full_arr.each do |m|
146
+ if m
147
+ rtrn_arr << m.slice(0, abbrev)
148
+ else
149
+ rtrn_arr << nil
150
+ end
151
+ end
152
+ else
153
+ rtrn_arr = full_arr
154
+ end
155
+
156
+ rtrn_arr
157
+ rescue
158
+ failed_to_log(unable_to(language))
159
+ end
160
+
161
+ def translate_month_name(name, to, from = 'English')
162
+ get_months(from).index(name)
163
+ get_months(to)[get_months(from).index(name)]
164
+ end
165
+
166
+ def get_timestamp(format = 'long', offset = nil, offset_unit = :years)
167
+ t = DateTime.now
168
+ if offset
169
+ t = t.advance(offset_unit => offset)
170
+ end
171
+ case format
172
+ when 'dateonly'
173
+ t.strftime("%m/%d/%Y")
174
+ when 'condensed'
175
+ t.strftime("%Y%m%d%H%M")
176
+ when 'condensed_seconds'
177
+ t.strftime("%Y%m%d%H%M%S")
178
+ when 'long'
179
+ t.strftime("%m/%d/%Y %I:%M %p")
180
+ when 'mdyy'
181
+ get_mdyy(t)
182
+ when 'm/d/y'
183
+ get_mdyy(t)
184
+ else
185
+ Time.now.strftime("%m/%d/%Y %H:%M:%S")
186
+ end
187
+ end
188
+
189
+ def tic(new = false)
190
+ now = Time.now.utc
191
+ if new
192
+ @tic_tic = now
193
+ else
194
+ debug_to_log(with_caller("#{now.to_f - @tic_tic.to_f}", "#{get_call_array(2)[1]}"))
195
+ @tic_tic = now
196
+ end
197
+ end
198
+
199
+ def tic_m(msg = '')
200
+ now = Time.now.utc
201
+ debug_to_log(with_caller("#{now.to_f - @tic_tic.to_f}", "#{get_call_array(2)[1]}", msg))
202
+ @tic_tic = now
203
+ end
204
+
205
+ def time_it(container, desc, timeout = 3, &block)
206
+ start = Time.now.to_f
207
+ begin
208
+ Watir::Wait.until(timeout) { block.call(nil) }
209
+ rescue => e
210
+ if e.class.to_s =~ /TimeOutException/ or e.message =~ /timed out/
211
+ debug_to_log("#{desc} '#{$!}'")
212
+ return Time.now.to_f - start
213
+ elsif not rescue_me(e, __method__, "#{block.to_s}", "#{container.class}")
214
+ raise e
215
+ end
216
+ end
217
+ duration = Time.now.to_f - start
218
+ debug_to_report(with_caller(desc, duration.to_s))
219
+ duration
220
+ rescue
221
+ failed_to_log(unable_to(desc))
222
+ end
223
+
224
+ def sec2hms(s)
225
+ Time.at(s.to_i).gmtime.strftime('%H:%M:%S')
226
+ end
227
+
228
+ def pad_date(dt)
229
+ if dt and dt.length > 0
230
+ a, d1, b, d2, c = dt.split(/([\/\.-])/)
231
+ a = a.rjust(2, '0') unless a and a.length > 1
232
+ b = b.rjust(2, '0') unless b and b.length > 1
233
+ c = c.rjust(2, '0') unless c and c.length > 1
234
+ a + d1 + b + d2 + c
235
+ else
236
+ ''
237
+ end
238
+ end
239
+
240
+ def convert_y_m_d_to_ymd(yrs, mos, dys, fmt_out = '%Y-%m-%d', alt_fmt = '%Y-%m')
241
+ dys = [dys] unless dys.is_a?(Array)
242
+ mos = [mos] unless mos.is_a?(Array)
243
+ yrs = [yrs] unless yrs.is_a?(Array)
244
+ arr = []
245
+ if dys.size > 0
246
+ dys.each do |dy|
247
+ mo = mos[dys.index(dy)] ? mos[dys.index(dy)] : mos[0]
248
+ yr = yrs[dys.index(dy)] ? yrs[dys.index(dy)] : yrs[0]
249
+ arr << DateTime::parse("#{dy}/#{mo}/#{yr}").strftime(fmt_out).sub(/^0/, '')
250
+ end
251
+ else
252
+ mos.each do |mo|
253
+ yr = yrs[mos.index(mo)] ? yrs[mos.index(mo)] : yrs[0]
254
+ arr << DateTime::parse("1/#{mo}/#{yr}").strftime(alt_fmt).sub(/^0/, '')
255
+ end
256
+ end
257
+ arr
258
+ rescue
259
+ failed_to_log(unable_to("y:#{yrs}, m:#{mos}, d:#{dys}"))
260
+ end
261
+
262
+ def parse_mdy_to_datetime(mdy)
263
+ if mdy and mdy.length > 0
264
+ m, d1, d, d2, y = mdy.split(/([\/\.-])/)
265
+ y = "20#{y}" unless y.length == 4
266
+ ymd = "#{y}#{d1}#{m}#{d1}#{d}"
267
+ DateTime.parse(ymd)
268
+ end
269
+ rescue
270
+ failed_to_log(unable_to)
271
+ end
272
+
273
+ def diff_datetimes_in_days(beg_dt, end_dt)
274
+ (end_dt - beg_dt).to_i
275
+ end
276
+
277
+
278
+ end
279
+ end
280
+ end
@@ -7,6 +7,30 @@ module Awetestlib
7
7
  # Rdoc is work in progress
8
8
  module DragAndDrop
9
9
 
10
+ def viewport_size(browser)
11
+ if @targetBrowser.abbrev == 'IE' and get_browser_version(browser).to_i < 9
12
+ insert_viewport_div(browser)
13
+ else
14
+ x = browser.execute_script("return window.innerWidth")
15
+ y = browser.execute_script("return window.innerHeight")
16
+ [x, y]
17
+ end
18
+ end
19
+
20
+ def insert_viewport_div(browser)
21
+ browser.execute_script(
22
+ 'var test = document.createElement( "div" );' +
23
+ 'test.style.cssText = "position: fixed;top: 0;left: 0;bottom: 0;right: 0;"; ' +
24
+ 'test.id = "awetest-temp-viewport"; ' +
25
+ 'document.documentElement.insertBefore( test, document.documentElement.firstChild ); '
26
+ )
27
+ viewport = browser.div(:id, 'awetest-temp-viewport')
28
+ x = browser.execute_script("return arguments[0].offsetWidth", viewport)
29
+ y = browser.execute_script("return arguments[0].offsetHeight", viewport)
30
+ browser.execute_script("document.documentElement.removeChild( arguments[0] )", viewport)
31
+ [x, y]
32
+ end
33
+
10
34
  # Verify that specified *inner_element* is fully enclosed by *outer_element*.
11
35
  # @param [Watir::Element] inner_element A reference to a DOM element
12
36
  # @param [Watir::Element] outer_element A reference to a DOM element
@@ -19,47 +19,12 @@ module Awetestlib
19
19
  # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
20
20
  # @param [String, Regexp] value A string or a regular expression to be found in the *:value* attribute that uniquely identifies the element.
21
21
  # @param [String] desc Contains a message or description intended to appear in the log and/or report output
22
- def get_element(browser, element, how, what, value = nil, desc = '')
23
- msg = build_message("Return #{element} with :#{how}=#{what}", value, desc)
24
- target = nil
25
- what = Regexp.new(Regexp.escape(what)) unless how == :index or what.is_a?(Regexp)
26
- case element
27
- when :link
28
- target = browser.link(how, what)
29
- when :button
30
- target = browser.button(how, what)
31
- when :div
32
- target = browser.div(how, what)
33
- when :checkbox
34
- target = browser.checkbox(how, what, value)
35
- when :text_field, :textfield
36
- target = browser.text_field(how, what)
37
- when :image
38
- target = browser.image(how, what)
39
- when :file_field, :filefield
40
- target = browser.file_field(how, what)
41
- when :form
42
- target = browser.form(how, what)
43
- when :frame
44
- target = browser.frame(how, what)
45
- when :radio
46
- target = browser.radio(how, what, value)
47
- when :span
48
- target = browser.span(how, what)
49
- when :table
50
- target = browser.table(how, what)
51
- when :li
52
- target = browser.li(how, what)
53
- when :select_list, :selectlist
54
- target = browser.select_list(how, what)
55
- when :hidden
56
- target = browser.hidden(how, what)
57
- when :area
58
- target = browser.area(how, what)
59
- else
60
- target = browser.element(how, what)
61
- end
62
- if target.exists?
22
+ def get_element(container, element, how, what, value = nil, desc = '', options = {})
23
+ value, desc, options = capture_value_desc(value, desc, options) # for backwards compatibility
24
+ msg = build_message("Return #{element} with :#{how}=>'#{what}'", value, desc)
25
+ code = build_webdriver_fetch(element, how, what, options)
26
+ target = eval(code)
27
+ if target and target.exists?
63
28
  passed_to_log(msg)
64
29
  target
65
30
  else
@@ -67,12 +32,13 @@ module Awetestlib
67
32
  nil
68
33
  end
69
34
  rescue => e
70
- unless rescue_me(e, __method__, rescue_me_command(target, how, what), "#{browser.class}", target)
35
+ unless rescue_me(e, __method__, rescue_me_command(target, how, what), "#{container.class}", target)
71
36
  raise e
72
37
  end
73
38
  end
74
39
 
75
40
  def get_attribute_value(browser, element, how, what, attribute, desc = '')
41
+ #TODO: eliminate case statement by using eval with build_webdriver_fetch
76
42
  msg = build_message("Value of #{attribute} in #{element} #{how}=>#{what}.", desc)
77
43
  case element
78
44
  when :link
@@ -80,7 +46,7 @@ module Awetestlib
80
46
  when :button
81
47
  value = browser.button(how => what).attribute_value attribute
82
48
  else
83
- if browser.element(how => what).responds_to('attribute_value')
49
+ if browser.element(how => what).responds_to?('attribute_value')
84
50
  value = browser.element(how => what).attribute_value attribute
85
51
  end
86
52
  end
@@ -89,6 +55,67 @@ module Awetestlib
89
55
  failed_to_log(" Unable to #{msg}: '#{$!}'")
90
56
  end
91
57
 
58
+ def get_directory(path)
59
+ if File.directory?(path)
60
+ debug_to_log("Directory already exists, '#{path}'.")
61
+ else
62
+ Dir::mkdir(path)
63
+ debug_to_log("Directory was created, '#{path}'.")
64
+ end
65
+ path
66
+ end
67
+
68
+ def get_ancestor(descendant, element, how, what, desc = '')
69
+ found = false
70
+ how = 'class_name' if how.to_s == 'class'
71
+ tag = element.to_s.downcase
72
+ debug_to_log("target: #{descendant.tag_name} :id=>#{descendant.id}")
73
+ debug_to_log("goal: #{element} :#{how}=>#{what} #{desc}")
74
+ ancestor = target.parent
75
+ debug_to_log("#{ancestor.tag_name}: :class=>'#{ancestor.class_name}'")
76
+ code = "ancestor.#{how}"
77
+ what.is_a?(Regexp) ? code << " =~ /#{what.source}/" : code << " == '#{what}'"
78
+ debug_to_log("#{code}")
79
+ until found do
80
+ debug_to_log("#{ancestor.tag_name}: :class=>'#{ancestor.class_name}'")
81
+ if ancestor.tag_name == tag
82
+ if eval(code)
83
+ found = true
84
+ break
85
+ end
86
+ end
87
+ break unless ancestor
88
+ ancestor = ancestor.parent
89
+ end
90
+ ancestor
91
+ rescue
92
+ failed_to_log(unable_to)
93
+ end
94
+
95
+ def capture_value_desc(value, desc, options = nil)
96
+ opt = options.dup if options
97
+ unless opt.kind_of?(Hash)
98
+ opt = Hash.new
99
+ end
100
+ if value
101
+ vlu = value.dup
102
+ if opt[:value]
103
+ vlu = nil
104
+ else
105
+ opt[:value] = vlu
106
+ end
107
+ end
108
+ if desc
109
+ dsc = desc.dup
110
+ unless opt[:desc]
111
+ opt[:desc] = dsc
112
+ end
113
+ end
114
+ [vlu, dsc, opt]
115
+ rescue
116
+ failed_to_log(unable_to)
117
+ end
118
+
92
119
  # Return an array containing the options available for selection in a select_list identifified by
93
120
  # its attribute *how*, and the contents of that attribute *what*.
94
121
  # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.