rudra 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rudra.rb +93 -44
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80b5c7e46548e01a83ab8c8be4ca81cc409ca9f1f234dbc8db44ce826bb2fa3c
4
- data.tar.gz: 584f2d9666937c1e644baf16d6988f41d78714bc80808c43a3a32e5b31968a50
3
+ metadata.gz: d484ee7375f26e20fe77c0a98b2118cc20233735406b1becd80f516df6e1c643
4
+ data.tar.gz: c51433cb3175890c782928e61d1194fee3b82fa1d36ec65d675e11c21ada5f97
5
5
  SHA512:
6
- metadata.gz: cf790ff40424a147a557f43009969858ce7748b72e6a8fb0e102408b00bdc2777c2cf32095219af16c441dabc27c9b0824a7ccd12894914543b6d8038f383e0c
7
- data.tar.gz: 205775b7873d7eab81d1845069f09d962f655ddab941b9915701d19a236767b038a5e38ae7f5601c829c9a9539867fd7528ced699078386a5f79871c5f828b0a
6
+ metadata.gz: 913236878e028057042b254f03a2ec61e6ac775918f92ad65328762b006ffd31e8e6407ab233d29bb163c903f6d41788f1d817355371f1ef413027f1d1732d08
7
+ data.tar.gz: 55f2404b44aa3b74517c12612458a7086e2c2ec170ccf8617ca0d79f9e81e020b91aa3ed7baa9bafb4952fbf5db5e9a8d21575a33519db79042154ab5eeeb996
data/lib/rudra.rb CHANGED
@@ -51,12 +51,14 @@ class Rudra
51
51
  # Initialize ActionBuilder
52
52
  # @return [Selenium::WebDriver::ActionBuilder] ActionBuilder
53
53
  def action
54
+ log('- action')
54
55
  driver.action
55
56
  end
56
57
 
57
58
  # Get the active element
58
59
  # @return [Selenium::WebDriver::Element] the active element
59
60
  def active_element
61
+ log('- active_element')
60
62
  driver.switch_to.active_element
61
63
  end
62
64
 
@@ -68,39 +70,43 @@ class Rudra
68
70
  # @option opts [Boolean] :secure (false) a boolean
69
71
  # @option opts [Time, DateTime, Numeric, nil] :expires (nil) expiry date
70
72
  def add_cookie(opts = {})
73
+ log("- add_cookie(#{opts})")
71
74
  driver.manage.add_cookie(opts)
72
75
  end
73
76
 
74
77
  # Accept an alert
75
78
  def alert_accept
79
+ log('- alert_accept')
76
80
  switch_to_alert.accept
77
81
  end
78
82
 
79
83
  # Dismiss an alert
80
84
  def alert_dismiss
85
+ log('- alert_dismiss')
81
86
  switch_to_alert.dismiss
82
87
  end
83
88
 
84
89
  # Send keys to an alert
85
90
  def alert_send_keys(keys)
91
+ log("- alert_send_keys(#{keys})")
86
92
  switch_to_alert.send_keys(keys)
87
93
  end
88
94
 
89
95
  # Move back a single entry in the browser's history
90
96
  def back
91
- log('- back') if @verbose
97
+ log('- back')
92
98
  driver.navigate.back
93
99
  end
94
100
 
95
101
  # Open a blank page
96
102
  def blank
97
- log('- blank') if @verbose
103
+ log('- blank')
98
104
  open('about:blank')
99
105
  end
100
106
 
101
107
  # Close the current window, or the browser if no windows are left
102
108
  def close
103
- log('- close') if @verbose
109
+ log('- close')
104
110
  driver.close
105
111
  end
106
112
 
@@ -108,23 +114,27 @@ class Rudra
108
114
  # @param [String] name the name of the cookie
109
115
  # @return [Hash, nil] the cookie, or nil if it wasn't found
110
116
  def cookie_named(name)
117
+ log("- cookie_named(#{name})")
111
118
  driver.manage.cookie_named(name)
112
119
  end
113
120
 
114
121
  # Get the URL of the current page
115
122
  # @return (String) the URL of the current page
116
123
  def current_url
