awetestlib 0.1.2 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/README.md +55 -0
  2. data/awetestlib.windows.gemspec +1 -1
  3. data/awetestlib_osx.gemspec +1 -0
  4. data/bin/AutoItX3.dll +0 -0
  5. data/bin/awetestlib +23 -3
  6. data/bin/awetestlib-helpers.rb +39 -0
  7. data/bin/awetestlib-netbeans-setup.rb +39 -0
  8. data/bin/awetestlib-regression-setup.rb +16 -0
  9. data/bin/awetestlib-rubymine-setup.rb +33 -0
  10. data/images/logo.png +0 -0
  11. data/lib/awetestlib.rb +4 -4
  12. data/lib/awetestlib/html_report.rb +171 -0
  13. data/lib/{regression → awetestlib}/logging.rb +13 -46
  14. data/lib/awetestlib/regression/browser.rb +1233 -0
  15. data/lib/awetestlib/regression/drag_and_drop.rb +379 -0
  16. data/lib/awetestlib/regression/find.rb +431 -0
  17. data/lib/awetestlib/regression/legacy.rb +45 -0
  18. data/lib/awetestlib/regression/page_data.rb +190 -0
  19. data/lib/awetestlib/regression/runner.rb +307 -0
  20. data/lib/awetestlib/regression/tables.rb +491 -0
  21. data/lib/awetestlib/regression/user_input.rb +1256 -0
  22. data/lib/awetestlib/regression/utilities.rb +895 -0
  23. data/lib/awetestlib/regression/validations.rb +1184 -0
  24. data/lib/awetestlib/regression/waits.rb +391 -0
  25. data/lib/awetestlib/runner.rb +16 -0
  26. data/lib/version.rb +2 -2
  27. data/setup_samples/sample_netbeans/demo.rb +86 -0
  28. data/setup_samples/sample_netbeans/nbproject/configs/Demo.properties +2 -0
  29. data/setup_samples/sample_netbeans/nbproject/private/config.properties +1 -0
  30. data/setup_samples/sample_netbeans/nbproject/private/configs/Demo.properties +1 -0
  31. data/setup_samples/sample_netbeans/nbproject/private/private.properties +2 -0
  32. data/setup_samples/sample_netbeans/nbproject/project.properties +5 -0
  33. data/setup_samples/sample_netbeans/nbproject/project.xml +13 -0
  34. data/setup_samples/sample_rubymine/.idea/.name +1 -0
  35. data/setup_samples/sample_rubymine/.idea/encodings.xml +5 -0
  36. data/setup_samples/sample_rubymine/.idea/misc.xml +5 -0
  37. data/setup_samples/sample_rubymine/.idea/modules.xml +9 -0
  38. data/setup_samples/sample_rubymine/.idea/sample_rubymine.iml +9 -0
  39. data/setup_samples/sample_rubymine/.idea/scopes/scope_settings.xml +5 -0
  40. data/setup_samples/sample_rubymine/.idea/vcs.xml +7 -0
  41. data/setup_samples/sample_rubymine/.idea/workspace.xml +213 -0
  42. data/setup_samples/sample_rubymine/demo.rb +86 -0
  43. metadata +64 -17
  44. data/lib/regression/browser.rb +0 -1259
  45. data/lib/regression/drag_and_drop.rb +0 -374
  46. data/lib/regression/find.rb +0 -426
  47. data/lib/regression/legacy.rb +0 -40
  48. data/lib/regression/page_data.rb +0 -185
  49. data/lib/regression/runner.rb +0 -278
  50. data/lib/regression/tables.rb +0 -486
  51. data/lib/regression/user_input.rb +0 -1255
  52. data/lib/regression/utilities.rb +0 -891
  53. data/lib/regression/validations.rb +0 -1179
  54. data/lib/regression/waits.rb +0 -387
