oct-automation-utilities 0.0.0

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 (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/oct-automation-utilities.rb +467 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24015a2f65305c235e154f0905df3bd444beb211
4
+ data.tar.gz: 0cfff2d07b269ab4cc995aec650bb5d761508cca
5
+ SHA512:
6
+ metadata.gz: 7702b7ef29ad9098a6174f58e2b7792032202fbe6b374837dd1782cac38bdcc25427c6a6e68b86cfcfcb067c7d0f2c47e753b8ab008a00e75769de3e4e4ff634
7
+ data.tar.gz: 6a3443075f461d313ea18141f06265b68116160436e143f6604af2e00ec10f42cdebe5fc616caaa1a6583f67995b5d0c39e3a4c465b91d3970bfade356f20049
@@ -0,0 +1,467 @@
1
+ module OctAutomationUtilities
2
+ require 'logger'
3
+ require 'capybara/rspec'
4
+
5
+ $test = ''
6
+ $step_num = 01
7
+
8
+ class Utilities
9
+ include Capybara::DSL
10
+ include Capybara::RSpecMatchers
11
+
12
+ #test data
13
+ attr_accessor :capture_screen, :screen_shot_path, :exe_time, :test_name, :project_directory, :test_time
14
+
15
+ #List of Objext
16
+ attr_accessor :obj_expected_page_content
17
+
18
+ def initialize
19
+ app = Performance::Application.new
20
+ self.project_directory = get_project_directory
21
+ self.test_name = 'default'
22
+ self.test_time = get_time
23
+ @config = Performance::Configuration.new
24
+ @log = Logger.new 'logger.log'
25
+ self.setup_log_level app.log_level
26
+ self.capture_screen = app.capture_screen_shot
27
+ end
28
+
29
+ def setup_directory(test_name = "default#{get_time}")
30
+ Dir.exist?("#{self.project_directory}/results") ? true : create_results_folder
31
+ Dir.exist?("#{self.project_directory}/results/#{test_name}") ? true : create_test_folder(test_name)
32
+ create_time_results_folder(test_name)
33
+ #Need to set self.screen_shot_path so that we can override the path as needed.
34
+ self.screen_shot_path = "#{self.project_directory}/results/#{test_name}/#{self.test_time}"
35
+ $test = self.screen_shot_path
36
+ $step_num = 01
37
+ self.log("Started - #{test_name}\n\nResults Path: #{self.screen_shot_path}", 'info')
38
+
39
+ end
40
+
41
+ def setup_log_level(log_level)
42
+ case log_level
43
+ when 'info'
44
+ @log.level = Logger::INFO
45
+ when 'debug'
46
+ @log.level = Logger::DEBUG
47
+ when 'warn'
48
+ @log.level = Logger::WARN
49
+ when 'error'
50
+ @log.level = Logger::ERROR
51
+ when 'fatal'
52
+ @log.level = Logger::FATAL
53
+ end
54
+ end
55
+
56
+ def log(msg, severity = 'info')
57
+ case severity
58
+ when 'progname'
59
+ @log.progname = msg
60
+ when 'debug'
61
+ @log.debug msg
62
+ when 'info'
63
+ @log.info msg
64
+ when 'warn'
65
+ @log.warn msg
66
+ when 'error'
67
+ @log.error msg
68
+ when 'fatal'
69
+ @log.fatal msg
70
+ end
71
+ puts msg
72
+ end
73
+
74
+ def create_results_folder
75
+ puts "Hi Aaron! This is the path to the results file we are trying to create #{self.project_directory}/results"
76
+ #Dir.mkdir("#{self.project_directory}/results")
77
+ end
78
+
79
+ def create_test_folder(test_name)
80
+ #Dir.mkdir("#{self.project_directory}/results/#{test_name}")
81
+ end
82
+
83
+ def create_time_results_folder(test_name)
84
+ #unless File.exists?("#{self.project_directory}/results/#{test_name}/#{self.test_time}")
85
+ #Dir.mkdir("#{self.project_directory}/results/#{test_name}/#{self.test_time}")
86
+ #end
87
+ end
88
+
89
+ def get_time
90
+ "#{Time.now.day}#{Time.now.month}#{Time.now.year}#{Time.now.hour.to_i - Time.now.zone.to_i}#{Time.now.min}#{Time.now.sec}"
91
+ end
92
+
93
+ def verify_page_content(content = '')
94
+ page.should_not have_content 'HTTP Status'
95
+ if content != nil
96
+ self.obj_expected_page_content = content
97
+ end
98
+ page.should have_content(self.obj_expected_page_content)
99
+ self.capture_screen_shot("Verify content - #{self.obj_expected_page_content}")
100
+ end
101
+
102
+ def capture_screen_shot(msg='', status = '')
103
+ begin
104
+ if self.capture_screen == 'true' or status == 'fail'
105
+ #used to sync the page so it can capture the screen shot.
106
+ page.has_no_title?('foo')
107
+ msgx = "#{$test}/#{$step_num.to_s}-#{msg.to_s}"
108
+ if status == 'fail'
109
+ self.log "failed screenshot name: #{msgx}", "fatal"
110
+ #page.driver.save_screenshot("#{msgx[0,101].to_s}-#{status}.png")
111
+ else
112
+ self.log "screenshot name: #{msgx}", "debug"
113
+ #page.driver.save_screenshot("#{msgx[0,101].to_s}.png")
114
+ end
115
+ $step_num = ($step_num + 1)
116
+ end
117
+ if status == ''
118
+ status = 'PASSED'
119
+ end
120
+ self.log("#{msg} - #{status}", 'info')
121
+ rescue Exception => e
122
+ self.log("#{msg} - FAILED", 'info')
123
+ raise e
124
+ end
125
+ end
126
+
127
+ def switch_windows(window_title)
128
+ #Usage Example: page.utilities.switch_windows('O.C. Tanner e-ClientLink')
129
+ page.within_window(window_title)
130
+ end
131
+
132
+ def close_windows
133
+ page.driver.browser.window_handles.each do |handle|
134
+ page.driver.browser.switch_to.window(handle)
135
+ page.exit(0)
136
+ end
137
+ end
138
+
139
+ def close_current_window
140
+ current_window = page.driver.browser.window_handles.last
141
+ page.within_window current_window do
142
+ page.execute_script "window.close()"
143
+ end
144
+ end
145
+
146
+ def close_all_windows
147
+ current_windows = page.driver.browser.window_handles
148
+ current_windows.each do |window_name|
149
+ page.within_window window_name do
150
+ page.execute_script "window.close()"
151
+ end
152
+ end
153
+ end
154
+
155
+ def browser_back
156
+ page.evaluate_script('window.history.back()')
157
+ end
158
+
159
+ def get_project_directory
160
+ File.expand_path('../../../', File.dirname(__FILE__))
161
+ end
162
+
163
+ def unique_id
164
+ dat = Time.now.to_s
165
+ dat.gsub!('-','')
166
+ dat.gsub!(':','')
167
+ dat.gsub!(' ','')
168
+ dat
169
+ end
170
+
171
+ #Author : Venkat
172
+ #Description: To click_ok_message
173
+ def click_ok_msgbox
174
+ page.driver.browser.switch_to.alert.accept
175
+ #@utilities.capture_screen_shot('Clicked Ok Confirm message box')
176
+ end
177
+
178
+ #Author: Murali Kunda
179
+ #Description: retrieve row number for the given text in a column
180
+ def retrieve_row_number(table_index,column='',text_to_verify)
181
+ row_number = 1
182
+ text_check = false
183
+ source = page.evaluate_script("document.getElementsByTagName('table')[#{table_index}].innerHTML")
184
+ doc = Nokogiri::HTML(source)
185
+ doc.css('tr').each do |row|
186
+ #row_content=row.xpath("./td[#{column.to_i}]").text
187
+ #row_content=row_content.gsub(/\s+/,'').squeeze('').strip
188
+ #row_content=row_content.squish
189
+
190
+ # if row.xpath("./td[#{column.to_i}]").text.gsub(/\s+/,'').squeeze('').strip == text_to_verify
191
+ if row.xpath("./td[#{column.to_i}]").text == text_to_verify
192
+ text_check = true
193
+ break
194
+ end
195
+ row_number = row_number + 1
196
+ end
197
+ if text_check == true
198
+ return row_number
199
+ else
200
+ return -1
201
+ end
202
+
203
+ end
204
+
205
+ #Author: Murali Kunda
206
+ #Description: retrieve row text of a given row and column, row number starts from 0
207
+ def retrieve_cell_content(table_index,column,row_num)
208
+ row_number = 0
209
+ text_to_return = ''
210
+ source = page.evaluate_script("document.getElementsByTagName('table')[#{table_index}].innerHTML")
211
+ doc = Nokogiri::HTML(source)
212
+ doc.css('tr').each do |row|
213
+ if row_number == row_num
214
+ text_to_return = row.xpath("./td[#{column.to_i}]").text
215
+ break
216
+ end
217
+ row_number = row_number+1
218
+ end
219
+ return text_to_return
220
+ end
221
+
222
+ def browser_maximize
223
+ if @config.head_less == 'false'
224
+ page.driver.browser.manage.window.maximize
225
+ end
226
+ end
227
+
228
+ #Author: Murali Kunda
229
+ def browser_launch(bro, url)
230
+ if bro.upcase =='IE'
231
+ Capybara.register_driver :ie do |app|
232
+ Capybara::Selenium::Driver.new(app, :browser => :ie)
233
+ end
234
+ Capybara.default_driver = :ie
235
+ elsif bro.upcase == 'CHROME'
236
+ Capybara.register_driver :chrome do |app|
237
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
238
+ end
239
+ Capybara.default_driver = :chrome
240
+ else
241
+ Capybara.register_driver :firefox do |app|
242
+ Capybara::Selenium::Driver.new(app, :browser => :firefox)
243
+ end
244
+ Capybara.default_driver = :firefox
245
+ end
246
+ visit url
247
+ self.log("Browser #{bro} launched with url #{url}", 'info')
248
+ end
249
+
250
+ #Author: Aravind
251
+ #Description: waits until given text appears on the page
252
+ def wait_until_text_appears(content)
253
+ page.has_content?(content)
254
+ end
255
+
256
+ #Author:Venkat
257
+ #Desc:moves the scroll bar position
258
+ def scroll(scroll_position)
259
+ page.execute_script "window.scrollBy(0,#{scroll_position})"
260
+ end
261
+
262
+ #Author: Nick Robertson
263
+ #Confirm pop up contains proper message
264
+ def confirm_popup_message(message, response = 'no')
265
+ a = page.driver.browser.switch_to.alert.text
266
+ if response == 'yes'
267
+ page.driver.browser.switch_to.alert.accept
268
+ else
269
+ page.driver.browser.switch_to.alert.dismiss
270
+ end
271
+
272
+ if a.include? message
273
+ return 0
274
+ else
275
+ return 1
276
+ end
277
+ end
278
+
279
+ #Author:Aravind ; Description : Click on OK button on pop-up
280
+ def click_on_ok_popup
281
+ page.driver.browser.switch_to.alert.accept
282
+ end
283
+
284
+ #Author: Murali Kunda
285
+ #Desc: Verifies content of the text and returns true or false. This method is different from Verify_page_content. Verify_page_content fails and exits test if
286
+ #expected content is not visible. This method returns false when content is not visible and continue to the next step
287
+ def is_content_visible(content)
288
+ if content != nil
289
+ self.obj_expected_page_content = content
290
+ end
291
+ return page.has_content?(self.obj_expected_page_content)
292
+ end
293
+
294
+ #Author: Murali Kunda
295
+ def is_checked(attribute = 'name', obj)
296
+ if page.all("[#{attribute}^='#{obj}'][checked]").count > 0
297
+ return true
298
+ else
299
+ return false
300
+ end
301
+ end
302
+
303
+ def check(attribute = 'name', obj)
304
+ if is_checked(obj) == false
305
+ page.find("[#{attribute}^='#{obj}']").click
306
+ end
307
+ end
308
+
309
+ def uncheck(attribute = 'name', obj)
310
+ if is_checked(obj) == true
311
+ page.find("[#{attribute}^='#{obj}']").click
312
+ end
313
+ end
314
+
315
+ #Author:venkat
316
+ #Desc:changed the default wait time(2) to the wait time passing through parameter
317
+ def set_default_wait_time(wait_time)
318
+ if wait_time !=''
319
+ Capybara.default_wait_time=Capybara.default_wait_time.to_i+wait_time.to_i
320
+ end
321
+ end
322
+
323
+ #Author: Murali Kunda
324
+ def read_servers(app_name)
325
+ #loading milestones objects yaml file
326
+ objs = YAML.load(File.read('servers_map.yml'))
327
+ objects = Hash.new
328
+
329
+ #parsng yaml and storing the objects in the hash
330
+ objs.each_value do |objects_base|
331
+ objects_base.each do |envs|
332
+ envs.each do |areas|
333
+ if envs[0].upcase == @config.env.upcase #Comparing area type
334
+ envs[1].each do |areas|
335
+ if areas[0] == app_name
336
+ return areas[1]
337
+ end
338
+ end
339
+ end
340
+ end
341
+ end
342
+ end
343
+ end
344
+
345
+
346
+
347
+ # Author: Mike Nelson
348
+ # compare_strings compares two strings, as when verifying on-screen content.
349
+ # Logs results, throws exception when false.
350
+ # Returns true when strings match, false when they do not.
351
+ # Parameters:
352
+ # expected_string: a string containing the expected content to be verified
353
+ # test_string: a string containing the test content to compare to expected_string
354
+ # description: a string describing the expected content, i.e. "Sender's Email Address"
355
+ # case_sensitive: a boolean that controls whether the comparison is case_sensitive, defaults to false.
356
+ def compare_strings (expected_string, test_string, description, case_sensitive = false)
357
+ estr = case_sensitive ? expected_string.upcase : expected_string
358
+ tstr = case_sensitive ? test_string.upcase : test_string
359
+ if estr == tstr
360
+ log "'#{description}' verified equal to '#{expected_string}'."
361
+ return true
362
+ else
363
+ error_str = "'#{description}' verification FAILED. Expected '#{expected_string}', got '#{test_string}'."
364
+ log error_str
365
+ raise Capybara::ExpectationNotMet, error_str
366
+ return false
367
+ end
368
+ end
369
+
370
+ # Author: Aaron Tracy
371
+ # Verify the text passed in is located on the page.
372
+ def verify_page_contains_text(text_to_verify)
373
+ log("Verify page has text: #{text_to_verify}")
374
+ page.has_xpath?(".//*[contains(*," + 34.chr + text_to_verify + 34.chr + ")]") ? true : raise(Capybara::ExpectationNotMet, "Couldn't locate #{text_to_verify} on the page.")
375
+ end
376
+
377
+ # Author: Aaron Tracy
378
+ # Verify the text passed in is located on the page.
379
+ def verify_page_contains_link(text_to_verify)
380
+ log("Verify page has link: #{text_to_verify}")
381
+ page.has_link?(text_to_verify) ? true : raise(Capybara::ExpectationNotMet, "Couldn't locate #{text_to_verify} link on the page.")
382
+ end
383
+
384
+ # Author: Aaron Tracy
385
+ # Verify the text passed in is located on the page.
386
+ def verify_page_contains_button(text_to_verify)
387
+ log("Verify page has button: #{text_to_verify}")
388
+ page.has_button?(text_to_verify) ? true : raise(Capybara::ExpectationNotMet, "Couldn't locate #{text_to_verify} button on the page.")
389
+ end
390
+
391
+ # Author: Aaron Tracy
392
+ # Verify the text passed in is located on the page.
393
+ def verify_page_contains_xpath(text_to_verify, description)
394
+ log("Verify page has xpath for: #{description}")
395
+ page.has_xpath?(text_to_verify) ? true : raise(Capybara::ExpectationNotMet, "Couldn't locate #{description} on the page.")
396
+ end
397
+
398
+ # Author: Aaron Tracy
399
+ # Verify the text passed in is located on the page.
400
+ def verify_page_contains_xpath_with_text(xpath, text_to_verify)
401
+ log("Verify page has xpath for: #{text_to_verify}")
402
+ page.has_xpath?(xpath, :text => text_to_verify) ? true : raise(Capybara::ExpectationNotMet, "Couldn't locate #{text_to_verify} on the page.")
403
+ end
404
+
405
+ # Author: Aaron Tracy
406
+ # Verify the field exists and contains the text. Description is simply the label of the control
407
+ def verify_page_contains_field(id_name_label, text, description)
408
+ log("Verify page has field for: #{description}")
409
+ page.has_field?(id_name_label, :with => text) ? true : raise(Capybara::ExpectationNotMet, "Couldn't locate #{description} on the page.")
410
+ #page.has_field?(id_name_label) ? true : raise(Capybara::ExpectationNotMet, "Couldn't locate #{description} on the page.")
411
+ end
412
+
413
+ # Author: Mike Nelson
414
+ # set_checkbox checks or unchecks a checkbox using its ID, name, or label text. It logs its results, and
415
+ # does not care whether the box is initially checked or unchecked.
416
+ # Logs results. Returns true when
417
+ # Parameters:
418
+ # checkbox_obj is the ID, name, or label text of the checkbox
419
+ # checkbox_title: a string describing the checkbox, i.e. "notify me when viewed"
420
+ # check_uncheck: a string with one of two values: "check" or "uncheck"
421
+ def set_checkbox (checkbox_obj, checkbox_title, check_uncheck)
422
+ if check_uncheck.downcase == "check"
423
+ Capybara::check(checkbox_obj)
424
+ elsif check_uncheck.downcase == "uncheck"
425
+ Capybara::uncheck(checkbox_obj)
426
+ else
427
+ raise(Capybara::ExpectationNotMet, "set_checkbox: check_uncheck invalid value '#{check_uncheck}'. Valid values: 'check' or 'uncheck'.")
428
+ return(false)
429
+ end
430
+ log("Checkbox '#{checkbox_title}' successful action: '#{check_uncheck}'.", "info")
431
+ return(true)
432
+ end
433
+
434
+ # This is the same as set_checkbox, but uses an xpath instead of an ID, name, or label
435
+ def set_checkbox_xpath (checkbox_obj, checkbox_title, check_uncheck)
436
+ if check_uncheck.downcase == "check"
437
+ page.find(:xpath, checkbox_obj).set(true)
438
+ elsif check_uncheck.downcase == "uncheck"
439
+ page.find(:xpath, checkbox_obj).set(false)
440
+ else
441
+ raise(Capybara::ExpectationNotMet, "set_checkbox_xpath: check_uncheck invalid value '#{check_uncheck}'. Valid values: 'check' or 'uncheck'.")
442
+ return(false)
443
+ end
444
+ log("Checkbox '#{checkbox_title}' successful action: '#{check_uncheck}'.")
445
+ return(true)
446
+ end
447
+
448
+ # Author: Mike Nelson
449
+ # string_is_numeric? returns true if the string only contains digits,
450
+ # or false if there is anything else in the string, even + or -, or a decimal.
451
+ # It uses regular expression evaluation. I ripped this off from this web site:
452
+ # https://www.ruby-forum.com
453
+ def string_is_numeric? (a_string)
454
+ /\A\d+\z/ === a_string
455
+ end
456
+
457
+ def todayMMDDYYYY
458
+ right_now = Time.new
459
+ day = ("00" + right_now.day.to_s)[-2,2]
460
+ month = ("00" + right_now.month.to_s)[-2,2]
461
+ year = ("0000" + right_now.year.to_s)[-4,4]
462
+ return "#{month}/#{day}/#{year}"
463
+ end
464
+
465
+ end
466
+
467
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oct-automation-utilities
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Tracy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Utilities class that performs common automation functionality that can
14
+ be used over multiple projects
15
+ email: aaron.tracy@octanner.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/oct-automation-utilities.rb
21
+ homepage: https://github.com/octanner/automation-utilities-gem
22
+ licenses: []
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Utilities for Automation Framework
44
+ test_files: []