rudra 1.0.10 → 1.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rudra.rb +80 -126
  3. metadata +13 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 672d728a083a59f7e8f5559154e96aa6cf496dea5d6fa4398c1b261f1e05c5e6
4
- data.tar.gz: e5f5ccb24176bfaedca406eee52a924546810cfd9431ca36874f261d4244e847
3
+ metadata.gz: 18f80bbed760fbf34d622b60e647507bab5ddfea167a6d144430dae84ed35a98
4
+ data.tar.gz: '04965c6ea61ea288861f22c6fabbb61240f384faf99b9a9402e51273d201caa4'
5
5
  SHA512:
6
- metadata.gz: 45d6c47667175460e47356c406338830048ed92938f0e56c7e388a5a073d31bc0cc517229665f79d57422c1e4afb6234331aa89855f3b200961c78872f76f606
7
- data.tar.gz: 032a07fb27ad99d89a3008e7164e218862ac2f151f0a9b14dec453504ed5ccd93386518a176105ac0d3c59ba37e63653a75f89f20dc7476897a8ff9d605d98df
6
+ metadata.gz: 55a6791c2d89ecb33b3833ac41ef6f1514b482ac13525070aa246166bc5d530c7dc23bf09d353630f4205ab5959dc8202a49cee271e96554e485e19a5ca24f6e
7
+ data.tar.gz: 1e9d5d7c2fd2cfa29aa3baa80145647e3088096a3af625f5e49d7baf931d2a72082d73abfeb7e12e44995a8d29607d08693e0533bbffdb5a34995e1182b7ee44
@@ -1,6 +1,7 @@
1
1
  require 'selenium-webdriver'
2
2
  require 'webdrivers/chromedriver'
3
3
  require 'webdrivers/geckodriver'
4
+ require 'webdrivers/iedriver'
4
5
 
5
6
  # Selenium::WebDriver::Chrome::Service.driver_path = './webdrivers/chromedriver'
6
7
  # Selenium::WebDriver::Firefox::Service.driver_path = './webdrivers/geckodriver'
@@ -16,7 +17,7 @@ require 'webdrivers/geckodriver'
16
17
  # @attr_reader [Boolean] verbose Verbose mode
17
18
  class Rudra
18
19
  # Supported Browsers
19
- BROWSERS = %i[chrome firefox safari].freeze
20
+ BROWSERS = %i[chrome firefox ie safari].freeze
20
21
 
21
22
  # Element Finder Methods
22
23
  HOWS = %i[
@@ -24,8 +25,15 @@ class Rudra
24
25
  name partial_link_text tag_name xpath
25
26
  ].freeze
26
27
 
28
+ # Attributes
29
+ ATTRIBUTES = %i[
30
+ browser driver install_dir locale
31
+ headless log_prefix timeout verbose
32
+ ].freeze
33
+
27
34
  attr_reader :browser, :driver, :install_dir, :locale,
28
- :log_prefix, :timeout, :verbose
35
+ :headless, :screen_dir, :log_prefix,
36
+ :timeout, :verbose
29
37
 
30
38
  # Initialize an instance of Rudra
31
39
  # @param [Hash] options the options to initialize Rudra
@@ -34,27 +42,24 @@ class Rudra
34
42
  # @option options [String] :install_dir ('./webdrivers/') the install
35
43
  # directory of WebDrivers
36
44
  # @option options [Symbol] :locale (:en) the browser locale
45
+ # @option options [Boolean] :headless (false) headless mode
46
+ # @option options [String] :screen_dir ('.//') the location of screenshots
37
47
  # @option options [String] :log_prefix (' - ') log prefix
38
48
  # @option options [Integer] :timeout (30) implicit_wait timeout
39
49
  # @option options [Boolean] :verbose (true) verbose mode
40
50
  def initialize(options = {})
41
51
  self.browser = options.fetch(:browser, :chrome)
42
52
  self.install_dir = options.fetch(:install_dir, './webdrivers/')
43
- self.locale = options.fetch(:locale, :en)
53
+ self.locale = options.fetch(:locale, :enscreens)
54
+ self.headless = options.fetch(:headless, false)
55
+ self.screen_dir = options.fetch(:screen_dir, './screens/')
44
56
  self.log_prefix = options.fetch(:log_prefix, ' - ')
45
57
  self.verbose = options.fetch(:verbose, true)
58
+ self.main_label = caller_locations(2, 1).first.label
46
59
 
47
60
  initialize_driver
48
61
 
49
62
  self.timeout = options.fetch(:timeout, 30)