124
+ log('- current_url')
117
125
  driver.current_url
118
126
  end
119
127
 
120
128
  # Delete all cookies
121
129
  def delete_all_cookies
130
+ log('- delete_all_cookies')
122
131
  driver.manage.delete_all_cookies
123
132
  end
124
133
 
125
134
  # Delete the cookie with the given name
126
135
  # @param [String] name the name of the cookie
127
136
  def delete_cookie(name)
137
+ log("- delete_cookie(#{name})")
128
138
  driver.manage.delete_cookie(name)
129
139
  end
130
140
 
@@ -136,6 +146,7 @@ class Rudra
136
146
  # @return [Selenium::WebDriver::Element, Integer, Float, Boolean, NilClass,
137
147
  # String, Array] the value returned from the script
138
148
  def execute_script(script, *args)
149
+ log('- execute_script')
139
150
  driver.execute_script(script, *args)
140
151
  end
141
152
 
@@ -144,6 +155,8 @@ class Rudra
144
155
  # identify the element or Selenium::WebDriver::Element
145
156
  # @return [Selenium::WebDriver::Element] the element found
146
157
  def find_element(locator)
158
+ log("- find_element(#{locator})")
159
+
147
160
  return locator if locator.is_a?(Selenium::WebDriver::Element)
148
161
 
149
162
  element = nil
@@ -167,6 +180,8 @@ class Rudra
167
180
  # @param [String] locator the locator to identify the elements
168
181
  # @return [Array<Selenium::WebDriver::Element>] the elements found
169
182
  def find_elements(locator)
183
+ log("- find_elements(#{locator})")
184
+
170
185
  how, what = parse_locator(locator)
171
186
  driver.find_elements(how, what) ||
172
187
  abort("Failed to find elements: #{locator}")
@@ -174,37 +189,31 @@ class Rudra
174
189
 
175
190
  # Move forward a single entry in the browser's history
176
191
  def forward
177
- log('- forward') if @verbose
192
+ log('- forward')
178
193
  driver.navigate.forward
179
194
  end
180
195
 
181
196
  # Make the current window full screen
182
197
  def full_screen
183
- log('- full_screen') if @verbose
198
+ log('- full_screen')
184
199
  driver.manage.window.full_screen
185
200
  end
186
201
 
187
202
  # Quit the browser
188
203
  def quit
189
- log('- quit') if @verbose
204
+ log('- quit')
190
205
  driver.quit
191
206
  end
192
207
 
193
- # Print message
194
- # @param [String] message the message to print
195
- def log(message)
196
- puts message
197
- end
198
-
199
208
  # Maximize the current window
200
209
  def maximize
201
- log('- maximize') if @verbose
210
+ log('- maximize')
202
211
  driver.manage.window.maximize
203
212
  end
204
213
 
205
214
  # Maximize the current window to the size of the screen
206
215
  def maximize_to_screen
207
- log('- maximize_to_screen') if @verbose
216
+ log('- maximize_to_screen')
208
217
 
