itms_automation 1.4 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05bc918b330ea3205841b377fa90427de896f86ac4d2921665c6742f04a968fa
4
- data.tar.gz: 9b5af3d5827abca21f3ee2f7d1d692fa116032bd1d0c4cc4480b165e4f8ad150
3
+ metadata.gz: 7850f811199a124469648cc2f546e2c88093357622fd840ce84a40006aebce4b
4
+ data.tar.gz: 54cbd6376994cc02e8d4313b2d72b11d6fcf19d00953102f4bacc327c09a7911
5
5
  SHA512:
6
- metadata.gz: dc98bf5a616b58f3231cd55c6552ee7be8cbf9c92d8ada8d9fbf129a28b768922d5183a09bebbc9fdfe543d98af881ee921f82ecc0186f403c0e7c2cb184e9f9
7
- data.tar.gz: 7a866b84f0dc31945b0b28fa41a38d1cb31072f60e58582f5dd44c21226ff8d1ac5f6f302775e9dd9cafaeff9a34f56348ec6dc804ef142d44a8cc5fc77b0ff3
6
+ metadata.gz: a3a17ab5a1774e1f1828a37fb008002be37233db1436ff0d0d625a29f64ec214b614f12a8a85676c9668b1dfeb17a6b2dd8ba7e5337da5e9dbbe3b166a12e586
7
+ data.tar.gz: 1254e99aa1063497ce52cf24be2e6825350bd7b29185c1bd209454b3eea5fe63e436920056aa62b51aa0d6425bd3f6cf343d3d3b9b1a00b3a787b77816d91a49
@@ -13,7 +13,7 @@ def set_var(var_name, var_value)
13
13
  eval strEval, $dyn_vars
14
14
  end
15
15
 
16
- def check_dynamic_value value
16
+ def check_dynamic_value(value)
17
17
  if !value.is_a? Fixnum
18
18
  if value.include? "params="
19
19
  resolve_params value
@@ -78,8 +78,7 @@ def bind_with_dyn_json_vars(json, bind_json)
78
78
  end
79
79
  end
80
80
 
81
-
82
- def var_collect string_var
81
+ def var_collect(string_var)
83
82
  if string_var =~ /^.*{year}.*$/
84
83
  string_var = replace_year(string_var)
85
84
  end
@@ -99,12 +98,12 @@ def var_collect string_var
99
98
  return string_var
100
99
  end
101
100
 
102
- def replace_year str
101
+ def replace_year(str)
103
102
  t = Time.now()
104
103
  return str.gsub("{year}", t.year.to_s)
105
104
  end
106
105
 
107
- def replace_month str
106
+ def replace_month(str)
108
107
  t = Time.now()
109
108
  _month = t.month
110
109
  if _month < 10
@@ -115,7 +114,7 @@ def replace_month str
115
114
  return str
116
115
  end
117
116
 
118
- def replace_day str
117
+ def replace_day(str)
119
118
  t = Time.now()
120
119
  _day = t.day
121
120
  if _day < 10
@@ -126,8 +125,574 @@ def replace_day str
126
125
  return str
127
126
  end
128
127
 
129
-
130
-
131
128
  def print_variable(variable)
132
129
  puts "VALUE OF #{variable}: #{eval_with_dyn_vars(variable)}"
133
130
  end