50
-
51
- @verbose && (
52
- puts %(
53
- ============ Rudra ============
54
- Browser: #{@browser}, Locale: #{@locale}
55
- ============ Log ============
56
- ).lines.map(&:strip).reject(&:empty?).join("\n")
57
- )
58
63
  end
59
64
 
60
65
  #
@@ -64,14 +69,12 @@ class Rudra
64
69
  # Initialize ActionBuilder
65
70
  # @return [Selenium::WebDriver::ActionBuilder] ActionBuilder
66
71
  def action
67
- log
68
72
  driver.action
69
73
  end
70
74
 
71
75
  # Get the active element
72
76
  # @return [Selenium::WebDriver::Element] the active element
73
77
  def active_element
74
- log
75
78
  driver.switch_to.active_element
76
79
  end
77
80
 
@@ -83,43 +86,36 @@ class Rudra
83
86
  # @option opts [Boolean] :secure (false) a boolean
84
87
  # @option opts [Time, DateTime, Numeric, nil] :expires (nil) expiry date
85
88
  def add_cookie(opts = {})
86
- log(opts)
87
89
  driver.manage.add_cookie(opts)
88
90
  end
89
91
 
90
92
  # Accept an alert
91
93
  def alert_accept
92
- log
93
94
  switch_to_alert.accept
94
95
  end
95
96
 
96
97
  # Dismiss an alert
97
98
  def alert_dismiss
98
- log
99
99
  switch_to_alert.dismiss
100
100
  end
101
101
 
102
102
  # Send keys to an alert
103
103
  def alert_send_keys(keys)
104
- log(keys)
105
104
  switch_to_alert.send_keys(keys)
106
105
  end
107
106
 
108
107
  # Move back a single entry in the browser's history
109
108
  def back
110
- log
111
109
  driver.navigate.back
112
110
  end
113
111
 
114
112
  # Open a blank page
115
113
  def blank
116
- log
117
114
  open('about:blank')
118
115
  end
119
116
 
120
117
  # Close the current window, or the browser if no windows are left
121
118
  def close
122
- log
123
119
  driver.close
124
120
  end
125
121
 
@@ -127,27 +123,23 @@ class Rudra
127
123
  # @param [String] name the name of the cookie
128
124
  # @return [Hash, nil] the cookie, or nil if it wasn't found
129
125
  def cookie_named(name)
130
- log(name)
131
126
  driver.manage.cookie_named(name)
132
127
  end
133
128
 
134
129
  # Get the URL of the current page
135
130
  # @return (String) the URL of the current page
136
131
  def current_url
137
- log
138
132
  driver.current_url
139
133
  end
140
134
 
141
135
  # Delete all cookies
142
136
  def delete_all_cookies
143
- log
144
137
  driver.manage.delete_all_cookies
145
138
  end
146
139
 
147
140
  # Delete the cookie with the given name
148
141
  # @param [String] name the name of the cookie
149
142
  def delete_cookie(name)
150
- log(name)
151
143
  driver.manage.delete_cookie(name)
152
144
  end
153
145
 
@@ -159,7 +151,6 @@ class Rudra
159
151
  # @return [Selenium::WebDriver::Element, Integer, Float, Boolean, NilClass,
160
152
  # String, Array] the value returned from the script
161
153
  def execute_script(script, *args)
162
- log
163
154
  driver.execute_script(script, *args)
164
155
  end
165
156
 
@@ -168,8 +159,6 @@ class Rudra
168
159
  # identify the element or Selenium::WebDriver::Element
169
160
  # @return [Selenium::WebDriver::Element] the element found
170
161
  def find_element(locator)
171
- log(locator)
172
-
173
162
  return locator if locator.is_a?(Selenium::WebDriver::Element)
174
163
 
175
164
  element = nil
@@ -193,8 +182,6 @@ class Rudra
193
182
  # @param [String] locator the locator to identify the elements
194
183
  # @return [Array<Selenium::WebDriver::Element>] the elements found
195
184
  def find_elements(locator)
196
- log(locator)
197
-
198
185
  how, what = parse_locator(locator)
199
186
  driver.find_elements(how, what) ||
200
187
  abort("Failed to find elements: #{locator}")
@@ -202,32 +189,26 @@ class Rudra
202
189
 
203
190
  # Move forward a single entry in the browser's history
204
191
  def forward
205
- log
206
192
  driver.navigate.forward
207
193
  end
208
194
 
209
195
  # Make the current window full screen
210
196
  def full_screen
211
- log
212
197
  driver.manage.window.full_screen
213
198
  end
214
199
 
215
200
  # Quit the browser
216
201
  def quit
217
- log
218
202
  driver.quit
219
203
  end
220
204
 