209
218
  size = execute_script(%(
210
219
  return { width: window.screen.width, height: window.screen.height };
@@ -216,7 +225,7 @@ class Rudra
216
225
 
217
226
  # Minimize the current window
218
227
  def minimize
219
- log('- minimize') if @verbose
228
+ log('- minimize')
220
229
  driver.manage.window.minimize
221
230
  end
222
231
 
@@ -224,12 +233,14 @@ class Rudra
224
233
  # @param [Integer] point_x the x coordinate
225
234
  # @param [Integer] point_y the y coordinate
226
235
  def move_window_to(point_x, point_y)
236
+ log("- move_window_to(#{point_x}, #{point_y})")
227
237
  driver.manage.window.move_to(point_x, point_y)
228
238
  end
229
239
 
230
240
  # Open a new tab
231
241
  # @return [String] the id of the new tab obtained from #window_handles
232
242
  def new_tab
243
+ log('- new_tab')
233
244
  execute_script('window.open();')
234
245
  window_handles.last
235
246
  end
@@ -237,6 +248,7 @@ class Rudra
237
248
  # Open a new window
238
249
  # @param [String] name the name of the window
239
250
  def new_window(name)
251
+ log("- new_window(#{name})")
240
252
  execute_script(%(
241
253
  var w = Math.max(
242
254
  document.documentElement.clientWidth, window.innerWidth || 0
@@ -251,19 +263,20 @@ class Rudra
251
263
  # Open the specified URL in the browser
252
264
  # @param [String] url the URL of the page to open
253
265
  def open(url)
254
- log("- open(#{url})") if @verbose
266
+ log("- open(#{url})")
255
267
  driver.get(url)
256
268
  end
257
269
 
258
270
  # Get the source of the current page
259
271
  # @return (String) the source of the current page
260
272
  def page_source
273
+ log('- page_source')
261
274
  driver.page_source
262
275
  end
263
276
 
264
277
  # Refresh the current pagef
265
278
  def refresh
266
- log('- refresh') if @verbose
279
+ log('- refresh')
267
280
  driver.navigate.refresh
268
281
  end
269
282
 
@@ -271,13 +284,14 @@ class Rudra
271
284
  # @param [Integer] width the width of the window
272
285
  # @param [Integer] height the height of the window
273
286
  def resize_window_to(width, height)
287
+ log("- resize_window_to(#{width}, #{height})")
274
288
  driver.manage.window.resize_to(width, height)
275
289
  end
276
290
 
277
291
  # Save a PNG screenshot to the given path
278
292
  # @param [String] png_path the path of PNG screenshot
279
293
  def save_screenshot(png_path)
280
- log("- save_screenshot(#{png_path})") if @verbose
294
+ log("- save_screenshot(#{png_path})")
281
295
  driver.save_screenshot(
282
296
  png_path.end_with?('.png') ? png_path : "#{png_path}.png"
283
297
  )
@@ -285,34 +299,40 @@ class Rudra
285
299
 
286
300
  # Switch to the currently active modal dialog
287
301
  def switch_to_alert
302
+ log('- switch_to_alert')
288
303
  driver.switch_to.alert
289
304
  end
290
305
 
291
306
  # Select either the first frame on the page,
292
307
  # or the main document when a page contains iframes
293
308
  def switch_to_default_content
309
+ log('- switch_to_default_content')
294
310
  driver.switch_to.default_content
295
311
  end
296
312
 
297
313
  # Switch to the frame with the given id
298
314
  def switch_to_frame(id)
315
+ log("- switch_to_frame(#{id})")
299
316
  driver.switch_to.frame(id)
300
317
  end
301
318
 
302
319
  # Switch to the parent frame
303
320
  def switch_to_parent_frame
321
+ log('- switch_to_parent_frame')
304
322
  driver.switch_to.parent_frame
305
323
  end
306
324
 
307
325
  # Switch to the given window handle
308
326
  # @param [String] id the window handle obtained through #window_handles
309
327
  def switch_to_window(id)
328
+ log("- switch_to_window(#{id})")
310
329
  driver.switch_to.window(id)
311
330
  end
312
331
 
313
332
  # Get the title of the current page
314
333
  # @return [String] the title of the current page
315
334
  def title
335
+ log('- title')
316
336
  driver.title
317
337
  end
318
338
 
@@ -320,18 +340,21 @@ class Rudra
320
340
  # @param [Integer] seconds seconds before timed out
321
341
  # @return [Object] the result of the block
322
342
  def wait_for(seconds = timeout)
343
+ log("- wait_for(#{seconds})")
323
344
  Selenium::WebDriver::Wait.new(timeout: seconds).until { yield }
324
345
  end
325
346
 
326
347
  # Wait until the title of the page including the given string
327
348
  # @param [String] string the string to compare
328
349
  def wait_for_title(string)
350
+ log("- wait_for_title(#{string})")
329
351
  wait_for { title.downcase.include?(string.downcase) }
330
352
  end
331
353
 
332
354
  # Wait until the URL of the page including the given url
333
355
  # @param [String] url the URL to compare
334
356
  def wait_for_url(url)
357
+ log("- wait_for_url(#{url})")
335
358
  wait_for { current_url.include?(url) }
336
359
  end
337
360
 
@@ -339,25 +362,28 @@ class Rudra
339
362
  # @param [String, Selenium::WebDriver::Element] locator the locator to
340
363
  # identify the element or Selenium::WebDriver::Element
341
364
  def wait_for_visible(locator)
365
+ log("- wait_for_visible(#{locator})")
342
366
  wait_for { find_element(locator).displayed? }
343
367
  end
344
368
 
345
369
  # Get the current window handle
346
370
  # @return [String] the id of the current window handle
347
371
  def window_handle
372
+ log('- window_handle')
348
373
  driver.window_handle
349
374
  end
350
375
 
351
376
  # Get the window handles of open browser windows
352
377
  # @return [Array<String>] the ids of window handles
353
378
  def window_handles
379
+ log('- window_handles')
354
380
  driver.window_handles
355
381
  end
356
382
 
357
383
  # Zoom the current page
358
384
  # @param [Float] scale the scale of zoom
359
385
  def zoom(scale)
360
- log("- zoom(#{scale})") if @verbose
386
+ log("- zoom(#{scale})")
361
387
  execute_script(%(document.body.style.zoom = arguments[0];), scale)
362
388
  end
363
389
 
@@ -372,6 +398,7 @@ class Rudra
372
398
  # @param [String] attribute the name of the attribute
373
399
  # @return [String, nil] attribute value
374
400
  def attribute(locator, attribute)
401
+ log("- attribute(#{locator}, #{attribute})")
375
402
  find_element(locator).property(attribute)
376
403
  end
377
404
 
@@ -381,6 +408,7 @@ class Rudra
381
408
  # @param [String] attribute the name of the attribute
382
409
  # @return [Boolean] the result of the existence of the given attribute
383
410
  def attribute?(locator, attribute)
411
+ log("- attribute?(#{locator}, #{attribute})")
384
412
  execute_script(%(
385
413
  return arguments[0].hasAttribute(arguments[1]);
386
414
  ), find_element(locator), attribute)
@@ -390,7 +418,7 @@ class Rudra
390
418
  # @param [String, Selenium::WebDriver::Element] locator the locator to
391
419
  # identify the element or Selenium::WebDriver::Element
392
420
  def blur(locator)
393
- log("- blur(#{locator})") if @verbose && locator.is_a?(String)
421
+ log("- blur(#{locator})")
394
422
  execute_script(
395
423
  'var element = arguments[0]; element.blur();',
396
424
  find_element(locator)
@@ -401,7 +429,7 @@ class Rudra
401
429
  # @param [String, Selenium::WebDriver::Element] locator the locator to
402
430
  # identify the element or Selenium::WebDriver::Element
403
431
  def clear(locator)
404
- log("- clear(#{locator})") if @verbose && locator.is_a?(String)
432
+ log("- clear(#{locator})")
405
433
  find_element(locator).clear
406
434
  end
407
435
 
@@ -409,7 +437,7 @@ class Rudra
409
437
  # @param [String, Selenium::WebDriver::Element] locator the locator to
410
438
  # identify the element or Selenium::WebDriver::Element
411
439
  def click(locator)
412
- log("- click(#{locator})") if @verbose && locator.is_a?(String)
440
+ log("- click(#{locator})")
413
441
  find_element(locator).click
414
442
  end
415
443
 
@@ -420,7 +448,7 @@ class Rudra
420
448
  # @option offset [Integer] :x (0) offset on x coordinate
421
449
  # @option offset [Integer] :y (0) offset on y coordinate
422
450
  def click_at(locator, offset = {})
423
- log("- click_at(#{locator})") if @verbose && locator.is_a?(String)
451
+ log("- click_at(#{locator}, #{offset})")
424
452
 
425
453
  x = offset.fetch(:x, 0)
426
454
  y = offset.fetch(:y, 0)
@@ -438,6 +466,7 @@ class Rudra
438
466
  # identify the element or Selenium::WebDriver::Element
439
467
  # @return [Boolean]
440
468
  def displayed?(locator)
469
+ log("- displayed?(#{locator})")
441
470
  find_element(locator).displayed?
442
471
  end
443
472
 
@@ -448,7 +477,7 @@ class Rudra
448
477
  # @option offset [Integer] :x (0) offset on x coordinate
449
478
  # @option offset [Integer] :y (0) offset on y coordinate
450
479
  def double_click(locator, offset = {})
451
- log("- double_click(#{locator})") if @verbose && locator.is_a?(String)
480
+ log("- double_click(#{locator}, #{offset})")
452
481
 
453
482
  x = offset.fetch(:x, 0)
454
483
  y = offset.fetch(:y, 0)
@@ -466,6 +495,7 @@ class Rudra
466
495
  # @param [String] to_locator the locator to to move to and release
467
496
  # the mouse at
468
497
  def drag_and_drop(from_locator, to_locator)
498
+ log("- drag_and_drop(#{from_locator}, #{to_locator})")
469
499
  el1 = find_element(from_locator)
470
500
  el2 = find_element(to_locator)
471
501
 
@@ -478,6 +508,7 @@ class Rudra
478
508
  # @option offset [Integer] :x (0) offset on x coordinate
479
509
  # @option offset [Integer] :y (0) offset on y coordinate
480
510
  def drag_and_drop_by(source, offset = {})
511
+ log("- drag_and_drop_by(#{source}, #{offset})")
481
512
  element = find_element(source)
482
513
  x = offset.fetch(:x, 0)
483
514
  y = offset.fetch(:y, 0)
@@ -490,6 +521,7 @@ class Rudra
490
521
  # identify the element or Selenium::WebDriver::Element
491
522
  # @return [Boolean]
492
523
  def enabled?(locator)
524
+ log("- enabled?(#{locator})")
493
525
  find_element(locator).enabled?
494
526
  end
495
527
 
@@ -497,7 +529,7 @@ class Rudra
497
529
  # @param [String, Selenium::WebDriver::Element] locator the locator to
498
530
  # identify the element or Selenium::WebDriver::Element
499
531
  def focus(locator)
500
- log("- focus(#{locator})") if @verbose && locator.is_a?(String)
532
+ log("- focus(#{locator})")
501
533
 
502
534
  execute_script(
503
535
  'var element = arguments[0]; element.focus();',
@@ -509,7 +541,7 @@ class Rudra
509
541
  # @param [String, Selenium::WebDriver::Element] locator the locator to
510
542
  # identify the element or Selenium::WebDriver::Element
511
543
  def hide(locator)
512
- log("- hide(#{locator})") if @verbose && locator.is_a?(String)
544
+ log("- hide(#{locator})")
513
545
 
514
546
  execute_script(%(
515
547
  arguments[0].style.display = 'none';
@@ -520,7 +552,7 @@ class Rudra
520
552
  # @param [String, Selenium::WebDriver::Element] locator the locator to
521
553
  # identify the element or Selenium::WebDriver::Element
522
554
  def highlight(locator)
523
- log("- highlight(#{locator})") if @verbose && locator.is_a?(String)
555
+ log("- highlight(#{locator})")
524
556
 
525
557
  execute_script(%(
526
558
  arguments[0].style.backgroundColor = '#ff3';
@@ -530,6 +562,7 @@ class Rudra
530
562
  # Set implicit_wait timeout
531
563
  # @param [Integer] seconds timeout for implicit_wait
532
564
  def implicit_wait(seconds)
565
+ log("- implicit_wait(#{seconds})")
533
566
  driver.manage.timeouts.implicit_wait = seconds
534
567
  end
535
568
 
@@ -537,7 +570,7 @@ class Rudra
537
570
  # @param [String, Selenium::WebDriver::Element] locator the locator to
538
571
  # identify the element or Selenium::WebDriver::Element
539
572
  def js_click(locator)
540
- log("- js_click(#{locator})") if @verbose && locator.is_a?(String)
573
+ log("- js_click(#{locator})")
541
574
  execute_script('arguments[0].click();', find_element(locator))
542
575
  end
543
576
 
@@ -546,6 +579,7 @@ class Rudra
546
579
  # identify the element or Selenium::WebDriver::Element
547
580
  # @return [Selenium::WebDriver::Point] the point of the given element
548
581
  def location(locator)
582
+ log("- location(#{locator})")
549
583
  find_element(locator).location
550
584
  end
551
585
 
@@ -553,6 +587,7 @@ class Rudra
553
587
  # @param [Integer] right_by horizontal offset
554
588
  # @param [Integer] down_by vertical offset
555
589
  def move_by(right_by = 0, down_by = 0)
590
+ log("- move_by(#{right_by}, #{down_by})")
556
591
  action.move_by(right_by, down_by).perform
557
592
  end
558
593
 
@@ -563,7 +598,7 @@ class Rudra
563
598
  # @option offset [Integer] :x (0) offset on x coordinate
564
599
  # @option offset [Integer] :y (0) offset on y coordinate
565
600
  def move_to(locator, offset = {})
566
- log("- move_to(#{locator})") if @verbose && locator.is_a?(String)
601
+ log("- move_to(#{locator}, #{offset})")
567
602
 
568
603
  x = offset.fetch(:x, 0)
569
604
  y = offset.fetch(:y, 0)
@@ -578,6 +613,7 @@ class Rudra
578
613
  # Set page_load timeout
579
614
  # @param [Integer] seconds timeout for page_load
580
615
  def page_load(seconds)
616
+ log("- page_load(#{seconds})")
581
617
  driver.manage.timeouts.page_load = seconds
582
618
  end
583
619
 
@@ -587,6 +623,7 @@ class Rudra
587
623
  # identify the element or Selenium::WebDriver::Element
588
624
  # @return [Selenium::WebDriver::Rectangle] the retangle of the given element
589
625
  def rect(locator)
626
+ log("- rect(#{locator})")
590
627
  find_element(locator).rect
591
628
  end
592
629
 
@@ -596,6 +633,7 @@ class Rudra
596
633
  # identify the element or Selenium::WebDriver::Element
597
634
  # @param [String] attribute the name of the attribute
598
635
  def remove_attribute(locator, attribute)
636
+ log("- remove_attribute(#{locator}, #{attribute})")
599
637
  execute_script(%(
600
638
  var element = arguments[0];
601
639
  var attributeName = arguments[1];
@@ -612,7 +650,7 @@ class Rudra
612
650
  # @option offset [Integer] :x (0) offset on x coordinate
613
651
  # @option offset [Integer] :y (0) offset on y coordinate
614
652
  def right_click(locator, offset = {})
615
- log("- right_click(#{locator})") if @verbose && locator.is_a?(String)
653
+ log("- right_click(#{locator}, #{offset})")
616
654
 
617
655
  x = offset.fetch(:x, 0)
618
656
  y = offset.fetch(:y, 0)
@@ -624,6 +662,7 @@ class Rudra
624
662
  # Set script_timeout timeout
625
663
  # @param [Integer] seconds timeout for script_timeout
626
664
  def script_timeout(seconds)
665
+ log("- script_timeout(#{seconds})")
627
666
  driver.manage.timeouts.script_timeout = seconds
628
667
  end
629
668
 
@@ -633,7 +672,7 @@ class Rudra
633
672
  # @param [Boolean] align_to true if aligned on top or
634
673
  # false if aligned at the bottom
635
674
  def scroll_into_view(locator, align_to = true)
636
- log("- scroll_into_view(#{locator})") if @verbose && locator.is_a?(String)
675
+ log("- scroll_into_view(#{locator}, #{align_to})")
637
676
 
638
677
  execute_script(
639
678
  'arguments[0].scrollIntoView(arguments[1]);',
@@ -646,9 +685,7 @@ class Rudra
646
685
  # @param [String, Selenium::WebDriver::Element] option_locator the locator to
647
686
  # identify the element or Selenium::WebDriver::Element
648
687
  def select(option_locator)
649
- if @verbose && option_locator.is_a?(String)
650
- log("- select(#{option_locator})")
651
- end
688
+ log("- select(#{option_locator})")
652
689
  find_element(option_locator).click
653
690
  end
654
691
 
@@ -657,6 +694,7 @@ class Rudra
657
694
  # identify the element or Selenium::WebDriver::Element
658
695
  # @return [Boolean]
659
696
  def selected?(locator)
697
+ log("- selected?(#{locator})")
660
698
  find_element(locator).selected?
661
699
  end
662
700
 
@@ -665,7 +703,7 @@ class Rudra
665
703
  # identify the element or Selenium::WebDriver::Element
666
704
  # @param [String, Symbol, Array] args keystrokes to send
667
705
  def send_keys(locator, *args)
668
- log("- send_keys(#{locator})") if @verbose && locator.is_a?(String)
706
+ log("- send_keys(#{locator}, #{args})")
669
707
  find_element(locator).send_keys(*args)
670
708
  end
671
709
 
@@ -675,6 +713,7 @@ class Rudra
675
713
  # @param [String] attribute the name of the attribute
676
714
  # @param [String] value the value of the attribute
677
715
  def set_attribute(locator, attribute, value)
716
+ log("- set_attribute(#{locator}, #{attribute}, #{value})")
678
717
  executeScript(%(
679
718
  var element = arguments[0];
680
719
  var attribute = arguments[1];
@@ -687,7 +726,7 @@ class Rudra
687
726
  # @param [String, Selenium::WebDriver::Element] locator the locator to
688
727
  # identify the element or Selenium::WebDriver::Element
689
728
  def show(locator)
690
- log("- show(#{locator})") if @verbose && locator.is_a?(String)
729
+ log("- show(#{locator})")
691
730
  execute_script(%(
692
731
  arguments[0].style.display = '';
693
732
  ), find_element(locator))
@@ -698,6 +737,7 @@ class Rudra
698
737
  # identify the element or Selenium::WebDriver::Element
699
738
  # @return [Selenium::WebDriver::Dimension]
700
739
  def size(locator)
740
+ log("- size(#{locator})")
701
741
  find_element(locator).size
702
742
  end
703
743
 
@@ -705,7 +745,7 @@ class Rudra
705
745
  # @param [String, Selenium::WebDriver::Element] locator the locator to
706
746
  # identify the element or Selenium::WebDriver::Element
707
747
  def submit(locator)
708
- log("- submit(#{locator})") if @verbose && locator.is_a?(String)
748
+ log("- submit(#{locator})")
709
749
  find_element(locator).submit
710
750
  end
711
751
 
@@ -714,6 +754,7 @@ class Rudra
714
754
  # identify the element or Selenium::WebDriver::Element
715
755
  # @return [String] the tag name of the given element
716
756
  def tag_name(locator)
757
+ log("- tag_name(#{locator})")
717
758
  find_element(locator).tag_name
718
759
  end
719
760
 
@@ -722,6 +763,7 @@ class Rudra
722
763
  # identify the element or Selenium::WebDriver::Element
723
764
  # @return [String] the text content of the given element
724
765
  def text(locator)
766
+ log("- text(#{locator})")
725
767
  find_element(locator).text
726
768
  end
727
769
 
@@ -730,7 +772,7 @@ class Rudra
730
772
  # identify the element or Selenium::WebDriver::Element
731
773
  # @param [String] event the event name
732
774
  def trigger(locator, event)
733
- log("- trigger(#{locator})") if @verbose && locator.is_a?(String)
775
+ log("- trigger(#{locator}, #{event})")
734
776
  execute_script(%(
735
777
  var element = arguments[0];
736
778
  var eventName = arguments[1];
@@ -745,7 +787,7 @@ class Rudra
745
787
 
746
788
  # Clear all drawing
747
789
  def clear_drawings
748
- log('- clear_drawings') if @verbose
790
+ log('- clear_drawings')
749
791
  execute_script(%(
750
792
  var elements = window.document.body.querySelectorAll('[id*="rudra_"]');
751
793
  for (var i = 0; i < elements.length; i++) {
@@ -763,6 +805,8 @@ class Rudra
763
805
  # or Selenium::WebDriver::Element where the arrow ends
764
806
  # @return [Selenium::WebDriver::Element] the arrow element
765
807
  def draw_arrow(from_locator, to_locator)
808
+ log("- draw_arrow(#{from_locator}, #{to_locator})")
809
+
766
810
  id = random_id
767
811
 
768
812
  execute_script(%(
@@ -830,7 +874,7 @@ class Rudra
830
874
  # @param [String] color CSS style of backgroundColor
831
875
  # @return [Selenium::WebDriver::Element] the color fill element
832
876
  def draw_color_fill(locator, color = 'rgba(255,0,0,0.8)')
833
- log("- draw_color_fill(#{locator})") if @verbose && locator.is_a?(String)
877
+ log("- draw_color_fill(#{locator}, #{color})")
834
878
 
835
879
  rectangle = rect(locator)
836
880
  id = random_id
@@ -869,7 +913,7 @@ class Rudra
869
913
  # @option options [Boolean] :draw_symbol (false) if to draw symbol
870
914
  # @return [Selenium::WebDriver::Element] the tooltip element
871
915
  def draw_flyover(locator, options = {})
872
- log("- draw_flyover(#{locator})") if @verbose && locator.is_a?(String)
916
+ log("- draw_flyover(#{locator}, #{options})")
873
917
 
874
918
  attribute_name = options.fetch(:attribute, 'title')
875
919
  offset_x = options.fetch(:offset_x, 5)
@@ -948,7 +992,7 @@ class Rudra
948
992
  # @option padding [Integer] :left (5) left padding
949
993
  # @return [Selenium::WebDriver::Element] the redmark element
950
994
  def draw_redmark(locator, padding = {})
951
- log("- draw_redmark(#{locator})") if @verbose && locator.is_a?(String)
995
+ log("- draw_redmark(#{locator}, #{padding})")
952
996
 
953
997
  top = padding.fetch(:top, 5)
954
998
  right = padding.fetch(:right, 5)
@@ -986,7 +1030,7 @@ class Rudra
986
1030
  # @option options [Integer] :offset_y (0) offset on y coordinate
987
1031
  # @return [Selenium::WebDriver::Element] the dropdown menu element
988
1032
  def draw_select(locator, options = {})
989
- log("- draw_select(#{locator})") if @verbose && locator.is_a?(String)
1033
+ log("- draw_select(#{locator}, #{options})")
990
1034
 
991
1035
  offset_x = options.fetch(:offset_x, 0)
992
1036
  offset_y = options.fetch(:offset_y, 0)
@@ -1048,7 +1092,7 @@ class Rudra
1048
1092
  # @option options [Integer] :right (20) CSS style of right
1049
1093
  # @return [Selenium::WebDriver::Element] the text element
1050
1094
  def draw_text(locator, text, options = {})
1051
- log("- draw_text(#{locator})") if @verbose && locator.is_a?(String)
1095
+ log("- draw_text(#{locator}, #{text}, #{options})")
1052
1096
 
1053
1097
  color = options.fetch(:color, '#f00')
1054
1098
  font_size = options.fetch(:font_size, 13)
@@ -1083,6 +1127,7 @@ class Rudra
1083
1127
  # Create directories, recursively, for the given dir
1084
1128
  # @param [String] dir the directories to create
1085
1129
  def mkdir(dir)
1130
+ log("- mkdir(#{dir})")
1086
1131
  FileUtils.mkdir_p(dir)
1087
1132
  end
1088
1133
 
@@ -1156,6 +1201,10 @@ class Rudra
1156
1201
  [how, what]
1157
1202
  end
1158
1203
 
1204
+ def log(message)
1205
+ puts message if @verbose && caller(2..2).first[/`([^']*)'/, 1] == '<main>'
1206
+ end
1207
+
1159
1208
  def random_id(length = 8)
1160
1209
  charset = [(0..9), ('a'..'z')].flat_map(&:to_a)
1161
1210
  id = Array.new(length) { charset.sample }.join
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.4
4
+ version: 1.0.5
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-06-30 00:00:00.000000000 Z
11
+ date: 2019-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 4.0.1
47
+ version: 4.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 4.0.1
54
+ version: 4.1.0
55
55
  description: Selenium IDE alternative using selenium-webdriver
56
56
  email: aaron@611b.com
57
57
  executables: []