rudra 1.0.9 → 1.0.14

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