221
205
  # Maximize the current window
222
206
  def maximize
223
- log
224
207
  driver.manage.window.maximize
225
208
  end
226
209
 
227
210
  # Maximize the current window to the size of the screen
228
211
  def maximize_to_screen
229
- log
230
-
231
212
  size = execute_script(%(
232
213
  return { width: window.screen.width, height: window.screen.height };
233
214
  ))
@@ -238,7 +219,6 @@ class Rudra
238
219
 
239
220
  # Minimize the current window
240
221
  def minimize
241
- log
242
222
  driver.manage.window.minimize
243
223
  end
244
224
 
@@ -246,14 +226,12 @@ class Rudra
246
226
  # @param [Integer] point_x the x coordinate
247
227
  # @param [Integer] point_y the y coordinate
248
228
  def move_window_to(point_x, point_y)
249
- log(point_x, point_y)
250
229
  driver.manage.window.move_to(point_x, point_y)
251
230
  end
252
231
 
253
232
  # Open a new tab
254
233
  # @return [String] the id of the new tab obtained from #window_handles
255
234
  def new_tab
256
- log
257
235
  execute_script('window.open();')
258
236
  window_handles.last
259
237
  end
@@ -261,7 +239,6 @@ class Rudra
261
239
  # Open a new window
262
240
  # @param [String] name the name of the window
263
241
  def new_window(name)
