rudra 1.0.5 → 1.0.6

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 +4 -4
  2. data/lib/rudra.rb +123 -92
  3. metadata +16 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d484ee7375f26e20fe77c0a98b2118cc20233735406b1becd80f516df6e1c643
4
- data.tar.gz: c51433cb3175890c782928e61d1194fee3b82fa1d36ec65d675e11c21ada5f97
3
+ metadata.gz: 6f3da5ea96d1321e14ee7fb023bb412387f78a79c1535c855025ec2a59c28499
4
+ data.tar.gz: a134bdf42ff39785a2cd59b739d3204cc8da4aa211efc8c31e5b19f8cb7b57c4
5
5
  SHA512:
6
- metadata.gz: 913236878e028057042b254f03a2ec61e6ac775918f92ad65328762b006ffd31e8e6407ab233d29bb163c903f6d41788f1d817355371f1ef413027f1d1732d08
7
- data.tar.gz: 55f2404b44aa3b74517c12612458a7086e2c2ec170ccf8617ca0d79f9e81e020b91aa3ed7baa9bafb4952fbf5db5e9a8d21575a33519db79042154ab5eeeb996
6
+ metadata.gz: 717abf0312e51703093d9f04245167788606c341d9214c195292fa082212cd366a4879ea998d5720ee4d907667543bfac03fb549c20c16cce22a8463d278eaff
7
+ data.tar.gz: eac45a3ab02d36332d694b889e279e094480f5a92b26d2892eb1becfdad6ad9c7f3eb7b9a6d263a3b5818dfb2e234f8c5489871fd7668a0136bd0769c1773c8c
data/lib/rudra.rb CHANGED
@@ -2,7 +2,6 @@ require 'selenium-webdriver'
2
2
  require 'webdrivers/chromedriver'
3
3
  require 'webdrivers/geckodriver'
4
4
 
5
- Webdrivers.install_dir = './webdrivers/'
6
5
  # Selenium::WebDriver::Chrome::Service.driver_path = './webdrivers/chromedriver'
7
6
  # Selenium::WebDriver::Firefox::Service.driver_path = './webdrivers/geckodriver'
8
7
 
@@ -11,9 +10,10 @@ Webdrivers.install_dir = './webdrivers/'
11
10
  # @attr_reader [Symbol] browser The chosen browser
12
11
  # @attr_reader [Selenium::WebDriver::Driver] driver The driver instance
13
12
  # of the chosen browser
13
+ # @attr_reader [String] install_dir The install directory of WebDrivers
14
14
  # @attr_reader [String] locale The browser locale
15
15
  # @attr_reader [Integer] timeout The driver timeout
16
- # @attr_writer [Boolean] verbose Verbose mode
16
+ # @attr_reader [Boolean] verbose Verbose mode
17
17
  class Rudra
18
18
  # Supported Browsers
19
19
  BROWSERS = %i[chrome firefox safari].freeze
@@ -24,24 +24,37 @@ class Rudra
24
24
  name partial_link_text tag_name xpath
25
25
  ].freeze
26
26
 
27
- attr_reader :browser, :driver, :locale, :timeout
28
- attr_writer :verbose
27
+ attr_reader :browser, :driver, :install_dir, :locale,
28
+ :log_prefix, :timeout, :verbose
29
29
 
30
30
  # Initialize an instance of Rudra
31
31
  # @param [Hash] options the options to initialize Rudra
32
32
  # @option options [Symbol] :browser (:chrome) the supported
33
33
  # browsers: :chrome, :firefox, :safari
34
+ # @option options [String] :install_dir ('./webdrivers/') the install
35
+ # directory of WebDrivers
34
36
  # @option options [Symbol] :locale (:en) the browser locale
37
+ # @option options [String] :log_prefix (' - ') log prefix
35
38
  # @option options [Integer] :timeout (30) implicit_wait timeout
36
39
  # @option options [Boolean] :verbose (true) verbose mode
37
40
  def initialize(options = {})
38
41
  self.browser = options.fetch(:browser, :chrome)
42
+ self.install_dir = options.fetch(:install_dir, './webdrivers/')
39
43
  self.locale = options.fetch(:locale, :en)
44
+ self.log_prefix = options.fetch(:log_prefix, ' - ')
45
+ self.verbose = options.fetch(:verbose, true)
40
46
 
41
47
  initialize_driver
42
48
 
43
49
  self.timeout = options.fetch(:timeout, 30)
44
- self.verbose = options.fetch(:verbose, true)
50
+
51
+ @verbose && (
52
+ puts %(
53
+ ============ Rudra ============
54
+ Browser: #{@browser}, Locale: #{@locale}
55
+ ============ Log ============
56
+ ).lines.map(&:strip).reject(&:empty?).join("\n")
57
+ )
45
58
  end