131
+
132
+ def duration(start)
133
+ current = Time.now
134
+ return current - start
135
+ end
136
+
137
+ def print_log(status, start, method, *args)
138
+ icon = status === "passed" ? "✅" : "❌"
139
+ str = ""
140
+ args = *args
141
+ args_length = args.length - 1
142
+ args.each_with_index do |a, i|
143
+ if i < args_length
144
+ str += "\"#{a}\", "
145
+ else
146
+ str += "\"#{a}\""
147
+ end
148
+ end
149
+
150
+ if status === "passed"
151
+ puts "#{icon} Step: #{method}(#{str}) (#{duration(start)})".green
152
+ else
153
+ puts "#{icon} Step: #{method}(#{str}) (#{duration(start)})".red
154
+ end
155
+ end
156
+
157
+ def get_object_value(str_obj)
158
+ string_object = str_obj.gsub(/"/, "'")
159
+ hash_object = $OBJECT[string_object]
160
+ if hash_object == nil
161
+ raise "❌ Error: #{str_obj} NAME MAYBE NOT FOUND!!!"
162
+ end
163
+ if hash_object.keys[0].to_s.upcase != "CSS_SELECTOR"
164
+ raise "❌ Error: #{str_obj} should be formatted as Css Selector."
165
+ end
166
+ hash_object[hash_object.keys[0]]
167
+ end
168
+
169
+ def put_log str
170
+ start = Time.now
171
+ p str if $print_log == true
172
+ end
173
+
174
+ def check_valid_option_by?(option_by)
175
+ %w(text value).include? option_by
176
+ end
177
+
178
+ def validate_option_by(option_by)
179
+ raise "Please select valid option, invalid option - #{option_by}" unless check_valid_option_by? option_by
180
+ end
181
+
182
+ def check_valid_keys?(key)
183
+ %w(:cancel :help :backspace :tab :clear :return :enter :shift :control :alt :pause :escape :space :page_up :page_down :end :home :left :up :right :down :insert :delete :semicolon :equals).include? key
184
+ end
185
+
186
+ def validate_supported_keys(key)
187
+ raise "Please select valid keys, invalid key - #{key}" unless check_valid_option_by? key
188
+ end
189
+
190
+ def find_object string_object
191
+ startTime = Time.new.to_i
192
+ string_object = string_object.gsub(/"/, "'")
193
+ locator_matching = /(.*?)(\{.*?\})/.match(string_object)
194
+ dyn_pros = {}
195
+ if locator_matching != nil
196
+ string_object = locator_matching[1]
197
+ eval(locator_matching[2].gsub(/['][\s,\t]*?:[\s,\t]*?[']?/, "'=>'")).each { |k, v|
198
+ dyn_pros[k.to_s.upcase] = v
199
+ }
200
+ end
201
+ hash_object = $OBJECT[string_object]
202
+ if hash_object == nil
203
+ raise "❌ find_object error: >>> Object: #{string_object} is not found in Object Repository."
204
+ end
205
+ upcase_attrb = {}
206
+ if hash_object != nil
207
+ hash_object.each {|k,v|
208
+ k = k.to_s.upcase
209
+ if k =~ /ph_/i
210
+ if dyn_pros[k] != nil
211
+ if v =~ /<ph_value>/i
212
+ upcase_attrb[k[3..k.size-1]] = v.gsub(/<ph_value>/i, dyn_pros[k])
213
+ else
214
+ upcase_attrb[k[3..k.size-1]] = dyn_pros[k]
215
+ end
216
+ dyn_pros.delete(k)
217
+ end
218
+ else
219
+ upcase_attrb[k.to_s.upcase] = v
220
+ end
221
+ }
222
+ end
223
+ ph_attrs = {}
224
+ dyn_pros.each{|k,v|
225
+ if k =~ /ph_/i
226
+ ph_attrs[k] = v
227
+ else
228
+ upcase_attrb[k.to_s.upcase] = v
229
+ end
230
+ }
231
+ if upcase_attrb.size > 0
232
+ strId = ""
233
+ strClass = ""
234
+ strName = ""
235
+ strTagname = ""
236
+ strCssSelector = ""
237
+ strXpathSelector = ""
238
+ strText = ""
239
+ strRelated = ""
240
+ strRelatedType = ""
241
+
242
+ index = nil
243
+ minWidth = -1
244
+ maxWidth = -1
245
+ minHeight = -1
246
+ maxHeight = -1
247
+
248
+ ano_pros = {}
249
+
250
+ upcase_attrb.each{|key, value|
251
+ upcase_key = key.to_s.upcase
252
+ case upcase_key
253
+ when "XPATH_SELECTOR"
254
+ strXpathSelector = value
255
+ when "CSS_SELECTOR"
256
+ strCssSelector = value
257
+ when "ID"
258
+ strId = value
259
+ when "CLASS"
260
+ strClass = value
261
+ when "NAME"
262
+ strName = value
263
+ when "TAGNAME"
264
+ strTagname = value
265
+ when "TEXT"
266
+ strText = value
267
+ when "INDEX"
268
+ index = value
269
+ else
270
+ raise "❌ find_object error: >>> Wrong format type: #{key.to_s} of object: #{string_object}. Available supported format are: XPATH_SELECTOR | CSS_SELECTOR | ID | NAME | CLASS | TEXT | TAGNAME | INDEX"
271
+ end
272
+ }
273
+ continue_run = true;
274
+ ref_object = nil;
275
+
276
+ if strRelated != nil and strRelated.length > 0
277
+ ref_object = find_object(strRelated)
278
+ if (ref_object == nil)
279
+ continue_run = false
280
+ end
281
+ end
282
+
283
+ if continue_run == true
284
+ begin
285
+ if strCssSelector != nil and strCssSelector.length > 0
286
+ foundElements = get_objects_by_css_selector(strCssSelector)
287
+ elsif strXpathSelector != nil and strXpathSelector.length > 0
288
+ foundElements = get_objects_by_xpath_selector(strXpathSelector)
289
+ else
290
+ strGenerateXpathSel = generate_xpath_selector(strId, strClass, strName, strTagname)
291
+ if strGenerateXpathSel.length > 0
292
+ foundElements = get_objects_by_xpath_selector(strGenerateXpathSel)
293
+ else
294
+ if (check_string_letters_only(strId))
295
+ foundElements = get_objects_by_Id(strId)
296
+ elsif (check_string_letters_only(strName))
297
+ foundElements = get_objects_by_Name(strName)
298
+ elsif (check_string_letters_only(strClass))
299
+ foundElements = get_objects_by_Class(strClass)
300
+ elsif (check_string_letters_only(strTagname))
301
+ foundElements = get_objects_by_Tagname(strTagname)
302
+ end
303
+ end
304
+ end
305
+ if foundElements == nil or foundElements.length == 0
306
+ currentTime = Time.new.to_i
307
+ else
308
+ break
309
+ end
310
+ test = currentTime - startTime
311
+ puts "\n Finding the object #{string_object}... TIME-OUT:: #{test} < #{$wait_time}"
312
+ sleep(0.5)
313
+ end while (currentTime - startTime) < $wait_time
314
+
315
+ if foundElements != nil or foundElements.length != 0
316
+ if index != nil and index.to_i >= 0
317
+ matched_index = 0;
318
+ return_element = nil
319
+ foundElements.each{|cur_element|
320
+ passCheck = find_object_check_object(cur_element, ref_object, strRelatedType, strId, strClass, strName, strTagname, strText, minWidth, maxWidth, minHeight, maxHeight, ano_pros)
321
+ if passCheck
322
+ if matched_index == index.to_i
323
+ return_element = cur_element
324
+ break
325
+ else
326
+ matched_index = matched_index + 1
327
+ end
328
+ end
329
+ }
330
+ return return_element
331
+ else
332
+ return_element = nil
333
+ foundElements.each{|cur_element|
334
+ passCheck = find_object_check_object(cur_element, ref_object, strRelatedType, strId, strClass, strName, strTagname, strText, minWidth, maxWidth, minHeight, maxHeight, ano_pros)
335
+ if passCheck
336
+ return_element = cur_element
337
+ break
338
+ end
339
+ }
340
+ return return_element
341
+ end # if index != nil and index.to_i >= 0
342
+ end #if foundElements != nil or foundElements.length != 0
343
+ end #if continue = true
344
+ end
345
+ return nil
346
+ end
347
+
348
+ def generate_xpath_selector(strId, strClass, strName, strTagname)
349
+ strGenerateXpathSel = ""
350
+ if strId != nil and strId.length > 0 and (strId =~ /^#/) == nil
351
+ strGenerateXpathSel = "[@id='#{strId}']"
352
+ end
353
+ if strClass != nil and strClass.length > 0 and (strClass =~ /^#/) == nil
354
+ strGenerateXpathSel = "#{strGenerateXpathSel}[@class='#{strClass}']"
355
+ end
356
+ if strName != nil and strName.length > 0 and (strName =~ /^#/) == nil
357
+ strGenerateXpathSel = "#{strGenerateXpathSel}[@name='#{strName}']"
358
+ end
359
+
360
+ if strGenerateXpathSel.length > 0
361
+ if strTagname != nil and strTagname.length > 0
362
+ strGenerateXpathSel = "//#{strTagname}#{strGenerateXpathSel}"
363
+ else
364
+ strGenerateXpathSel = "//*#{strGenerateXpathSel}"
365
+ end
366
+ end
367
+
368
+ return strGenerateXpathSel
369
+ end
370
+
371
+ def check_string_letters_only(strToCheck)
372
+ if strToCheck != nil and strToCheck.length > 0 and strToCheck =~ /^[a-zA-Z]+$/
373
+ return true
374
+ end
375
+ return false
376
+ end
377
+
378
+ def get_objects_by_Id(strId)
379
+ foundElements = nil
380
+ begin
381
+ foundElements = page.all("*[@id='#{strId}']")
382
+ rescue StandardError => e
383
+ raise "Error: #{e.message}"
384
+ end
385
+
386
+ return foundElements
387
+ end
388
+
389
+ def get_objects_by_Class(strClass)
390
+ foundElements = nil
391
+ begin
392
+ foundElements = page.all("*[@class='#{strClass}']")
393
+ rescue StandardError => e
394
+ raise "Error: #{e.message}"
395
+ end
396
+
397
+ return foundElements
398
+ end
399
+
400
+ def get_objects_by_Name(strName)
401
+ foundElements = nil
402
+ begin
403
+ foundElements = page.all("*[@name='#{strName}']")
404
+ rescue StandardError => e
405
+ raise "Error: #{e.message}"
406
+ end
407
+
408
+ return foundElements
409
+ end
410
+
411
+ def get_objects_by_Tagname(strTagname)
412
+ foundElements = nil
413
+ begin
414
+ foundElements = page.all("#{strTagname}")
415
+ rescue StandardError => e
416
+ raise "Error: #{e.message}"
417
+ end
418
+
419
+ return foundElements
420
+ end
421
+
422
+ def get_objects_by_css_selector(strCssSelector)
423
+ foundElements = nil
424
+ begin
425
+ foundElements = page.all(:css, strCssSelector)
426
+ rescue StandardError => e
427
+ raise "Error: #{e.message}"
428
+ end
429
+ foundElements
430
+ end
431
+
432
+ def get_objects_by_xpath_selector(strXpathSelector)
433
+ foundElements = nil
434
+ begin
435
+ foundElements = page.all(:xpath, strXpathSelector)
436
+ rescue StandardError => e
437
+ raise "Error: #{e.message}"
438
+ end
439
+ foundElements
440
+ end
441
+
442
+ def find_object_check_object(cur_element, ref_object, ref_object_type, strId, strClass, strName, strTagname, strText, minWidth, maxWidth, minHeight, maxHeight, ano_pros)
443
+ passCheck = true
444
+ if cur_element != nil
445
+ # Check ref_object
446
+ if (ref_object != nil)
447
+ if find_object_check_ref_object(ref_object, ref_object_type, cur_element) == false
448
+ passCheck = false
449
+ end
450
+ end
451
+
452
+ # Check ID
453
+ if strId != nil and strId.length > 0
454
+ if strId =~ /^#/
455
+ strId = strId[1..-1]
456
+ end
457
+ if find_object_check_Id(cur_element, strId) == false
458
+ passCheck = false
459
+ end
460
+ end
461
+
462
+ # Check Class
463
+ if passCheck and strClass != nil and strClass.length > 0
464
+ if strClass =~ /^#/
465
+ strClass = strClass[1..-1]
466
+ end
467
+ if find_object_check_Class(cur_element, strClass) == false
468
+ passCheck = false
469
+ end
470
+ end
471
+
472
+ # Check Name
473
+ if passCheck and strName != nil and strName.length > 0
474
+ if strName =~ /^#/
475
+ strName = strName[1..-1]
476
+ end
477
+ if find_object_check_Name(cur_element, strName) == false
478
+ passCheck = false
479
+ end
480
+ end
481
+
482
+ # Check Tag name
483
+ if passCheck and strTagname != nil and strTagname.length > 0
484
+ if find_object_check_Tagname(cur_element, strTagname) == false
485
+ passCheck = false
486
+ end
487
+ end
488
+
489
+ # Check Text
490
+ if passCheck and strText != nil and strText.length > 0
491
+ if (strText =~ /^#/)
492
+ strText = strText[1..-1]
493
+ end
494
+
495
+ if find_object_check_Text(cur_element, strText) == false
496
+ passCheck = false
497
+ end
498
+ end
499
+
500
+ # Check minWidth
501
+ if passCheck and minWidth > 0
502
+ if !find_object_check_minWidth(cur_element, minWidth)
503
+ passCheck = false
504
+ end
505
+ end
506
+
507
+ # Check maxWidth
508
+ if passCheck and maxWidth > 0
509
+ if !find_object_check_maxWidth(cur_element, maxWidth)
510
+ passCheck = false
511
+ end
512
+ end
513
+
514
+ # Check minHeight
515
+ if passCheck and minHeight > 0
516
+ if !find_object_check_minHeight(cur_element, minHeight)
517
+ passCheck = false
518
+ end
519
+ end
520
+
521
+ # Check maxHeight
522
+ if passCheck and maxHeight > 0
523
+ if !find_object_check_maxHeight(cur_element, maxHeight)
524
+ passCheck = false
525
+ end
526
+ end
527
+
528
+ # Check another properties
529
+ if passCheck and ano_pros.length > 0
530
+ ano_pros.each{|property, value|
531
+ if value =~ /^#/
532
+ value = value[1..-1]
533
+ end
534
+ if !find_object_check_property(cur_element, property, value)
535
+ passCheck = false
536
+ break
537
+ end
538
+ }
539
+ end
540
+
541
+ return passCheck
542
+ end
543
+
544
+ return false
545
+ end
546
+
547
+ def find_object_check_Id(element, strId)
548
+ actual_Id = element[:id]
549
+ if actual_Id != nil and actual_Id.length > 0
550
+ actual_Id = actual_Id.strip
551
+ if reg_compare(actual_Id, strId)
552
+ return true
553
+ end
554
+ end
555
+
556
+ return false
557
+ end
558
+
559
+ def find_object_check_Class(element, strClass)
560
+ actual_Class = element[:class]
561
+ if actual_Class != nil and actual_Class.length > 0
562
+ actual_Class = actual_Class.strip
563
+ if reg_compare(actual_Class, strClass)
564
+ return true
565
+ end
566
+ end
567
+
568
+ return false
569
+ end
570
+
571
+ def find_object_check_Name(element, strName)
572
+ actual_Name = element[:name]
573
+ if actual_Name != nil and actual_Name.length > 0
574
+ actual_Name = actual_Name.strip
575
+ if reg_compare(actual_Name, strName)
576
+ return true
577
+ end
578
+ end
579
+
580
+ return false
581
+ end
582
+
583
+ def find_object_check_Tagname(element, strTagname)
584
+ actual_Tagname = element.tag_name()
585
+ if actual_Tagname != nil and actual_Tagname.length > 0
586
+ actual_Tagname = actual_Tagname.strip
587
+ if reg_compare(actual_Tagname, strTagname)
588
+ return true
589
+ end
590
+ end
591
+
592
+ return false
593
+ end
594
+
595
+ def find_object_check_Xpath(element, strXpath)
596
+
597
+ end
598
+
599
+ def find_object_check_Text(element, strText)
600
+ actual_Text = element.text()
601
+ if actual_Text != nil and actual_Text.length > 0
602
+ actual_Text = actual_Text.strip
603
+ if reg_compare(actual_Text, strText)
604
+ return true
605
+ end
606
+ end
607
+
608
+ return false
609
+ end
610
+
611
+ def find_object_check_minWidth(element, minWidth)
612
+ width = element[:width]
613
+ if (width >= minWidth)
614
+ return true
615
+ end
616
+
617
+ return false
618
+ end
619
+
620
+ def find_object_check_maxWidth(element, maxWidth)
621
+ width = element[:width]
622
+ if (width <= maxWidth)
623
+ return true
624
+ end
625
+
626
+ return false
627
+ end
628
+
629
+ def find_object_check_minHeight(element, minHeight)
630
+ height = element[:height]
631
+ if (height <= minHeight)
632
+ return true
633
+ end
634
+
635
+ return false
636
+ end
637
+
638
+ def find_object_check_maxHeight(element, maxHeight)
639
+ height = element[:height]
640
+ if (height <= maxHeight)
641
+ return true
642
+ end
643
+
644
+ return false
645
+ end
646
+
647
+ def find_object_check_ref_object(ref_object, ref_type, target_element)
648
+ begin
649
+ ref = ref_object.native
650
+ target = target_element.native
651
+ if(ref_type == "up" or ref_type == "down")
652
+ ref_x1 = ref.location.x - 10
653
+ ref_x2 = ref.location.x + ref.size.width + 10
654
+ target_x1 = target.location.x
655
+ target_x2 = target_x1 + target.size.width
656
+ elsif(ref_type == "left" or ref_type == "right")
657
+ ref_y1 = ref.location.y - 10
658
+ ref_y2 = ref.location.y + ref_object.native.size.height + 10
659
+ target_y1 = target.location.y
660
+ target_y2 = target_y1 + target.size.height
661
+ elsif(ref_type == "child" or ref_type == "parent")
662
+ ref_W = ref.location.x + ref.size.width
663
+ ref_H = ref.location.y + ref.size.height
664
+ target_W = target.location.x + target.size.width
665
+ target_H = target.location.y + target.size.height
666
+ end
667
+
668
+ if(ref_type == "up" and
669
+ target_x1 > ref_x1 and target_x2 < ref_x2 and # has same column or X Position
670
+ target.location.y < ref.location.y) # at row or Y position, target is upper
671
+ return true
672
+ elsif(ref_type == "down" and
673
+ target_x1 > ref_x1 and target_x2 < ref_x2 and # has same column or X Position
674
+ target.location.y > ref.location.y) # at row or Y position, target is at down
675
+ return true
676
+ elsif(ref_type == "left" and
677
+ target.location.x < ref.location.x and # at column or X Position, target is at left
678
+ target_y1 > ref_y1 and target_y2 < ref_y2) # at row or Y position, target is same as ref object
679
+ return true
680
+ elsif(ref_type == "right" and
681
+ target.location.x > ref.location.x and # at column or X Position, target is at right
682
+ target_y1 > ref_y1 and target_y2 < ref_y2) # at row or Y position, target is same as ref object
683
+ return true
684
+ elsif(ref_type == "child" and
685
+ (target_W < ref_W) and (target_H < ref_H) and
686
+ (target.location.x > ref.location.x) and (target.location.y > ref.location.y))
687
+ return true
688
+ elsif(ref_type == "parent" and
689
+ (target_W > ref_W) and (target_H > ref_H) and
690
+ (target.location.x < ref.location.x) and (target.location.y < ref.location.y))
691
+ return true
692
+ end
693
+ rescue StandardError => e
694
+ puts "Error: #{e.message}"
695
+ end
696
+
697
+ return false;
698
+ end