@@ -0,0 +1,45 @@
1
+ module Awetestlib
2
+ module Regression
3
+ module Legacy
4
+
5
+ #--
6
+ ##def open_log
7
+ # start = Time.now.to_f.to_s
8
+ #
9
+ # logTS = Time.at(@myRun.launched.to_f).strftime("%Y%m%d%H%M%S")
10
+ # xls = @myAppEnv.xls_name.gsub('.xls', '') + '_' if @myAppEnv.xls_name.length > 0
11
+ # @logFileSpec = "#{@myRoot}/#{logdir}/#{@myName}_#{@targetBrowser.abbrev}_#{xls}#{logTS}.log"
12
+ # init_logger(@logFileSpec, @myName)
13
+ #
14
+ # # message_tolog( self.inspect )
15
+ # message_to_log("#{@myName} launched at [#{@myRun.launched.to_f.to_s}][#{@myScript.id}][#{@myRun.id}][#{@myChild.id}]")
16
+ # debug_to_log("pid: #{$$}")
17
+ # message_to_log("#{@myName} begin at [#{start}]")
18
+ # message_to_log("#{@myName} environment [#{@myAppEnv.name}]")
19
+ # message_to_log("#{@myName} xls_name [#{@myAppEnv.xls_name}]") if @myAppEnv.xls_name.length > 0
20
+ # message_to_log("#{@myName} rootDir [#{@myRoot}]")
21
+ # message_to_log("#{@myName} Target Browser [#{@targetBrowser.name}]")
22
+ # mark_testlevel(@myParent.name, @myParent.level) # Module
23
+ # mark_testlevel(@myChild.name, @myChild.level) # SubModule
24
+ #
25
+ #end
26
+ #++
27
+
28
+ #def find_me(where, how, what)
29
+ # me = where.element(how, what)
30
+ # puts me.inspect
31
+ #rescue
32
+ # error_to_log("#{where.inspect} doesn't seem to respond to element() #{$!}")
33
+ #end
34
+
35
+ # def click_me(element)
36
+ # element.click
37
+ # rescue
38
+ # error_to_log("#{element.inspect} doesn't seem to respond to click() #{$!}")
39
+ # end
40
+
41
+
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,190 @@
1
+ module Awetestlib
2
+ module Regression
3
+ module PageData
4
+
5
+ =begin rdoc
6
+ :category: Page Data
7
+ :tags: data, DOM, page
8
+
9
+ _Parameters_::
10
+
11
+ *browser* is any container element, usually the browser window or a div within it. Best to use is the smallest that contains the desired data.
12
+
13
+ *types* is an array that defaults to all of: :text, :textarea, :select_list, :span, :hidden, :checkbox, and :radio.
14
+ Set types to an array of a subset of these if fewer elements are desired.
15
+
16
+ No positive validations are reported but failure is rescued and reported.
17
+ =end
18
+ def capture_page_data(browser, types = [:text, :textarea, :select_list, :span, :hidden, :checkbox, :radio])
19
+ start = Time.now
20
+ debug_to_log("Begin #{__method__}")
21
+ data = Hash.new
22
+ data[:id] = Hash.new
23
+ data[:name] = Hash.new
24
+ data[:index] = Hash.new
25
+ types.each do |type|
26
+ #debug_to_log("#{__method__}: #{type}. . .")
27
+ data[:id][type], data[:name][type], data[:index][type] = parse_elements(browser, type)
28
+ end
29
+ data
30
+ rescue
31
+ failed_to_log("#{__method__}: '#{$!}'")
32
+ ensure
33
+ stop = Time.now
34
+ passed_to_log("#{__method__.to_s.titleize} finished. (#{"%.5f" % (stop - start)} secs)")
35
+ #debug_to_log("End #{__method__}")
36
+ end
37
+
38
+ def compare_page_data(before, after, how, desc = '')
39
+ [:text, :textarea, :select_list, :span, :checkbox, :radio].each do |type|
40
+ before[how][type].each_key do |what|
41
+ msg = "#{desc} #{type} #{how}=#{what}: Expected '#{before[how][type][what]}'."
42
+ if after[how][type][what] == before[how][type][what]
43
+ passed_to_log(msg)
44
+ else
45
+ failed_to_log("#{msg} Found '#{after[how][type][what]}'")
46
+ end
47
+ end
48
+ end
49
+ rescue
50
+ failed_to_log("Unable to compare before and after page data. '#{$!}'")
51
+ end
52
+
53
+ =begin rdoc
54
+ :category: Page Data
55
+ :tags:data, DOM
56
+
57
+ *data* is the hash returned by capture_page_data().
58
+
59
+ *how* is one of :id, :name, :index
60
+
61
+ *what* is the target value for how. It can be a string or a regular expression
62
+
63
+ *type* is one of :text,:textarea,:select_list,:span,:hidden,:checkbox,:radio
64
+
65
+ *get_text* determines whether selected option's text or value is returned. Default is true, i.e., return the selected text.
66
+ This only applies when the *type* is :select_list.
67
+
68
+ =end
69
+ def fetch_page_data(data, how, what, type, get_text = true)
70
+ rslt = data[how][type][what]
71
+ if type == :select_list
72
+ value, text = rslt.split('::')
73
+ if get_text
74
+ rslt = text
75
+ else
76
+ rslt = value
77
+ end
78
+ end
79
+ rslt
80
+ end
81
+
82
+ =begin rdoc
83
+ :category: Page Data
84
+ :tags:data, DOM
85
+
86
+ *browser* is any container element. best to use is the smallest that contains the desired data.
87
+
88
+ *type* is one of these symbols: :text,:textarea,:select_list,:span,:hidden,:checkbox,:radio
89
+
90
+ Returns three hashes: id[type][id] = value, name[type][id] = value, index[type][id] = value
91
+
92
+ A given element appears once in the set of hashes depending on how is is found: id first
93
+ then name, then index.
94
+
95
+ Select list value is in the form 'value::text'. parse with x.split('::')
96
+
97
+ No positive validations are reported but failure is rescued and reported.
98
+ =end
99
+ def parse_elements(browser, type)
100
+ id = Hash.new
101
+ name = Hash.new
102
+ index = Hash.new
103
+ idx = 0
104
+ #debug_to_log("#{__method__}: #{type}")
105
+ case type
106
+ when :span
107
+ collection = browser.spans
108
+ when :select_list
109
+ collection = browser.select_lists
110
+ when :radio
111
+ collection = browser.radios
112
+ when :checkbox
113
+ collection = browser.checkboxes
114
+ else
115
+ collection = browser.elements(:type, type.to_s)
116
+ end
117
+ #debug_to_log("#{__method__}: collection: #{collection.inspect}")
118
+ collection.each do |e|
119
+ case type
120
+ when :span
121
+ vlu = e.text
122
+ when :select_list
123
+ vlu = "#{e.value}::#{e.selected_options[0]}"
124
+ when :radio
125
+ vlu = e.set?
126
+ when :checkbox
127
+ vlu = e.set?
128
+ else
129
+ vlu = e.value
130
+ end
131
+ idx += 1
132
+ if e.id.length > 0 and not e.id =~ /^__[A-Z]/
133
+ id[e.id] = vlu
134
+ elsif e.name.length > 0 and not e.name =~ /^__[A-Z]/
135
+ name[e.name] = vlu
136
+ else
137
+ index[idx] = vlu if not type == :hidden
138
+ end
139
+ end
140
+ [id, name, index]
141
+
142
+ rescue
143
+ failed_to_log("#{__method__}: '#{$!}'")
144
+ end
145
+
146
+ def get_textfield_value(browser, how, what, desc = '')
147
+ msg = "Return value in textfield #{how}='#{what}'"
148
+ msg << " #{desc}" if desc.length > 0
149
+ tf = browser.text_field(how, what)
150
+ if validate(browser, @myName, __LINE__)
151
+ if tf
152
+ debug_to_log("#{tf.inspect}")
153
+ vlu = tf.value
154
+ passed_to_log("#{msg} Value='#{vlu}'")
155
+ vlu
156
+ else
157
+ failed_to_log("#{msg}")
158
+ end
159
+ end
160
+ rescue
161
+ failed_to_log("Unable to #{msg}: '#{$!}'")
162
+ end
163
+
164
+ def get_textfield_value_by_name(browser, strg, desc = '')
165
+ get_textfield_value(browser, :name, strg, desc)
166
+ end
167
+
168
+ def get_textfield_value_by_id(browser, strg)
169
+ get_textfield_value(browser, :id, strg)
170
+ end
171
+
172
+ def get_element_text(browser, element, how, what, desc = '')
173
+ msg = "Return text in #{element} #{how}='#{what}'"
174
+ msg << " #{desc}" if desc.length > 0
175
+ text = browser.element(how, what).text
176
+ if validate(browser, @myName, __LINE__)
177
+ passed_to_log("#{msg} text='#{text}'")
178
+ text
179
+ end
180
+ rescue
181
+ failed_to_log("Unable to #{msg}: '#{$!}'")
182
+ end
183
+
184
+
185
+
186
+
187
+ end
188
+ end
189
+ end
190
+
@@ -0,0 +1,307 @@
1
+ require 'awetestlib/regression/browser'
2
+ require 'awetestlib/regression/find'
3
+ require 'awetestlib/regression/user_input'
4
+ require 'awetestlib/regression/waits'
5
+ require 'awetestlib/regression/tables'
6
+ require 'awetestlib/regression/page_data'
7
+ require 'awetestlib/regression/drag_and_drop'
8
+ require 'awetestlib/regression/utilities'
9
+ require 'awetestlib/logging'
10
+ require 'awetestlib/regression/validations'
11
+ require 'awetestlib/html_report'
12
+ #require 'rbconfig'
13
+ require 'ostruct'
14
+ require 'active_support'
15
+ require 'active_support/inflector'
16
+
17
+ module Awetestlib
18
+ module Regression
19
+ class Runner < Awetestlib::Runner
20
+
21
+ # order matters here
22
+ include Awetestlib::Logging
23
+ include Awetestlib::Regression::Browser
24
+ include Awetestlib::Regression::Find
25
+ include Awetestlib::Regression::UserInput
26
+ include Awetestlib::Regression::Waits
27
+ include Awetestlib::Regression::Tables
28
+ include Awetestlib::Regression::PageData
29
+ include Awetestlib::Regression::DragAndDrop
30
+ include Awetestlib::Regression::Utilities
31
+ include Awetestlib::Regression::Validations
32
+
33
+ ::DEBUG = 0
34
+ ::INFO = 1
35
+ ::WARN = 2
36
+ ::ERROR = 3
37
+ ::FATAL = 4
38
+ ::UNKNOWN = 5
39
+
40
+ ::TOP_LEVEL = 7
41
+ ::SECOND_LEVEL = ::TOP_LEVEL - 1
42
+
43
+ ::WAIT = 20
44
+ ::PASS = '-PASS'
45
+ ::FAIL = '-FAIL'
46
+
47
+ attr_accessor :browser, :browser_abbrev, :version, :env,
48
+ :library, :script_type, :script_file,
49
+ :log_properties, :log_queue, :log_class,
50
+ :notify_queue, :notify_class, :notify_id,
51
+ :screencap_path, :xls_path, :script_path, :user_token, :root_path,
52
+ :debug_on_fail,
53
+ :environment, :environment_name, :environment_url, :environment_nodename,
54
+ :cycle, :browser_sequence,
55
+ :output_to_log, :log_path_subdir, :report_all_test_refs,
56
+ :timeout
57
+
58
+ #def self.build(options)
59
+ # #build_class = "Awetestlib::#{script_module_for options[:script_type]}::Runner".constantize
60
+ # build_class = "Awetestlib::Runner".constantize
61
+ # #options = options.merge(:script_file => options[:script_file])
62
+ # #if build_class.respond_to?(:runner_class)
63
+ # # build_class.runner_class(options)
64
+ # #else
65
+ # build_class.new(options)
66
+ # #end
67
+ #end
68
+
69
+ # TODO: Encapsulate in some kind of config
70
+ ###################################
71
+ def setup_global_test_vars(options)
72
+ @my_failed_count = 0
73
+ @my_passed_count = 0
74
+ @my_error_references = Hash.new
75
+ @my_error_hits = Hash.new
76
+
77
+ @report_all_refs = options[:report_all_test_refs]
78
+
79
+ if options[:environment]
80
+ @myAppEnv = OpenStruct.new(
81
+ :name => options[:environment]['name'],
82
+ :url => options[:environment]['url'],
83
+ :nodename => options[:environment]['nodename']
84
+ )
85
+ @runenv = options[:environment]['nodename'] || options[:environment]['name']
86
+ @myURL = options[:environment]['url']
87
+ else
88
+ @runenv = options[:environment_name]
89
+ end
90
+
91
+ @targetBrowser = browser_to_use(options[:browser], options[:version])
92
+ @targetVersion = @targetBrowser.version
93
+ @browserAbbrev = @targetBrowser.abbrev
94
+ @myRoot = options[:root_path]
95
+ @myName = File.basename(options[:script_file]).sub(/\.rb$/, '')
96
+
97
+ if options[:output_to_log]
98
+ log_path = "#{@myRoot}/"
99
+ log_path << "#{options[:log_path_subdir]}/" if options[:log_path_subdir]
100
+ log_spec = File.join log_path, "#{@myName}_#{Time.now.strftime("%Y%m%d%H%M%S")}.log"
101
+ @myLog = init_logger(log_spec, @myName)
102
+ #@start_timestamp = Time.now
103
+ #start_to_log(@start_timestamp)
104
+ end
105
+
106
+ if options[:xls_path]
107
+ @xls_path = options[:xls_path]
108
+ end
109
+
110
+ #TODO need to find way to calculate these on the fly
111
+ # window top border 30
112
+ # IE toolbars 86
113
+ @vertical_hack_ie = 117
114
+ # FF toolbars 114
115
+ @vertical_hack_ff = 144
116
+ # window left border 4
117
+ @horizontal_hack_ie = 5
118
+ @horizontal_hack_ff = 4
119
+ #
120
+ # @x_tolerance = 12
121
+ # @y_tolerance = 12
122
+ require_gems
123
+ end
124
+
125
+ #def self.runner_class(options)
126
+ # script_file = options[:script_file]
127
+ # load script_file # force a load
128
+ #
129
+ # runner_module = self.module_for script_file
130
+ # klass_name = "#{runner_module.to_s}::Runner"
131
+ #
132
+ # # Define a Runner class in the test script's module inheriting from AwetestLegacy::Runner
133
+ # runner_module.module_eval do
134
+ # eval <<-RUBY
135
+ # class #{klass_name} < Awetestlib::Runner
136
+ # def initialize(options)
137
+ # #super(options)
138
+ # setup_global_test_vars(options)
139
+ # end
140
+ # end
141
+ # RUBY
142
+ # end
143
+ #
144
+ # runner = runner_module::Runner.new(options)
145
+ #
146
+ # if options[:library]
147
+ # lib_file = options[:library]
148
+ # load lib_file
149
+ # lib_module = self.module_for lib_file
150
+ # runner.extend(lib_module)
151
+ # end
152
+ #
153
+ # # Add in the methods defined in the script's module
154
+ # runner.extend(runner_module)
155
+ # runner
156
+ #end
157
+
158
+ def initialize(options)
159
+
160
+ options.each_pair do |k, v|
161
+ self.send("#{k}=", v)
162
+ end
163
+ load script_file
164
+ setup_global_test_vars(options)
165
+
166
+ # load and extend with library module if it exists
167
+ if options[:library]
168
+ lib_file = options[:library]
169
+ load lib_file # force a fresh load
170
+ lib_module = module_for lib_file
171
+ self.extend(lib_module)
172
+ end
173
+
174
+ # load and extend with script
175
+ script_file = options[:script_file]
176
+ load script_file # force a fresh load
177
+ runner_module = module_for script_file
178
+ self.extend(runner_module)
179
+
180
+ end
181
+
182
+ def browser_to_use(browser, browser_version = nil)
183
+ platform = ''
184
+ platform = 'Windows' if !!((RUBY_PLATFORM =~ /(win|w)(32|64)$/) || (RUBY_PLATFORM =~ /mswin|mingw/))
185
+ platform = 'OSX' if RUBY_PLATFORM =~ /darwin/
186
+
187
+ browser_abbrev =
188
+ Awetestlib::BROWSER_ALTERNATES[platform][browser] ?
189
+ Awetestlib::BROWSER_ALTERNATES[platform][browser] : browser
190
+ if not browser_version
191
+ case browser_abbrev
192
+ when 'IE'
193
+ browser_version = 8
194
+ when 'FF'
195
+ browser_version = 11
196
+ when 'C', 'GC'
197
+ browser_version = 10
198
+ when 'S'
199
+ browser_version = 10
200
+ end
201
+ end
202
+ return OpenStruct.new(
203
+ :name => (Awetestlib::BROWSER_MAP[browser_abbrev]),
204
+ :abbrev => browser_abbrev,
205
+ :version => browser_version
206
+ )
207
+ end
208
+
209
+ def require_gems
210
+
211
+ case @targetBrowser.abbrev
212
+
213
+ when 'IE'
214
+ if $watir_script
215
+ require 'watir/ie'
216
+ require 'watir'
217
+ require 'watir/process'
218
+ require 'watirloo'
219
+ require 'patches/watir'
220
+ Watir::IE.visible = true
221
+ else
222
+ require 'watir-webdriver'
223
+ end
224
+ when 'FF'
225
+ if @targetBrowser.version.to_f < 4.0
226
+ require 'firewatir'
227
+ require 'patches/firewatir'
228
+ else
229
+ require 'watir-webdriver'
230
+ end
231
+
232
+ when 'S'
233
+ require 'safariwatir'
234
+
235
+ when 'C', 'GC'
236
+ require 'watir-webdriver'
237
+
238
+ # when 'CL'
239
+ # require 'celerity'
240
+ # require 'watir-webdriver'
241
+
242
+ end
243
+
244
+ if USING_WINDOWS
245
+ require 'watir/win32ole'
246
+ @ai = ::WIN32OLE.new('AutoItX3.Control')
247
+ require 'pry'
248
+ else
249
+ # TODO: Need alternative for Mac?
250
+ @ai = ''
251
+ end
252
+
253
+ if @xls_path
254
+ require 'roo'
255
+ end
256
+
257
+ end
258
+
259
+ def module_for(script_file)
260
+ File.read(script_file).match(/^module\s+(\w+)/)[1].constantize
261
+ end
262
+
263
+ def before_run
264
+ initiate_html_report
265
+ start_run
266
+ end
267
+
268
+ def start
269
+ before_run
270
+ run
271
+ rescue Exception => e
272
+ failed_to_log(e.to_s)
273
+ ensure
274
+ after_run
275
+ end
276
+
277
+ def after_run
278
+ finish_run
279
+ @report_class.finish_report(@html_report_file)
280
+ open_report_file
281
+ #finish_run
282
+ @myLog.close if @myLog
283
+ end
284
+
285
+ def initiate_html_report
286
+ @html_report_name = File.join(File.dirname(__FILE__), '..', '..', '..', 'tmp', @myName)
287
+ @html_report_dir = File.dirname(@html_report_name)
288
+ FileUtils.mkdir @html_report_dir unless File.directory? @html_report_dir
289
+ @report_class = Awetestlib::HtmlReport.new(@myName)
290
+ @html_report_file = @report_class.create_report(@html_report_name)
291
+ end
292
+
293
+ def open_report_file
294
+ full_report_file = File.expand_path(@html_report_file)
295
+ if USING_WINDOWS
296
+ system("explorer file:///#{full_report_file}")
297
+ elsif USING_OSX
298
+ system("open #{full_report_file}")
299
+ else
300
+ puts "Can find report in #{full_report_file}"
301
+ end
302
+
303
+ end
304
+
305
+ end
306
+ end
307
+ end