46
59
 
47
60
  #
@@ -51,14 +64,14 @@ class Rudra
51
64
  # Initialize ActionBuilder
52
65
  # @return [Selenium::WebDriver::ActionBuilder] ActionBuilder
53
66
  def action
54
- log('- action')
67
+ log
55
68
  driver.action
56
69
  end
57
70
 
58
71
  # Get the active element
59
72
  # @return [Selenium::WebDriver::Element] the active element
60
73
  def active_element
61
- log('- active_element')
74
+ log
62
75
  driver.switch_to.active_element
63
76
  end
64
77
 
@@ -70,43 +83,43 @@ class Rudra
70
83
  # @option opts [Boolean] :secure (false) a boolean
71
84
  # @option opts [Time, DateTime, Numeric, nil] :expires (nil) expiry date
72
85
  def add_cookie(opts = {})
73
- log("- add_cookie(#{opts})")
86
+ log(opts)
74
87
  driver.manage.add_cookie(opts)
75
88
  end
76
89
 
77
90
  # Accept an alert
78
91
  def alert_accept
79
- log('- alert_accept')
92
+ log
80
93
  switch_to_alert.accept
81
94
  end
82
95
 
83
96
  # Dismiss an alert
84
97
  def alert_dismiss
85
- log('- alert_dismiss')
98
+ log
86
99
  switch_to_alert.dismiss
87
100
  end
88
101
 
89
102
  # Send keys to an alert
90
103
  def alert_send_keys(keys)
91
- log("- alert_send_keys(#{keys})")
104
+ log(keys)
92
105
  switch_to_alert.send_keys(keys)
93
106
  end
94
107
 
95
108
  # Move back a single entry in the browser's history
96
109
  def back
97
- log('- back')
110
+ log
98
111
  driver.navigate.back
99
112
  end
100
113
 
101
114
  # Open a blank page
102
115
  def blank
103
- log('- blank')
116
+ log
104
117
  open('about:blank')
105
118
  end
106
119
 
107
120
  # Close the current window, or the browser if no windows are left
108
121
  def close
109
- log('- close')
122
+ log
110
123
  driver.close
111
124
  end
112
125
 
@@ -114,27 +127,27 @@ class Rudra
114
127
  # @param [String] name the name of the cookie
115
128
  # @return [Hash, nil] the cookie, or nil if it wasn't found
116
129
  def cookie_named(name)
117
- log("- cookie_named(#{name})")
130
+ log(name)
118
131
  driver.manage.cookie_named(name)
119
132
  end
120
133
 
121
134
  # Get the URL of the current page
122
135
  # @return (String) the URL of the current page
123
136
  def current_url
124
- log('- current_url')
137
+ log
125
138
  driver.current_url
126
139
  end
127
140
 
128
141
  # Delete all cookies
129
142
  def delete_all_cookies
130
- log('- delete_all_cookies')
143
+ log
131
144
  driver.manage.delete_all_cookies
132
145
  end
133
146
 
134
147
  # Delete the cookie with the given name
135
148
  # @param [String] name the name of the cookie
136
149
  def delete_cookie(name)
137
- log("- delete_cookie(#{name})")
150
+ log(name)
138
151
  driver.manage.delete_cookie(name)
139
152
  end
140
153
 
@@ -146,7 +159,7 @@ class Rudra
146
159
  # @return [Selenium::WebDriver::Element, Integer, Float, Boolean, NilClass,
147
160
  # String, Array] the value returned from the script
148
161
  def execute_script(script, *args)
149
- log('- execute_script')
162
+ log
150
163
  driver.execute_script(script, *args)
151
164
  end
152
165
 
@@ -155,7 +168,7 @@ class Rudra
155
168
  # identify the element or Selenium::WebDriver::Element
156
169
  # @return [Selenium::WebDriver::Element] the element found
157
170
  def find_element(locator)
158
- log("- find_element(#{locator})")
171
+ log(locator)
159
172
 
160
173
  return locator if locator.is_a?(Selenium::WebDriver::Element)
161
174
 
@@ -180,7 +193,7 @@ class Rudra
180
193
  # @param [String] locator the locator to identify the elements
181
194
  # @return [Array<Selenium::WebDriver::Element>] the elements found
182
195
  def find_elements(locator)
183
- log("- find_elements(#{locator})")
196
+ log(locator)
184
197
 
185
198
  how, what = parse_locator(locator)
186
199
  driver.find_elements(how, what) ||
@@ -189,31 +202,31 @@ class Rudra
189
202
 