264
- log(name)
265
242
  execute_script(%(
266
243
  var w = Math.max(
267
244
  document.documentElement.clientWidth, window.innerWidth || 0
@@ -276,20 +253,17 @@ class Rudra
276
253
  # Open the specified URL in the browser
277
254
  # @param [String] url the URL of the page to open
278
255
  def open(url)
279
- log(url)
280
256
  driver.get(url)
281
257
  end
282
258
 
283
259
  # Get the source of the current page
284
260
  # @return (String) the source of the current page
285
261
  def page_source
286
- log
287
262
  driver.page_source
288
263
  end
289
264
 
290
265
  # Refresh the current pagef
291
266
  def refresh
292
- log
293
267
  driver.navigate.refresh
294
268
  end
295
269
 
@@ -297,55 +271,51 @@ class Rudra
297
271
  # @param [Integer] width the width of the window
298
272
  # @param [Integer] height the height of the window
299
273
  def resize_window_to(width, height)
300
- log(width, height)
301
274
  driver.manage.window.resize_to(width, height)
302
275
  end
303
276
 
304
- # Save a PNG screenshot to the given path
305
- # @param [String] png_path the path of PNG screenshot
306
- def save_screenshot(png_path)
307
- log(png_path)
277
+ # Save a PNG screenshot to file
278
+ # @param [String] filename the filename of PNG screenshot
279
+ def save_screenshot(filename)
280
+ mkdir(@screen_dir) unless Dir.exist?(@screen_dir)
308
281
  driver.save_screenshot(
309
- png_path.end_with?('.png') ? png_path : "#{png_path}.png"
282
+ File.join(
283
+ @screen_dir,
284
+ filename.end_with?('.png') ? filename : "#{filename}.png"
285
+ )
310
286
  )
311
287
  end
312
288
 
313
289
  # Switch to the currently active modal dialog
314
290
  def switch_to_alert
315
- log
316
291
  driver.switch_to.alert
317
292
  end
318
293
 
319
294
  # Select either the first frame on the page,
320
295
  # or the main document when a page contains iframes
321
296
  def switch_to_default_content
322
- log
323
297
  driver.switch_to.default_content
324
298
  end
325
299
 
326
300
  # Switch to the frame with the given id
327
301
  def switch_to_frame(id)
328
- log(id)
329
302
  driver.switch_to.frame(id)
330
303
  end
331
304
 
332
305
  # Switch to the parent frame
333
306
  def switch_to_parent_frame
334
- log
335
307
  driver.switch_to.parent_frame
336
308
  end
337
309
 
338
310
  # Switch to the given window handle
339
311
  # @param [String] id the window handle obtained through #window_handles
340
312
  def switch_to_window(id)
341
- log(id)
342
313
  driver.switch_to.window(id)
343
314
  end
344
315
 
345
316
  # Get the title of the current page
346
317
  # @return [String] the title of the current page
347
318
  def title
348
- log
349
319
  driver.title
350
320
  end
351
321
 
@@ -353,21 +323,25 @@ class Rudra
353
323
  # @param [Integer] seconds seconds before timed out
354
324
  # @return [Object] the result of the block
355
325
  def wait_for(seconds = timeout)
356
- log(seconds)
357
326
  Selenium::WebDriver::Wait.new(timeout: seconds).until { yield }
358
327
  end
359
328
 
329
+ # Wait until the element, identified by locator, is enabled
330
+ # @param [String, Selenium::WebDriver::Element] locator the locator to
331
+ # identify the element or Selenium::WebDriver::Element
332
+ def wait_for_enabled(locator)
333
+ wait_for { find_element(locator).enabled? }
334
+ end
335
+
360
336
  # Wait until the title of the page including the given string
361
337
  # @param [String] string the string to compare
362
338
  def wait_for_title(string)
363
- log(string)
364
339
  wait_for { title.downcase.include?(string.downcase) }
365
340
  end
366
341
 
367
342
  # Wait until the URL of the page including the given url
368
343
  # @param [String] url the URL to compare
369
344
  def wait_for_url(url)
370
- log(url)
371
345
  wait_for { current_url.include?(url) }
372
346
  end
373
347
 
@@ -375,28 +349,24 @@ class Rudra
375
349
  # @param [String, Selenium::WebDriver::Element] locator the locator to
376
350
  # identify the element or Selenium::WebDriver::Element
377
351
  def wait_for_visible(locator)
378
- log(locator)
379
352
  wait_for { find_element(locator).displayed? }
380
353
  end
381
354
 
382
355
  # Get the current window handle
383
356
  # @return [String] the id of the current window handle
384
357
  def window_handle
385
- log
386
358
  driver.window_handle
387
359
  end
388
360
 
389
361
  # Get the window handles of open browser windows
390
362
  # @return [Array<String>] the ids of window handles
391
363
  def window_handles
392
- log
393
364
  driver.window_handles
394
365
  end
395
366
 
396
367
  # Zoom the current page
397
368
  # @param [Float] scale the scale of zoom
398
369
  def zoom(scale)
399
- log(scale)
400
370
  execute_script(%(document.body.style.zoom = arguments[0];), scale)
401
371
  end
402
372
 
@@ -411,7 +381,6 @@ class Rudra
411
381
  # @param [String] attribute the name of the attribute
412
382
  # @return [String, nil] attribute value
413
383
  def attribute(locator, attribute)
414
- log(locator, attribute)
415
384
  find_element(locator).property(attribute)
416
385
  end
417
386
 
@@ -421,7 +390,6 @@ class Rudra
421
390
  # @param [String] attribute the name of the attribute
422
391
  # @return [Boolean] the result of the existence of the given attribute
423
392
  def attribute?(locator, attribute)
424
- log(locator, attribute)
425
393
  execute_script(%(
426
394
  return arguments[0].hasAttribute(arguments[1]);
427
395
  ), find_element(locator), attribute)
@@ -431,7 +399,6 @@ class Rudra
431
399
  # @param [String, Selenium::WebDriver::Element] locator the locator to
432
400
  # identify the element or Selenium::WebDriver::Element
433
401
  def blur(locator)
434
- log(locator)
435
402
  execute_script(
436
403
  'var element = arguments[0]; element.blur();',
437
404
  find_element(locator)
@@ -442,7 +409,6 @@ class Rudra
442
409
  # @param [String, Selenium::WebDriver::Element] locator the locator to
443
410
  # identify the element or Selenium::WebDriver::Element
444
411
  def clear(locator)
445
- log(locator)
446
412
  find_element(locator).clear
447
413
  end
448
414
 
@@ -450,7 +416,6 @@ class Rudra
450
416
  # @param [String, Selenium::WebDriver::Element] locator the locator to
451
417
  # identify the element or Selenium::WebDriver::Element
452
418
  def click(locator)
453
- log(locator)
454
419
  find_element(locator).click
455
420
  end
456
421
 
@@ -461,8 +426,6 @@ class Rudra
461
426
  # @option offset [Integer] :x (0) offset on x coordinate
462
427
  # @option offset [Integer] :y (0) offset on y coordinate
463
428
  def click_at(locator, offset = {})
464
- log(locator, offset)
465
-
466
429
  x = offset.fetch(:x, 0)
467
430
  y = offset.fetch(:y, 0)
468
431
 
@@ -479,7 +442,6 @@ class Rudra
479
442
  # identify the element or Selenium::WebDriver::Element
480
443
  # @param [String] property the longhand name of the property
481
444
  def css_value(locator, property)
482
- log(locator, property)
483
445
  find_element(locator).css_value(property)
484
446
  end
485
447
 
@@ -488,7 +450,6 @@ class Rudra
488
450
  # identify the element or Selenium::WebDriver::Element
489
451
  # @return [Boolean]
490
452
  def displayed?(locator)
491
- log(locator)
492
453
  find_element(locator).displayed?
493
454
  end
494
455
 
@@ -499,8 +460,6 @@ class Rudra
499
460
  # @option offset [Integer] :x (0) offset on x coordinate
500
461
  # @option offset [Integer] :y (0) offset on y coordinate
501
462
  def double_click(locator, offset = {})
502
- log(locator, offset)
503
-
504
463
  x = offset.fetch(:x, 0)
505
464
  y = offset.fetch(:y, 0)
506
465
 
@@ -517,7 +476,6 @@ class Rudra
517
476
  # @param [String] to_locator the locator to to move to and release
518
477
  # the mouse at
519
478
  def drag_and_drop(from_locator, to_locator)
520
- log(from_locator, to_locator)
521
479
  el1 = find_element(from_locator)
522
480
  el2 = find_element(to_locator)
523
481
 
@@ -530,7 +488,6 @@ class Rudra
530
488
  # @option offset [Integer] :x (0) offset on x coordinate
531
489
  # @option offset [Integer] :y (0) offset on y coordinate
532
490
  def drag_and_drop_by(source, offset = {})
533
- log(source, offset)
534
491
  element = find_element(source)
535
492
  x = offset.fetch(:x, 0)
536
493
  y = offset.fetch(:y, 0)
@@ -543,7 +500,6 @@ class Rudra
543
500
  # identify the element or Selenium::WebDriver::Element
544
501
  # @return [Boolean]
545
502
  def enabled?(locator)
546
- log(locator)
547
503
  find_element(locator).enabled?
548
504
  end
549
505
 
@@ -551,8 +507,6 @@ class Rudra
551
507
  # @param [String, Selenium::WebDriver::Element] locator the locator to
552
508
  # identify the element or Selenium::WebDriver::Element
553
509
  def focus(locator)
554
- log(locator)
555
-
556
510
  execute_script(
557
511
  'var element = arguments[0]; element.focus();',
558
512
  find_element(locator)
@@ -563,8 +517,6 @@ class Rudra
563
517
  # @param [String, Selenium::WebDriver::Element] locator the locator to
564
518
  # identify the element or Selenium::WebDriver::Element
565
519
  def hide(locator)
566
- log(locator)
567
-
568
520
  execute_script(%(
569
521
  arguments[0].style.display = 'none';
570
522
  ), find_element(locator))
@@ -574,8 +526,6 @@ class Rudra
574
526
  # @param [String, Selenium::WebDriver::Element] locator the locator to
575
527
  # identify the element or Selenium::WebDriver::Element
576
528
  def highlight(locator)
577
- log(locator)
578
-
579
529
  execute_script(%(
580
530
  arguments[0].style.backgroundColor = '#ff3';
581
531
  ), find_element(locator))
@@ -584,7 +534,6 @@ class Rudra
584
534
  # Set implicit_wait timeout
585
535
  # @param [Integer] seconds timeout for implicit_wait
586
536
  def implicit_wait(seconds)
587
- log(seconds)
588
537
  driver.manage.timeouts.implicit_wait = seconds
589
538
  end
590
539
 
@@ -592,7 +541,6 @@ class Rudra
592
541
  # @param [String, Selenium::WebDriver::Element] locator the locator to
593
542
  # identify the element or Selenium::WebDriver::Element
594
543
  def js_click(locator)
595
- log(locator)
596
544
  execute_script('arguments[0].click();', find_element(locator))
597
545
  end
598
546
 
@@ -601,7 +549,6 @@ class Rudra
601
549
  # identify the element or Selenium::WebDriver::Element
602
550
  # @return [Selenium::WebDriver::Point] the point of the given element
603
551
  def location(locator)
604
- log(locator)
605
552
  find_element(locator).location
606
553
  end
607
554
 
@@ -609,7 +556,6 @@ class Rudra
609
556
  # @param [Integer] right_by horizontal offset
610
557
  # @param [Integer] down_by vertical offset
611
558
  def move_by(right_by = 0, down_by = 0)
612
- log(right_by, down_by)
613
559
  action.move_by(right_by, down_by).perform
614
560
  end
615
561
 
@@ -620,8 +566,6 @@ class Rudra
620
566
  # @option offset [Integer] :x (0) offset on x coordinate
621
567
  # @option offset [Integer] :y (0) offset on y coordinate
622
568
  def move_to(locator, offset = {})
623
- log(locator, offset)
624
-
625
569
  x = offset.fetch(:x, 0)
626
570
  y = offset.fetch(:y, 0)
627
571
 
@@ -635,7 +579,6 @@ class Rudra
635
579
  # Set page_load timeout
636
580
  # @param [Integer] seconds timeout for page_load
637
581
  def page_load(seconds)
638
- log(seconds)
639
582
  driver.manage.timeouts.page_load = seconds
640
583
  end
641
584
 
@@ -645,7 +588,6 @@ class Rudra
645
588
  # identify the element or Selenium::WebDriver::Element
646
589
  # @return [Selenium::WebDriver::Rectangle] the retangle of the given element
647
590
  def rect(locator)
648
- log(locator)
649
591
  find_element(locator).rect
650
592
  end
651
593
 
@@ -655,7 +597,6 @@ class Rudra
655
597
  # identify the element or Selenium::WebDriver::Element
656
598
  # @param [String] attribute the name of the attribute
657
599
  def remove_attribute(locator, attribute)
658
- log(locator, attribute)
659
600
  execute_script(%(
660
601
  var element = arguments[0];
661
602
  var attributeName = arguments[1];
@@ -672,8 +613,6 @@ class Rudra
672
613
  # @option offset [Integer] :x (0) offset on x coordinate
673
614
  # @option offset [Integer] :y (0) offset on y coordinate
674
615
  def right_click(locator, offset = {})
675
- log(locator, offset)
676
-
677
616
  x = offset.fetch(:x, 0)
678
617
  y = offset.fetch(:y, 0)
679
618
 
@@ -684,7 +623,6 @@ class Rudra
684
623
  # Set script_timeout timeout
685
624
  # @param [Integer] seconds timeout for script_timeout
686
625
  def script_timeout(seconds)
687
- log(seconds)
688
626
  driver.manage.timeouts.script_timeout = seconds
689
627
  end
690
628
 
@@ -694,8 +632,6 @@ class Rudra
694
632
  # @param [Boolean] align_to true if aligned on top or
695
633
  # false if aligned at the bottom
696
634
  def scroll_into_view(locator, align_to = true)
697
- log(locator, align_to)
698
-
699
635
  execute_script(
700
636
  'arguments[0].scrollIntoView(arguments[1]);',
701
637
  find_element(locator),
@@ -707,7 +643,6 @@ class Rudra
707
643
  # @param [String, Selenium::WebDriver::Element] option_locator the locator to
708
644
  # identify the element or Selenium::WebDriver::Element
709
645
  def select(option_locator)
710
- log(option_locator)
711
646
  find_element(option_locator).click
712
647
  end
713
648
 
@@ -716,7 +651,6 @@ class Rudra
716
651
  # identify the element or Selenium::WebDriver::Element
717
652
  # @return [Boolean]
718
653
  def selected?(locator)
719
- log(locator)
720
654
  find_element(locator).selected?
721
655
  end
722
656
 
@@ -725,7 +659,6 @@ class Rudra
725
659
  # identify the element or Selenium::WebDriver::Element
726
660
  # @param [String, Symbol, Array] args keystrokes to send
727
661
  def send_keys(locator, *args)
728
- log(locator, *args)
729
662
  find_element(locator).send_keys(*args)
730
663
  end
731
664
 
@@ -735,7 +668,6 @@ class Rudra
735
668
  # @param [String] attribute the name of the attribute
736
669
  # @param [String] value the value of the attribute
737
670
  def set_attribute(locator, attribute, value)
738
- log(locator, attribute, value)
739
671
  execute_script(%(
740
672
  var element = arguments[0];
741
673
  var attribute = arguments[1];
@@ -748,7 +680,6 @@ class Rudra
748
680
  # @param [String, Selenium::WebDriver::Element] locator the locator to
749
681
  # identify the element or Selenium::WebDriver::Element
750
682
  def show(locator)
751
- log(locator)
752
683
  execute_script(%(
753
684
  arguments[0].style.display = '';
754
685
  ), find_element(locator))
@@ -759,7 +690,6 @@ class Rudra
759
690
  # identify the element or Selenium::WebDriver::Element
760
691
  # @return [Selenium::WebDriver::Dimension]
761
692
  def size(locator)
762
- log(locator)
763
693
  find_element(locator).size
764
694
  end
765
695
 
@@ -767,7 +697,6 @@ class Rudra
767
697
  # @param [String, Selenium::WebDriver::Element] locator the locator to
768
698
  # identify the element or Selenium::WebDriver::Element
769
699
  def submit(locator)
770
- log("- submit(#{locator})")
771
700
  find_element(locator).submit
772
701
  end
773
702
 
@@ -776,7 +705,6 @@ class Rudra
776
705
  # identify the element or Selenium::WebDriver::Element
777
706
  # @return [String] the tag name of the given element
778
707
  def tag_name(locator)
779
- log(locator)
780
708
  find_element(locator).tag_name
781
709
  end
782
710
 
@@ -785,7 +713,6 @@ class Rudra
785
713
  # identify the element or Selenium::WebDriver::Element
786
714
  # @return [String] the text content of the given element
787
715
  def text(locator)
788
- log(locator)
789
716
  find_element(locator).text
790
717
  end
791
718
 
@@ -794,7 +721,6 @@ class Rudra
794
721
  # identify the element or Selenium::WebDriver::Element
795
722
  # @param [String] event the event name
796
723
  def trigger(locator, event)
797
- log(locator, event)
798
724
  execute_script(%(
799
725
  var element = arguments[0];
800
726
  var eventName = arguments[1];
@@ -809,7 +735,6 @@ class Rudra
809
735
 
810
736
  # Clear all drawing
811
737
  def clear_drawings
812
- log
813
738
  execute_script(%(
814
739
  var elements = window.document.body.querySelectorAll('[id*="rudra_"]');
815
740
  for (var i = 0; i < elements.length; i++) {
@@ -827,8 +752,6 @@ class Rudra
827
752
  # or Selenium::WebDriver::Element where the arrow ends
828
753
  # @return [Selenium::WebDriver::Element] the arrow element
829
754
  def draw_arrow(from_locator, to_locator)
830
- log(from_locator, to_locator)
831
-
832
755
  id = random_id
833
756
 
834
757
  execute_script(%(
@@ -896,8 +819,6 @@ class Rudra
896
819
  # @param [String] color CSS style of backgroundColor
897
820
  # @return [Selenium::WebDriver::Element] the color fill element
898
821
  def draw_color_fill(locator, color = 'rgba(255,0,0,0.8)')
899
- log(locator, color)
900
-
901
822
  rectangle = rect(locator)
902
823
  id = random_id
903
824
 
@@ -935,8 +856,6 @@ class Rudra
935
856
  # @option options [Boolean] :draw_symbol (false) if to draw symbol
936
857
  # @return [Selenium::WebDriver::Element] the tooltip element
937
858
  def draw_flyover(locator, options = {})
938
- log(locator, options)
939
-
940
859
  attribute_name = options.fetch(:attribute, 'title')
941
860
  offset_x = options.fetch(:offset_x, 5)
942
861
  offset_y = options.fetch(:offset_y, 15)
@@ -1014,8 +933,6 @@ class Rudra
1014
933
  # @option padding [Integer] :left (5) left padding
1015
934
  # @return [Selenium::WebDriver::Element] the redmark element
1016
935
  def draw_redmark(locator, padding = {})
1017
- log(locator, padding)
1018
-
1019
936
  top = padding.fetch(:top, 5)
1020
937
  right = padding.fetch(:right, 5)
1021
938
  bottom = padding.fetch(:bottom, 5)
@@ -1052,8 +969,6 @@ class Rudra
1052
969
  # @option options [Integer] :offset_y (0) offset on y coordinate
1053
970
  # @return [Selenium::WebDriver::Element] the dropdown menu element
1054
971
  def draw_select(locator, options = {})
1055
- log(locator, options)
1056
-
1057
972
  offset_x = options.fetch(:offset_x, 0)
1058
973
  offset_y = options.fetch(:offset_y, 0)
1059
974
 
@@ -1114,8 +1029,6 @@ class Rudra
1114
1029
  # @option options [Integer] :right (20) CSS style of right
1115
1030
  # @return [Selenium::WebDriver::Element] the text element
1116
1031
  def draw_text(locator, text, options = {})
1117
- log(locator, text, options)
1118
-
1119
1032
  color = options.fetch(:color, '#f00')
1120
1033
  font_size = options.fetch(:font_size, 13)
1121
1034
  top = options.fetch(:top, 2)
@@ -1149,12 +1062,24 @@ class Rudra
1149
1062
  # Create directories, recursively, for the given dir
1150
1063
  # @param [String] dir the directories to create
1151
1064
  def mkdir(dir)
1152
- log(dir)
1153
1065
  FileUtils.mkdir_p(dir)
1154
1066
  end
1155
1067
 
1068
+ (instance_methods - superclass.instance_methods).map do |method_name|
1069
+ next if private_method_defined?(method_name) || ATTRIBUTES.include?(method_name)
1070
+
1071
+ original_method = instance_method(method_name)
1072
+
1073
+ define_method(method_name) do |*args, &block|
1074
+ log(method_name, *args)
1075
+ original_method.bind(self).call(*args, &block)
1076
+ end
1077
+ end
1078
+
1156
1079
  private
1157
1080
 
1081
+ attr_writer :main_label
1082
+
1158
1083
  def browser=(brw)
1159
1084
  unless BROWSERS.include?(brw)
1160
1085
  browsers = BROWSERS.map { |b| ":#{b}" }.join(', ')
@@ -1176,6 +1101,14 @@ class Rudra
1176
1101
  end
1177
1102
  end
1178
1103
 
1104
+ def headless=(mode)
1105
+ @headless = true?(mode)
1106
+ end
1107
+
1108
+ def screen_dir=(path)
1109
+ @screen_dir = File.join(path, @locale.to_s)
1110
+ end
1111
+
1179
1112
  def log_prefix=(prefix)
1180
1113
  @log_prefix = prefix.chomp
1181
1114
  end
@@ -1188,7 +1121,11 @@ class Rudra
1188
1121
  end
1189
1122
 
1190
1123
  def verbose=(mode)
1191
- @verbose = [1, true, '1', 'true'].include?(mode)
1124
+ @verbose = true?(mode)
1125
+ end
1126
+
1127
+ def true?(mode)
1128
+ [1, true, '1', 'true'].include?(mode)
1192
1129
  end
1193
1130
 
1194
1131
  def initialize_driver
@@ -1196,6 +1133,8 @@ class Rudra
1196
1133
  Selenium::WebDriver.for(:chrome, options: chrome_options)
1197
1134
  elsif browser == :firefox
1198
1135
  Selenium::WebDriver.for(:firefox, options: firefox_options)
1136
+ elsif browser == :ie
1137
+ Selenium::WebDriver.for(:ie, options: ie_options)
1199
1138
  else
1200
1139
  Selenium::WebDriver.for(:safari)
1201
1140
  end
@@ -1203,8 +1142,12 @@ class Rudra
1203
1142
 
1204
1143
  def chrome_options
1205
1144
  options = Selenium::WebDriver::Chrome::Options.new
1206
- options.add_argument('disable-infobars')
1207
- options.add_argument('disable-notifications')
1145
+ options.add_argument('--disable-notifications')
1146
+ options.add_argument('--headless') if headless
1147
+ options.add_option(
1148
+ 'excludeSwitches',
1149
+ %w[enable-automation enable-logging]
1150
+ )
1208
1151
  options.add_preference('intl.accept_languages', locale)
1209
1152
  options
1210
1153
  end
@@ -1212,6 +1155,17 @@ class Rudra
1212
1155
  def firefox_options
1213
1156
  options = Selenium::WebDriver::Firefox::Options.new
1214
1157
  options.add_preference('intl.accept_languages', locale)
1158
+ options.add_argument('--headless') if headless
1159
+ options
1160
+ end
1161
+
1162
+ def ie_options
1163
+ options = Selenium::WebDriver::IE::Options.new
1164
+ options.ensure_clean_session = true
1165
+ options.full_page_screenshot = true
1166
+ options.ignore_protected_mode_settings = true
1167
+ options.ignore_zoom_level = true
1168
+ options.native_events = false
1215
1169
  options
1216
1170
  end
1217
1171
 
@@ -1235,13 +1189,13 @@ class Rudra
1235
1189
  [how, what]
1236
1190
  end
1237
1191
 
1238
- def log(*args)
1239
- return unless @verbose && caller_locations(2, 1).first.label == '<main>'
1192
+ def log(method_name, *args)
1193
+ return unless @verbose && caller_locations(2, 1).first.label == @main_label
1240
1194
 
1241
- function = caller_locations(1, 1).first.label
1242
1195
  arguments = args.map(&:to_s).join(', ')
1196
+
1243
1197
  puts @log_prefix + (
1244
- arguments.empty? ? function : "#{function}(#{arguments})"
1198
+ arguments.empty? ? method_name.to_s : "#{method_name}(#{arguments})"
1245
1199
  )
1246
1200
  end
1247
1201
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rudra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-26 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.24
19
+ version: 0.9.25
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.24
26
+ version: 0.9.25
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: selenium-webdriver
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -48,24 +48,24 @@ dependencies:
48
48
  name: webdrivers
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: 4.2.0
54
51
  - - "~>"
55
52
  - !ruby/object:Gem::Version
56
- version: '4.2'
53
+ version: '4.4'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 4.4.1
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: 4.2.0
64
61
  - - "~>"
65
62
  - !ruby/object:Gem::Version
66
- version: '4.2'
63
+ version: '4.4'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 4.4.1
67
67
  description: Selenium IDE alternative using selenium-webdriver
68
- email: aaron@oobo.be
68
+ email: aaron@611b.com
69
69
  executables: []
70
70
  extensions: []
71
71
  extra_rdoc_files: []