190
203
  # Move forward a single entry in the browser's history
191
204
  def forward
192
- log('- forward')
205
+ log
193
206
  driver.navigate.forward
194
207
  end
195
208
 
196
209
  # Make the current window full screen
197
210
  def full_screen
198
- log('- full_screen')
211
+ log
199
212
  driver.manage.window.full_screen
200
213
  end
201
214
 
202
215
  # Quit the browser
203
216
  def quit
204
- log('- quit')
217
+ log
205
218
  driver.quit
206
219
  end
207
220
 
208
221
  # Maximize the current window
209
222
  def maximize
210
- log('- maximize')
223
+ log
211
224
  driver.manage.window.maximize
212
225
  end
213
226
 
214
227
  # Maximize the current window to the size of the screen
215
228
  def maximize_to_screen
216
- log('- maximize_to_screen')
229
+ log
217
230
 
218
231
  size = execute_script(%(
219
232
  return { width: window.screen.width, height: window.screen.height };
@@ -225,7 +238,7 @@ class Rudra
225
238
 
226
239
  # Minimize the current window
227
240
  def minimize
228
- log('- minimize')
241
+ log
229
242
  driver.manage.window.minimize
230
243
  end
231
244
 
@@ -233,14 +246,14 @@ class Rudra
233
246
  # @param [Integer] point_x the x coordinate
234
247
  # @param [Integer] point_y the y coordinate
235
248
  def move_window_to(point_x, point_y)
236
- log("- move_window_to(#{point_x}, #{point_y})")
249
+ log(point_x, point_y)
237
250
  driver.manage.window.move_to(point_x, point_y)
238
251
  end
239
252
 
240
253
  # Open a new tab
241
254
  # @return [String] the id of the new tab obtained from #window_handles
242
255
  def new_tab
243
- log('- new_tab')
256
+ log
244
257
  execute_script('window.open();')
245
258
  window_handles.last
246
259
  end
@@ -248,7 +261,7 @@ class Rudra
248
261
  # Open a new window
249
262
  # @param [String] name the name of the window
250
263
  def new_window(name)
251
- log("- new_window(#{name})")
264
+ log(name)
252
265
  execute_script(%(
253
266
  var w = Math.max(
254
267
  document.documentElement.clientWidth, window.innerWidth || 0
@@ -263,20 +276,20 @@ class Rudra
263
276
  # Open the specified URL in the browser
264
277
  # @param [String] url the URL of the page to open
265
278
  def open(url)
266
- log("- open(#{url})")
279
+ log(url)
267
280
  driver.get(url)
268
281
  end
269
282
 
270
283
  # Get the source of the current page
271
284
  # @return (String) the source of the current page
272
285
  def page_source
273
- log('- page_source')
286
+ log
274
287
  driver.page_source
275
288
  end
276
289
 
277
290
  # Refresh the current pagef
278
291
  def refresh
279
- log('- refresh')
292
+ log
280
293
  driver.navigate.refresh
281
294
  end
282
295
 
@@ -284,14 +297,14 @@ class Rudra
284
297
  # @param [Integer] width the width of the window
285
298
  # @param [Integer] height the height of the window
286
299
  def resize_window_to(width, height)
287
- log("- resize_window_to(#{width}, #{height})")
300
+ log(width, height)
288
301
  driver.manage.window.resize_to(width, height)
289
302
  end
290
303
 
291
304
  # Save a PNG screenshot to the given path
292
305
  # @param [String] png_path the path of PNG screenshot
293
306
  def save_screenshot(png_path)
294
- log("- save_screenshot(#{png_path})")
307
+ log(png_path)
295
308
  driver.save_screenshot(
296
309
  png_path.end_with?('.png') ? png_path : "#{png_path}.png"
297
310
  )
@@ -299,40 +312,40 @@ class Rudra
299
312
 
300
313
  # Switch to the currently active modal dialog
301
314
  def switch_to_alert
302
- log('- switch_to_alert')
315
+ log
303
316
  driver.switch_to.alert
304
317
  end
305
318
 
306
319
  # Select either the first frame on the page,
307
320
  # or the main document when a page contains iframes
308
321
  def switch_to_default_content
309
- log('- switch_to_default_content')
322
+ log
310
323
  driver.switch_to.default_content
311
324
  end
312
325
 
313
326
  # Switch to the frame with the given id
314
327
  def switch_to_frame(id)
315
- log("- switch_to_frame(#{id})")
328
+ log(id)
316
329
  driver.switch_to.frame(id)
317
330
  end
318
331
 
319
332
  # Switch to the parent frame
320
333
  def switch_to_parent_frame
321
- log('- switch_to_parent_frame')
334
+ log
322
335
  driver.switch_to.parent_frame
323
336
  end
324
337
 
325
338
  # Switch to the given window handle
326
339
  # @param [String] id the window handle obtained through #window_handles
327
340
  def switch_to_window(id)
328
- log("- switch_to_window(#{id})")
341
+ log(id)
329
342
  driver.switch_to.window(id)
330
343
  end
331
344
 
332
345
  # Get the title of the current page
333
346
  # @return [String] the title of the current page
334
347
  def title
335
- log('- title')
348
+ log
336
349
  driver.title
337
350
  end
338
351
 
@@ -340,21 +353,21 @@ class Rudra
340
353
  # @param [Integer] seconds seconds before timed out
341
354
  # @return [Object] the result of the block
342
355
  def wait_for(seconds = timeout)
343
- log("- wait_for(#{seconds})")
356
+ log(seconds)
344
357
  Selenium::WebDriver::Wait.new(timeout: seconds).until { yield }
345
358
  end
346
359
 
347
360
  # Wait until the title of the page including the given string
348
361
  # @param [String] string the string to compare
349
362
  def wait_for_title(string)
350
- log("- wait_for_title(#{string})")
363
+ log(string)
351
364
  wait_for { title.downcase.include?(string.downcase) }
352
365
  end
353
366
 
354
367
  # Wait until the URL of the page including the given url
355
368
  # @param [String] url the URL to compare
356
369
  def wait_for_url(url)
357
- log("- wait_for_url(#{url})")
370
+ log(url)
358
371
  wait_for { current_url.include?(url) }
359
372
  end
360
373
 
@@ -362,28 +375,28 @@ class Rudra
362
375
  # @param [String, Selenium::WebDriver::Element] locator the locator to
363
376
  # identify the element or Selenium::WebDriver::Element
364
377
  def wait_for_visible(locator)
365
- log("- wait_for_visible(#{locator})")
378
+ log(locator)
366
379
  wait_for { find_element(locator).displayed? }
367
380
  end
368
381
 
369
382
  # Get the current window handle
370
383
  # @return [String] the id of the current window handle
371
384
  def window_handle
372
- log('- window_handle')
385
+ log
373
386
  driver.window_handle
374
387
  end
375
388
 
376
389
  # Get the window handles of open browser windows
377
390
  # @return [Array<String>] the ids of window handles
378
391
  def window_handles
379
- log('- window_handles')
392
+ log
380
393
  driver.window_handles
381
394
  end
382
395
 
383
396
  # Zoom the current page
384
397
  # @param [Float] scale the scale of zoom
385
398
  def zoom(scale)
386
- log("- zoom(#{scale})")
399
+ log(scale)
387
400
  execute_script(%(document.body.style.zoom = arguments[0];), scale)
388
401
  end
389
402
 
@@ -398,7 +411,7 @@ class Rudra
398
411
  # @param [String] attribute the name of the attribute
399
412
  # @return [String, nil] attribute value
400
413
  def attribute(locator, attribute)
401
- log("- attribute(#{locator}, #{attribute})")
414
+ log(locator, attribute)
402
415
  find_element(locator).property(attribute)
403
416
  end
404
417
 
@@ -408,7 +421,7 @@ class Rudra
408
421
  # @param [String] attribute the name of the attribute
409
422
  # @return [Boolean] the result of the existence of the given attribute
410
423
  def attribute?(locator, attribute)
411
- log("- attribute?(#{locator}, #{attribute})")
424
+ log(locator, attribute)
412
425
  execute_script(%(
413
426
  return arguments[0].hasAttribute(arguments[1]);
414
427
  ), find_element(locator), attribute)
@@ -418,7 +431,7 @@ class Rudra
418
431
  # @param [String, Selenium::WebDriver::Element] locator the locator to
419
432
  # identify the element or Selenium::WebDriver::Element
420
433
  def blur(locator)
421
- log("- blur(#{locator})")
434
+ log(locator)
422
435
  execute_script(
423
436
  'var element = arguments[0]; element.blur();',
424
437
  find_element(locator)
@@ -429,7 +442,7 @@ class Rudra
429
442
  # @param [String, Selenium::WebDriver::Element] locator the locator to
430
443
  # identify the element or Selenium::WebDriver::Element
431
444
  def clear(locator)
432
- log("- clear(#{locator})")
445
+ log(locator)
433
446
  find_element(locator).clear
434
447
  end
435
448
 
@@ -437,7 +450,7 @@ class Rudra
437
450
  # @param [String, Selenium::WebDriver::Element] locator the locator to
438
451
  # identify the element or Selenium::WebDriver::Element
439
452
  def click(locator)
440
- log("- click(#{locator})")
453
+ log(locator)
441
454
  find_element(locator).click
442
455
  end
443
456
 
@@ -448,7 +461,7 @@ class Rudra
448
461
  # @option offset [Integer] :x (0) offset on x coordinate
449
462
  # @option offset [Integer] :y (0) offset on y coordinate
450
463
  def click_at(locator, offset = {})
451
- log("- click_at(#{locator}, #{offset})")
464
+ log(locator, offset)
452
465
 
453
466
  x = offset.fetch(:x, 0)
454
467
  y = offset.fetch(:y, 0)
@@ -466,7 +479,7 @@ class Rudra
466
479
  # identify the element or Selenium::WebDriver::Element
467
480
  # @return [Boolean]
468
481
  def displayed?(locator)
469
- log("- displayed?(#{locator})")
482
+ log(locator)
470
483
  find_element(locator).displayed?
471
484
  end
472
485
 
@@ -477,7 +490,7 @@ class Rudra
477
490
  # @option offset [Integer] :x (0) offset on x coordinate
478
491
  # @option offset [Integer] :y (0) offset on y coordinate
479
492
  def double_click(locator, offset = {})
480
- log("- double_click(#{locator}, #{offset})")
493
+ log(locator, offset)
481
494
 
482
495
  x = offset.fetch(:x, 0)
483
496
  y = offset.fetch(:y, 0)
@@ -495,7 +508,7 @@ class Rudra
495
508
  # @param [String] to_locator the locator to to move to and release
496
509
  # the mouse at
497
510
  def drag_and_drop(from_locator, to_locator)
498
- log("- drag_and_drop(#{from_locator}, #{to_locator})")
511
+ log(from_locator, to_locator)
499
512
  el1 = find_element(from_locator)
500
513
  el2 = find_element(to_locator)
501
514
 
@@ -508,7 +521,7 @@ class Rudra
508
521
  # @option offset [Integer] :x (0) offset on x coordinate
509
522
  # @option offset [Integer] :y (0) offset on y coordinate
510
523
  def drag_and_drop_by(source, offset = {})
511
- log("- drag_and_drop_by(#{source}, #{offset})")
524
+ log(source, offset)
512
525
  element = find_element(source)
513
526
  x = offset.fetch(:x, 0)
514
527
  y = offset.fetch(:y, 0)
@@ -521,7 +534,7 @@ class Rudra
521
534
  # identify the element or Selenium::WebDriver::Element
522
535
  # @return [Boolean]
523
536
  def enabled?(locator)
524
- log("- enabled?(#{locator})")
537
+ log(locator)
525
538
  find_element(locator).enabled?
526
539
  end
527
540
 
@@ -529,7 +542,7 @@ class Rudra
529
542
  # @param [String, Selenium::WebDriver::Element] locator the locator to
530
543
  # identify the element or Selenium::WebDriver::Element
531
544
  def focus(locator)
532
- log("- focus(#{locator})")
545
+ log(locator)
533
546
 
534
547
  execute_script(
535
548
  'var element = arguments[0]; element.focus();',
@@ -541,7 +554,7 @@ class Rudra
541
554
  # @param [String, Selenium::WebDriver::Element] locator the locator to
542
555
  # identify the element or Selenium::WebDriver::Element
543
556
  def hide(locator)
544
- log("- hide(#{locator})")
557
+ log(locator)
545
558
 
546
559
  execute_script(%(
547
560
  arguments[0].style.display = 'none';
@@ -552,7 +565,7 @@ class Rudra
552
565
  # @param [String, Selenium::WebDriver::Element] locator the locator to
553
566
  # identify the element or Selenium::WebDriver::Element
554
567
  def highlight(locator)
555
- log("- highlight(#{locator})")
568
+ log(locator)
556
569
 
557
570
  execute_script(%(
558
571
  arguments[0].style.backgroundColor = '#ff3';
@@ -562,7 +575,7 @@ class Rudra
562
575
  # Set implicit_wait timeout
563
576
  # @param [Integer] seconds timeout for implicit_wait
564
577
  def implicit_wait(seconds)
565
- log("- implicit_wait(#{seconds})")
578
+ log(seconds)
566
579
  driver.manage.timeouts.implicit_wait = seconds
567
580
  end
568
581
 
@@ -570,7 +583,7 @@ class Rudra
570
583
  # @param [String, Selenium::WebDriver::Element] locator the locator to
571
584
  # identify the element or Selenium::WebDriver::Element
572
585
  def js_click(locator)
573
- log("- js_click(#{locator})")
586
+ log(locator)
574
587
  execute_script('arguments[0].click();', find_element(locator))
575
588
  end
576
589
 
@@ -579,7 +592,7 @@ class Rudra
579
592
  # identify the element or Selenium::WebDriver::Element
580
593
  # @return [Selenium::WebDriver::Point] the point of the given element
581
594
  def location(locator)
582
- log("- location(#{locator})")
595
+ log(locator)
583
596
  find_element(locator).location
584
597
  end
585
598
 
@@ -587,7 +600,7 @@ class Rudra
587
600
  # @param [Integer] right_by horizontal offset
588
601
  # @param [Integer] down_by vertical offset
589
602
  def move_by(right_by = 0, down_by = 0)
590
- log("- move_by(#{right_by}, #{down_by})")
603
+ log(right_by, down_by)
591
604
  action.move_by(right_by, down_by).perform
592
605
  end
593
606
 
@@ -598,7 +611,7 @@ class Rudra
598
611
  # @option offset [Integer] :x (0) offset on x coordinate
599
612
  # @option offset [Integer] :y (0) offset on y coordinate
600
613
  def move_to(locator, offset = {})
601
- log("- move_to(#{locator}, #{offset})")
614
+ log(locator, offset)
602
615
 
603
616
  x = offset.fetch(:x, 0)
604
617
  y = offset.fetch(:y, 0)
@@ -613,7 +626,7 @@ class Rudra
613
626
  # Set page_load timeout
614
627
  # @param [Integer] seconds timeout for page_load
615
628
  def page_load(seconds)
616
- log("- page_load(#{seconds})")
629
+ log(seconds)
617
630
  driver.manage.timeouts.page_load = seconds
618
631
  end
619
632
 
@@ -623,7 +636,7 @@ class Rudra
623
636
  # identify the element or Selenium::WebDriver::Element
624
637
  # @return [Selenium::WebDriver::Rectangle] the retangle of the given element
625
638
  def rect(locator)
626
- log("- rect(#{locator})")
639
+ log(locator)
627
640
  find_element(locator).rect
628
641
  end
629
642
 
@@ -633,7 +646,7 @@ class Rudra
633
646
  # identify the element or Selenium::WebDriver::Element
634
647
  # @param [String] attribute the name of the attribute
635
648
  def remove_attribute(locator, attribute)
636
- log("- remove_attribute(#{locator}, #{attribute})")
649
+ log(locator, attribute)
637
650
  execute_script(%(
638
651
  var element = arguments[0];
639
652
  var attributeName = arguments[1];
@@ -650,7 +663,7 @@ class Rudra
650
663
  # @option offset [Integer] :x (0) offset on x coordinate
651
664
  # @option offset [Integer] :y (0) offset on y coordinate
652
665
  def right_click(locator, offset = {})
653
- log("- right_click(#{locator}, #{offset})")
666
+ log(locator, offset)
654
667
 
655
668
  x = offset.fetch(:x, 0)
656
669
  y = offset.fetch(:y, 0)
@@ -662,7 +675,7 @@ class Rudra
662
675
  # Set script_timeout timeout
663
676
  # @param [Integer] seconds timeout for script_timeout
664
677
  def script_timeout(seconds)
665
- log("- script_timeout(#{seconds})")
678
+ log(seconds)
666
679
  driver.manage.timeouts.script_timeout = seconds
667
680
  end
668
681
 
@@ -672,7 +685,7 @@ class Rudra
672
685
  # @param [Boolean] align_to true if aligned on top or
673
686
  # false if aligned at the bottom
674
687
  def scroll_into_view(locator, align_to = true)
675
- log("- scroll_into_view(#{locator}, #{align_to})")
688
+ log(locator, align_to)
676
689
 
677
690
  execute_script(
678
691
  'arguments[0].scrollIntoView(arguments[1]);',
@@ -685,7 +698,7 @@ class Rudra
685
698
  # @param [String, Selenium::WebDriver::Element] option_locator the locator to
686
699
  # identify the element or Selenium::WebDriver::Element
687
700
  def select(option_locator)
688
- log("- select(#{option_locator})")
701
+ log(option_locator)
689
702
  find_element(option_locator).click
690
703
  end
691
704
 
@@ -694,7 +707,7 @@ class Rudra
694
707
  # identify the element or Selenium::WebDriver::Element
695
708
  # @return [Boolean]
696
709
  def selected?(locator)
697
- log("- selected?(#{locator})")
710
+ log(locator)
698
711
  find_element(locator).selected?
699
712
  end
700
713
 
@@ -703,7 +716,7 @@ class Rudra
703
716
  # identify the element or Selenium::WebDriver::Element
704
717
  # @param [String, Symbol, Array] args keystrokes to send
705
718
  def send_keys(locator, *args)
706
- log("- send_keys(#{locator}, #{args})")
719
+ log(locator, *args)
707
720
  find_element(locator).send_keys(*args)
708
721
  end
709
722
 
@@ -713,7 +726,7 @@ class Rudra
713
726
  # @param [String] attribute the name of the attribute
714
727
  # @param [String] value the value of the attribute
715
728
  def set_attribute(locator, attribute, value)
716
- log("- set_attribute(#{locator}, #{attribute}, #{value})")
729
+ log(locator, attribute, value)
717
730
  executeScript(%(
718
731
  var element = arguments[0];
719
732
  var attribute = arguments[1];
@@ -726,7 +739,7 @@ class Rudra
726
739
  # @param [String, Selenium::WebDriver::Element] locator the locator to
727
740
  # identify the element or Selenium::WebDriver::Element
728
741
  def show(locator)
729
- log("- show(#{locator})")
742
+ log(locator)
730
743
  execute_script(%(
731
744
  arguments[0].style.display = '';
732
745
  ), find_element(locator))
@@ -737,7 +750,7 @@ class Rudra
737
750
  # identify the element or Selenium::WebDriver::Element
738
751
  # @return [Selenium::WebDriver::Dimension]
739
752
  def size(locator)
740
- log("- size(#{locator})")
753
+ log(locator)
741
754
  find_element(locator).size
742
755
  end
743
756
 
@@ -754,7 +767,7 @@ class Rudra
754
767
  # identify the element or Selenium::WebDriver::Element
755
768
  # @return [String] the tag name of the given element
756
769
  def tag_name(locator)
757
- log("- tag_name(#{locator})")
770
+ log(locator)
758
771
  find_element(locator).tag_name
759
772
  end
760
773
 
@@ -763,7 +776,7 @@ class Rudra
763
776
  # identify the element or Selenium::WebDriver::Element
764
777
  # @return [String] the text content of the given element
765
778
  def text(locator)
766
- log("- text(#{locator})")
779
+ log(locator)
767
780
  find_element(locator).text
768
781
  end
769
782
 
@@ -772,7 +785,7 @@ class Rudra
772
785
  # identify the element or Selenium::WebDriver::Element
773
786
  # @param [String] event the event name
774
787
  def trigger(locator, event)
775
- log("- trigger(#{locator}, #{event})")
788
+ log(locator, event)
776
789
  execute_script(%(
777
790
  var element = arguments[0];
778
791
  var eventName = arguments[1];
@@ -787,7 +800,7 @@ class Rudra
787
800
 
788
801
  # Clear all drawing
789
802
  def clear_drawings
790
- log('- clear_drawings')
803
+ log
791
804
  execute_script(%(
792
805
  var elements = window.document.body.querySelectorAll('[id*="rudra_"]');
793
806
  for (var i = 0; i < elements.length; i++) {
@@ -805,7 +818,7 @@ class Rudra
805
818
  # or Selenium::WebDriver::Element where the arrow ends
806
819
  # @return [Selenium::WebDriver::Element] the arrow element
807
820
  def draw_arrow(from_locator, to_locator)
808
- log("- draw_arrow(#{from_locator}, #{to_locator})")
821
+ log(from_locator, to_locator)
809
822
 
810
823
  id = random_id
811
824
 
@@ -874,7 +887,7 @@ class Rudra
874
887
  # @param [String] color CSS style of backgroundColor
875
888
  # @return [Selenium::WebDriver::Element] the color fill element
876
889
  def draw_color_fill(locator, color = 'rgba(255,0,0,0.8)')
877
- log("- draw_color_fill(#{locator}, #{color})")
890
+ log(locator, color)
878
891
 
879
892
  rectangle = rect(locator)
880
893
  id = random_id
@@ -913,7 +926,7 @@ class Rudra
913
926
  # @option options [Boolean] :draw_symbol (false) if to draw symbol
914
927
  # @return [Selenium::WebDriver::Element] the tooltip element
915
928
  def draw_flyover(locator, options = {})
916
- log("- draw_flyover(#{locator}, #{options})")
929
+ log(locator, options)
917
930
 
918
931
  attribute_name = options.fetch(:attribute, 'title')
919
932
  offset_x = options.fetch(:offset_x, 5)
@@ -992,7 +1005,7 @@ class Rudra
992
1005
  # @option padding [Integer] :left (5) left padding
993
1006
  # @return [Selenium::WebDriver::Element] the redmark element
994
1007
  def draw_redmark(locator, padding = {})
995
- log("- draw_redmark(#{locator}, #{padding})")
1008
+ log(locator, padding)
996
1009
 
997
1010
  top = padding.fetch(:top, 5)
998
1011
  right = padding.fetch(:right, 5)
@@ -1030,7 +1043,7 @@ class Rudra
1030
1043
  # @option options [Integer] :offset_y (0) offset on y coordinate
1031
1044
  # @return [Selenium::WebDriver::Element] the dropdown menu element
1032
1045
  def draw_select(locator, options = {})
1033
- log("- draw_select(#{locator}, #{options})")
1046
+ log(locator, options)
1034
1047
 
1035
1048
  offset_x = options.fetch(:offset_x, 0)
1036
1049
  offset_y = options.fetch(:offset_y, 0)
@@ -1092,7 +1105,7 @@ class Rudra
1092
1105
  # @option options [Integer] :right (20) CSS style of right
1093
1106
  # @return [Selenium::WebDriver::Element] the text element
1094
1107
  def draw_text(locator, text, options = {})
1095
- log("- draw_text(#{locator}, #{text}, #{options})")
1108
+ log(locator, text, options)
1096
1109
 
1097
1110
  color = options.fetch(:color, '#f00')
1098
1111
  font_size = options.fetch(:font_size, 13)
@@ -1127,7 +1140,7 @@ class Rudra
1127
1140
  # Create directories, recursively, for the given dir
1128
1141
  # @param [String] dir the directories to create
1129
1142
  def mkdir(dir)
1130
- log("- mkdir(#{dir})")
1143
+ log(dir)
1131
1144
  FileUtils.mkdir_p(dir)
1132
1145
  end
1133
1146
 
@@ -1142,6 +1155,10 @@ class Rudra
1142
1155
  @browser = brw
1143
1156
  end
1144
1157
 
1158
+ def install_dir=(path)
1159
+ Webdrivers.install_dir = @install_dir = path
1160
+ end
1161
+
1145
1162
  def locale=(loc)
1146
1163
  @locale = if browser == :firefox
1147
1164
  loc.to_s.sub('_', '-').gsub(/(-[a-zA-Z]{2})$/, &:downcase)
@@ -1150,6 +1167,10 @@ class Rudra
1150
1167
  end
1151
1168
  end
1152
1169
 
1170
+ def log_prefix=(prefix)
1171
+ @log_prefix = prefix.chomp
1172
+ end
1173
+
1153
1174
  def timeout=(seconds)
1154
1175
  implicit_wait(seconds)
1155
1176
  page_load(seconds)
@@ -1157,6 +1178,10 @@ class Rudra
1157
1178
  @timeout = seconds
1158
1179
  end
1159
1180
 
1181
+ def verbose=(mode)
1182
+ @verbose = [1, true, '1', 'true'].include?(mode)
1183
+ end
1184
+
1160
1185
  def initialize_driver
1161
1186
  @driver = if browser == :chrome
1162
1187
  Selenium::WebDriver.for(:chrome, options: chrome_options)
@@ -1201,8 +1226,14 @@ class Rudra
1201
1226
  [how, what]
1202
1227
  end
1203
1228
 
1204
- def log(message)
1205
- puts message if @verbose && caller(2..2).first[/`([^']*)'/, 1] == '<main>'
1229
+ def log(*args)
1230
+ return unless @verbose && caller_locations(2, 1).first.label == '<main>'
1231
+
1232
+ function = caller_locations(1, 1).first.label
1233
+ arguments = args.map(&:to_s).join(', ')
1234
+ puts @log_prefix + (
1235
+ arguments.empty? ? function : "#{function}(#{arguments})"
1236
+ )
1206
1237
  end
1207
1238
 
1208
1239
  def random_id(length = 8)
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.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-07 00:00:00.000000000 Z
11
+ date: 2019-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -29,6 +29,9 @@ dependencies:
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.142'
34
+ - - ">="
32
35
  - !ruby/object:Gem::Version
33
36
  version: 3.142.3
34
37
  type: :runtime
@@ -36,22 +39,31 @@ dependencies:
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '3.142'
44
+ - - ">="
39
45
  - !ruby/object:Gem::Version
40
46
  version: 3.142.3
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: webdrivers
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - "~>"
51
+ - - ">="
46
52
  - !ruby/object:Gem::Version
47
53
  version: 4.1.0
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '4.1'
48
57
  type: :runtime
49
58
  prerelease: false
50
59
  version_requirements: !ruby/object:Gem::Requirement
51
60
  requirements:
52
- - - "~>"
61
+ - - ">="
53
62
  - !ruby/object:Gem::Version
54
63
  version: 4.1.0
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '4.1'
55
67
  description: Selenium IDE alternative using selenium-webdriver
56
68
  email: aaron@611b.com
57
69
  executables: []