rudra 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rudra.rb +231 -56
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fb6b46567ff821faf5058a1163e67de3a9149136cec110ee69ddf5ad602d7f4
|
4
|
+
data.tar.gz: e412407e9f8bcb6ba939442d8a34d4ddef2a935a2c34473635696bf47dbbcb33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6387910a2d5b11839881c06b46af46bb2952257ae3a16db1b3a183a248039ed10bf1dbf257e0614479301ea5cc08a07599265254e7541579b201fb9f613dcd28
|
7
|
+
data.tar.gz: 286190866ddc06a7b4f226c5aaedc2b45aed199ca49cf11fb3c9c696b4c8a0bd55a9e6f1c7cf8dc8b328dc962ed4047aa8c6dfc898a2f99d44e699bbaa0198d1
|
data/lib/rudra.rb
CHANGED
@@ -9,10 +9,11 @@ Webdrivers.install_dir = './webdrivers/'
|
|
9
9
|
# Selenium IDE-like WebDriver based upon Ruby binding
|
10
10
|
# @author Aaron Chen
|
11
11
|
# @attr_reader [Symbol] browser The chosen browser
|
12
|
-
# @attr_reader [WebDriver::Driver] driver The driver instance
|
12
|
+
# @attr_reader [Selenium::WebDriver::Driver] driver The driver instance
|
13
13
|
# of the chosen browser
|
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
17
|
class Rudra
|
17
18
|
# Supported Browsers
|
18
19
|
BROWSERS = %i[chrome firefox safari].freeze
|
@@ -24,6 +25,7 @@ class Rudra
|
|
24
25
|
].freeze
|
25
26
|
|
26
27
|
attr_reader :browser, :driver, :locale, :timeout
|
28
|
+
attr_writer :verbose
|
27
29
|
|
28
30
|
# Initialize an instance of Rudra
|
29
31
|
# @param [Hash] options the options to initialize Rudra
|
@@ -38,14 +40,21 @@ class Rudra
|
|
38
40
|
initialize_driver
|
39
41
|
|
40
42
|
self.timeout = options.fetch(:timeout, 30)
|
43
|
+
self.verbose = options.fetch(:verbose, true)
|
41
44
|
end
|
42
45
|
|
43
46
|
#
|
44
47
|
# Driver Functions
|
45
48
|
#
|
46
49
|
|
50
|
+
# Initialize ActionBuilder
|
51
|
+
# @return [Selenium::WebDriver::ActionBuilder] ActionBuilder
|
52
|
+
def action
|
53
|
+
driver.action
|
54
|
+
end
|
55
|
+
|
47
56
|
# Get the active element
|
48
|
-
# @return [WebDriver::Element] the active element
|
57
|
+
# @return [Selenium::WebDriver::Element] the active element
|
49
58
|
def active_element
|
50
59
|
driver.switch_to.active_element
|
51
60
|
end
|
@@ -78,16 +87,19 @@ class Rudra
|
|
78
87
|
|
79
88
|
# Move back a single entry in the browser's history
|
80
89
|
def back
|
90
|
+
log('- back') if @verbose
|
81
91
|
driver.navigate.back
|
82
92
|
end
|
83
93
|
|
84
94
|
# Open a blank page
|
85
95
|
def blank
|
96
|
+
log('- blank') if @verbose
|
86
97
|
open('about:blank')
|
87
98
|
end
|
88
99
|
|
89
100
|
# Close the current window, or the browser if no windows are left
|
90
101
|
def close
|
102
|
+
log('- close') if @verbose
|
91
103
|
driver.close
|
92
104
|
end
|
93
105
|
|
@@ -117,19 +129,22 @@ class Rudra
|
|
117
129
|
|
118
130
|
# Execute the given JavaScript
|
119
131
|
# @param [String] script JavaScript source to execute
|
120
|
-
# @param [WebDriver::Element, Integer, Float, Boolean, NilClass,
|
121
|
-
# Array] args arguments will be available in the given script
|
122
|
-
# 'arguments' pseudo-array
|
123
|
-
# @return [WebDriver::Element, Integer, Float, Boolean, NilClass,
|
124
|
-
# Array] the value returned from the script
|
132
|
+
# @param [Selenium::WebDriver::Element, Integer, Float, Boolean, NilClass,
|
133
|
+
# String, Array] args arguments will be available in the given script
|
134
|
+
# in the 'arguments' pseudo-array
|
135
|
+
# @return [Selenium::WebDriver::Element, Integer, Float, Boolean, NilClass,
|
136
|
+
# String, Array] the value returned from the script
|
125
137
|
def execute_script(script, *args)
|
126
138
|
driver.execute_script(script, *args)
|
127
139
|
end
|
128
140
|
|
129
141
|
# Find the first element matching the given locator
|
130
|
-
# @param [String] locator the locator to
|
131
|
-
#
|
142
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
143
|
+
# identify the element or Selenium::WebDriver::Element
|
144
|
+
# @return [Selenium::WebDriver::Element] the element found
|
132
145
|
def find_element(locator)
|
146
|
+
return locator if locator.is_a?(Selenium::WebDriver::Element)
|
147
|
+
|
133
148
|
element = nil
|
134
149
|
how, what = parse_locator(locator)
|
135
150
|
|
@@ -149,7 +164,7 @@ class Rudra
|
|
149
164
|
|
150
165
|
# Find all elements matching the given locator
|
151
166
|
# @param [String] locator the locator to identify the elements
|
152
|
-
# @return [Array<WebDriver::Element>] the elements found
|
167
|
+
# @return [Array<Selenium::WebDriver::Element>] the elements found
|
153
168
|
def find_elements(locator)
|
154
169
|
how, what = parse_locator(locator)
|
155
170
|
driver.find_elements(how, what) ||
|
@@ -158,26 +173,38 @@ class Rudra
|
|
158
173
|
|
159
174
|
# Move forward a single entry in the browser's history
|
160
175
|
def forward
|
176
|
+
log('- forward') if @verbose
|
161
177
|
driver.navigate.forward
|
162
178
|
end
|
163
179
|
|
164
180
|
# Make the current window full screen
|
165
181
|
def full_screen
|
182
|
+
log('- full_screen') if @verbose
|
166
183
|
driver.manage.window.full_screen
|
167
184
|
end
|
168
185
|
|
169
186
|
# Quit the browser
|
170
187
|
def quit
|
188
|
+
log('- quit') if @verbose
|
171
189
|
driver.quit
|
172
190
|
end
|
173
191
|
|
192
|
+
# Print message
|
193
|
+
# @param [String] message the message to print
|
194
|
+
def log(message)
|
195
|
+
puts message
|
196
|
+
end
|
197
|
+
|
174
198
|
# Maximize the current window
|
175
199
|
def maximize
|
200
|
+
log('- maximize') if @verbose
|
176
201
|
driver.manage.window.maximize
|
177
202
|
end
|
178
203
|
|
179
204
|
# Maximize the current window to the size of the screen
|
180
205
|
def maximize_to_screen
|
206
|
+
log('- maximize_to_screen') if @verbose
|
207
|
+
|
181
208
|
size = execute_script(%(
|
182
209
|
return { width: window.screen.width, height: window.screen.height };
|
183
210
|
))
|
@@ -188,6 +215,7 @@ class Rudra
|
|
188
215
|
|
189
216
|
# Minimize the current window
|
190
217
|
def minimize
|
218
|
+
log('- minimize') if @verbose
|
191
219
|
driver.manage.window.minimize
|
192
220
|
end
|
193
221
|
|
@@ -222,11 +250,19 @@ class Rudra
|
|
222
250
|
# Open the specified URL in the browser
|
223
251
|
# @param [String] url the URL of the page to open
|
224
252
|
def open(url)
|
253
|
+
log("- open(#{url})") if @verbose
|
225
254
|
driver.get(url)
|
226
255
|
end
|
227
256
|
|
228
|
-
#
|
257
|
+
# Get the source of the current page
|
258
|
+
# @return (String) the source of the current page
|
259
|
+
def page_source
|
260
|
+
driver.page_source
|
261
|
+
end
|
262
|
+
|
263
|
+
# Refresh the current pagef
|
229
264
|
def refresh
|
265
|
+
log('- refresh') if @verbose
|
230
266
|
driver.navigate.refresh
|
231
267
|
end
|
232
268
|
|
@@ -240,6 +276,7 @@ class Rudra
|
|
240
276
|
# Save a PNG screenshot to the given path
|
241
277
|
# @param [String] png_path the path of PNG screenshot
|
242
278
|
def save_screenshot(png_path)
|
279
|
+
log("- save_screenshot(#{png_path})") if @verbose
|
243
280
|
driver.save_screenshot(
|
244
281
|
png_path.end_with?('.png') ? png_path : "#{png_path}.png"
|
245
282
|
)
|
@@ -298,7 +335,8 @@ class Rudra
|
|
298
335
|
end
|
299
336
|
|
300
337
|
# Wait until the element, identified by locator, is visible
|
301
|
-
# @param [String] locator the locator to
|
338
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
339
|
+
# identify the element or Selenium::WebDriver::Element
|
302
340
|
def wait_for_visible(locator)
|
303
341
|
wait_for { find_element(locator).displayed? }
|
304
342
|
end
|
@@ -318,6 +356,7 @@ class Rudra
|
|
318
356
|
# Zoom the current page
|
319
357
|
# @param [Float] scale the scale of zoom
|
320
358
|
def zoom(scale)
|
359
|
+
log("- zoom(#{scale})") if @verbose
|
321
360
|
execute_script(%(document.body.style.zoom = arguments[0];), scale)
|
322
361
|
end
|
323
362
|
|
@@ -327,7 +366,8 @@ class Rudra
|
|
327
366
|
|
328
367
|
# Get the value of the given attribute of the element,
|
329
368
|
# identified by locator
|
330
|
-
# @param [String] locator the locator to
|
369
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
370
|
+
# identify the element or Selenium::WebDriver::Element
|
331
371
|
# @param [String] attribute the name of the attribute
|
332
372
|
# @return [String, nil] attribute value
|
333
373
|
def attribute(locator, attribute)
|
@@ -335,7 +375,8 @@ class Rudra
|
|
335
375
|
end
|
336
376
|
|
337
377
|
# If the element, identified by locator, has the given attribute
|
338
|
-
# @param [String] locator the locator to
|
378
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
379
|
+
# identify the element or Selenium::WebDriver::Element
|
339
380
|
# @param [String] attribute the name of the attribute
|
340
381
|
# @return [Boolean] the result of the existence of the given attribute
|
341
382
|
def attribute?(locator, attribute)
|
@@ -345,8 +386,10 @@ class Rudra
|
|
345
386
|
end
|
346
387
|
|
347
388
|
# Blur the given element, identfied by locator
|
348
|
-
# @param [String] locator the locator to
|
389
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
390
|
+
# identify the element or Selenium::WebDriver::Element
|
349
391
|
def blur(locator)
|
392
|
+
log("- blur(#{locator})") if @verbose && locator.is_a?(String)
|
350
393
|
execute_script(
|
351
394
|
'var element = arguments[0]; element.blur();',
|
352
395
|
find_element(locator)
|
@@ -354,34 +397,94 @@ class Rudra
|
|
354
397
|
end
|
355
398
|
|
356
399
|
# Clear the input of the given element, identified by locator
|
357
|
-
# @param [String] locator the locator to
|
400
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
401
|
+
# identify the element or Selenium::WebDriver::Element
|
358
402
|
def clear(locator)
|
403
|
+
log("- clear(#{locator})") if @verbose && locator.is_a?(String)
|
359
404
|
find_element(locator).clear
|
360
405
|
end
|
361
406
|
|
362
407
|
# Click the given element, identified by locator
|
363
|
-
# @param [String] locator the locator to
|
408
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
409
|
+
# identify the element or Selenium::WebDriver::Element
|
364
410
|
def click(locator)
|
411
|
+
log("- click(#{locator})") if @verbose && locator.is_a?(String)
|
365
412
|
find_element(locator).click
|
366
413
|
end
|
367
414
|
|
415
|
+
# Click the given element, identified by locator, with an offset
|
416
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
417
|
+
# identify the element or Selenium::WebDriver::Element
|
418
|
+
# @param [Hash] offset the offset coordinates
|
419
|
+
# @option offset [Integer] :x (0) offset on x coordinate
|
420
|
+
# @option offset [Integer] :y (0) offset on y coordinate
|
421
|
+
def click_at(locator, offset = {})
|
422
|
+
log("- click_at(#{locator})") if @verbose && locator.is_a?(String)
|
423
|
+
|
424
|
+
x = offset.fetch(:x, 0)
|
425
|
+
y = offset.fetch(:y, 0)
|
426
|
+
|
427
|
+
element = find_element(locator)
|
428
|
+
|
429
|
+
action
|
430
|
+
.move_to(element, x, y)
|
431
|
+
.click
|
432
|
+
.perform
|
433
|
+
end
|
434
|
+
|
368
435
|
# If the given element, identified by locator, is displayed
|
369
|
-
# @param [String] locator the locator to
|
436
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
437
|
+
# identify the element or Selenium::WebDriver::Element
|
370
438
|
# @return [Boolean]
|
371
439
|
def displayed?(locator)
|
372
440
|
find_element(locator).displayed?
|
373
441
|
end
|
374
442
|
|
443
|
+
# Double-click the given element, identified by locator, with an offset
|
444
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
445
|
+
# identify the element or Selenium::WebDriver::Element
|
446
|
+
# @param [Hash] offset the offset coordinates
|
447
|
+
# @option offset [Integer] :x (0) offset on x coordinate
|
448
|
+
# @option offset [Integer] :y (0) offset on y coordinate
|
449
|
+
def double_click(locator, offset = {})
|
450
|
+
log("- double_click(#{locator})") if @verbose && locator.is_a?(String)
|
451
|
+
|
452
|
+
x = offset.fetch(:x, 0)
|
453
|
+
y = offset.fetch(:y, 0)
|
454
|
+
|
455
|
+
element = find_element(locator)
|
456
|
+
|
457
|
+
action
|
458
|
+
.move_to(element, x, y)
|
459
|
+
.double_click
|
460
|
+
.perform
|
461
|
+
end
|
462
|
+
|
463
|
+
# Drag and drop
|
464
|
+
# @param [String] from_locator the locator to emulate button down at
|
465
|
+
# @param [String] to_locator the locator to to move to and release
|
466
|
+
# the mouse at
|
467
|
+
def drag_and_drop(from_locator, to_locator)
|
468
|
+
el1 = find_element(from_locator)
|
469
|
+
el2 = find_element(to_locator)
|
470
|
+
|
471
|
+
action.drag_and_drop(el1, el2).perform
|
472
|
+
end
|
473
|
+
|
375
474
|
# If the given element, identified by locator, is enabled
|
376
|
-
# @param [String] locator the locator to
|
475
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
476
|
+
# identify the element or Selenium::WebDriver::Element
|
377
477
|
# @return [Boolean]
|
378
478
|
def enabled?(locator)
|
379
479
|
find_element(locator).enabled?
|
380
480
|
end
|
381
481
|
|
382
482
|
# Focus the given element, identfied by locator
|
383
|
-
# @param [String] locator the locator to
|
483
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
484
|
+
# identify the element or Selenium::WebDriver::Element
|
384
485
|
def focus(locator)
|
486
|
+
log("- focus(#{locator})") if @verbose && locator.is_a?(String)
|
487
|
+
|
385
488
|
execute_script(
|
386
489
|
'var element = arguments[0]; element.focus();',
|
387
490
|
find_element(locator)
|
@@ -389,45 +492,75 @@ class Rudra
|
|
389
492
|
end
|
390
493
|
|
391
494
|
# Hide the given element, identfied by locator
|
392
|
-
# @param [String] locator the locator to
|
495
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
496
|
+
# identify the element or Selenium::WebDriver::Element
|
393
497
|
def hide(locator)
|
498
|
+
log("- hide(#{locator})") if @verbose && locator.is_a?(String)
|
499
|
+
|
394
500
|
execute_script(%(
|
395
501
|
arguments[0].style.display = 'none';
|
396
502
|
), find_element(locator))
|
397
503
|
end
|
398
504
|
|
399
505
|
# Hightlight the given element, identfied by locator
|
400
|
-
# @param [String] locator the locator to
|
506
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
507
|
+
# identify the element or Selenium::WebDriver::Element
|
401
508
|
def highlight(locator)
|
509
|
+
log("- highlight(#{locator})") if @verbose && locator.is_a?(String)
|
510
|
+
|
402
511
|
execute_script(%(
|
403
|
-
arguments[0].style.backgroundColor = '#
|
512
|
+
arguments[0].style.backgroundColor = '#ff3';
|
404
513
|
), find_element(locator))
|
405
514
|
end
|
406
515
|
|
407
516
|
# Click the given element, identified by locator, via Javascript
|
408
|
-
# @param [String] locator the locator to
|
517
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
518
|
+
# identify the element or Selenium::WebDriver::Element
|
409
519
|
def js_click(locator)
|
520
|
+
log("- js_click(#{locator})") if @verbose && locator.is_a?(String)
|
410
521
|
execute_script('arguments[0].click();', find_element(locator))
|
411
522
|
end
|
412
523
|
|
413
524
|
# Get the location of the given element, identfied by locator
|
414
|
-
# @param [String] locator the locator to
|
415
|
-
#
|
525
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
526
|
+
# identify the element or Selenium::WebDriver::Element
|
527
|
+
# @return [Selenium::WebDriver::Point] the point of the given element
|
416
528
|
def location(locator)
|
417
529
|
find_element(locator).location
|
418
530
|
end
|
419
531
|
|
532
|
+
# Move to the given element, identified by locator, with an offset
|
533
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
534
|
+
# identify the element or Selenium::WebDriver::Element
|
535
|
+
# @param [Hash] offset the offset coordinates
|
536
|
+
# @option offset [Integer] :x (0) offset on x coordinate
|
537
|
+
# @option offset [Integer] :y (0) offset on y coordinate
|
538
|
+
def move_to(locator, offset = {})
|
539
|
+
log("- move_to(#{locator})") if @verbose && locator.is_a?(String)
|
540
|
+
|
541
|
+
x = offset.fetch(:x, 0)
|
542
|
+
y = offset.fetch(:y, 0)
|
543
|
+
|
544
|
+
element = find_element(locator)
|
545
|
+
|
546
|
+
action
|
547
|
+
.move_to(element, x, y)
|
548
|
+
.perform
|
549
|
+
end
|
550
|
+
|
420
551
|
# Get the dimensions and coordinates of the given element,
|
421
552
|
# identfied by locator
|
422
|
-
# @param [String] locator the locator to
|
423
|
-
#
|
553
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
554
|
+
# identify the element or Selenium::WebDriver::Element
|
555
|
+
# @return [Selenium::WebDriver::Rectangle] the retangle of the given element
|
424
556
|
def rect(locator)
|
425
557
|
find_element(locator).rect
|
426
558
|
end
|
427
559
|
|
428
560
|
# Remove the given attribute from the given element,
|
429
561
|
# identfied by locator
|
430
|
-
# @param [String] locator the locator to
|
562
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
563
|
+
# identify the element or Selenium::WebDriver::Element
|
431
564
|
# @param [String] attribute the name of the attribute
|
432
565
|
def remove_attribute(locator, attribute)
|
433
566
|
execute_script(%(
|
@@ -439,11 +572,30 @@ class Rudra
|
|
439
572
|
), find_element(locator), attribute)
|
440
573
|
end
|
441
574
|
|
575
|
+
# Right-click the given element, identified by locator, with an offset
|
576
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
577
|
+
# identify the element or Selenium::WebDriver::Element
|
578
|
+
# @param [Hash] offset the offset coordinates
|
579
|
+
# @option offset [Integer] :x (0) offset on x coordinate
|
580
|
+
# @option offset [Integer] :y (0) offset on y coordinate
|
581
|
+
def right_click(locator, offset = {})
|
582
|
+
log("- right_click(#{locator})") if @verbose && locator.is_a?(String)
|
583
|
+
|
584
|
+
x = offset.fetch(:x, 0)
|
585
|
+
y = offset.fetch(:y, 0)
|
586
|
+
|
587
|
+
element = find_element(locator)
|
588
|
+
action.move_to(element, x, y).context_click.perform
|
589
|
+
end
|
590
|
+
|
442
591
|
# Scroll the given element, identfied by locator, into view
|
443
|
-
# @param [String] locator the locator to
|
592
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
593
|
+
# identify the element or Selenium::WebDriver::Element
|
444
594
|
# @param [Boolean] align_to true if aligned on top or
|
445
595
|
# false if aligned at the bottom
|
446
596
|
def scroll_into_view(locator, align_to = true)
|
597
|
+
log("- scroll_into_view(#{locator})") if @verbose && locator.is_a?(String)
|
598
|
+
|
447
599
|
execute_script(
|
448
600
|
'arguments[0].scrollIntoView(arguments[1]);',
|
449
601
|
find_element(locator),
|
@@ -452,27 +604,35 @@ class Rudra
|
|
452
604
|
end
|
453
605
|
|
454
606
|
# Select the given option, identified by locator
|
455
|
-
# @param [String] option_locator the
|
607
|
+
# @param [String, Selenium::WebDriver::Element] option_locator the locator to
|
608
|
+
# identify the element or Selenium::WebDriver::Element
|
456
609
|
def select(option_locator)
|
610
|
+
if @verbose && option_locator.is_a?(String)
|
611
|
+
log("- select(#{option_locator})")
|
612
|
+
end
|
457
613
|
find_element(option_locator).click
|
458
614
|
end
|
459
615
|
|
460
616
|
# If the given element, identified by locator, is selected
|
461
|
-
# @param [String] locator the locator to
|
617
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
618
|
+
# identify the element or Selenium::WebDriver::Element
|
462
619
|
# @return [Boolean]
|
463
620
|
def selected?(locator)
|
464
621
|
find_element(locator).selected?
|
465
622
|
end
|
466
623
|
|
467
624
|
# Send keystrokes to the given element, identfied by locator
|
468
|
-
# @param [String] locator the locator to
|
625
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
626
|
+
# identify the element or Selenium::WebDriver::Element
|
469
627
|
# @param [String, Symbol, Array] args keystrokes to send
|
470
628
|
def send_keys(locator, *args)
|
629
|
+
log("- send_keys(#{locator})") if @verbose && locator.is_a?(String)
|
471
630
|
find_element(locator).send_keys(*args)
|
472
631
|
end
|
473
632
|
|
474
633
|
# Set the attribute's value of the given element, identfied by locator
|
475
|
-
# @param [String] locator the locator to
|
634
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
635
|
+
# identify the element or Selenium::WebDriver::Element
|
476
636
|
# @param [String] attribute the name of the attribute
|
477
637
|
# @param [String] value the value of the attribute
|
478
638
|
def set_attribute(locator, attribute, value)
|
@@ -485,42 +645,50 @@ class Rudra
|
|
485
645
|
end
|
486
646
|
|
487
647
|
# Show the given element, identfied by locator
|
488
|
-
# @param [String] locator the locator to
|
648
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
649
|
+
# identify the element or Selenium::WebDriver::Element
|
489
650
|
def show(locator)
|
651
|
+
log("- show(#{locator})") if @verbose && locator.is_a?(String)
|
490
652
|
execute_script(%(
|
491
653
|
arguments[0].style.display = '';
|
492
654
|
), find_element(locator))
|
493
655
|
end
|
494
656
|
|
495
657
|
# Get the size of the given element, identfied by locator
|
496
|
-
# @param [String] locator the locator to
|
497
|
-
#
|
658
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
659
|
+
# identify the element or Selenium::WebDriver::Element
|
660
|
+
# @return [Selenium::WebDriver::Dimension]
|
498
661
|
def size(locator)
|
499
662
|
find_element(locator).size
|
500
663
|
end
|
501
664
|
|
502
665
|
# Submit the given element, identfied by locator
|
503
|
-
# @param [String] locator the locator to
|
666
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
667
|
+
# identify the element or Selenium::WebDriver::Element
|
504
668
|
def submit(locator)
|
669
|
+
log("- submit(#{locator})") if @verbose && locator.is_a?(String)
|
505
670
|
find_element(locator).submit
|
506
671
|
end
|
507
672
|
|
508
673
|
# Get the tag name of the given element, identfied by locator
|
509
|
-
# @param [String] locator the locator to
|
674
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
675
|
+
# identify the element or Selenium::WebDriver::Element
|
510
676
|
# @return [String] the tag name of the given element
|
511
677
|
def tag_name(locator)
|
512
678
|
find_element(locator).tag_name
|
513
679
|
end
|
514
680
|
|
515
681
|
# Get the text content of the given element, identfied by locator
|
516
|
-
# @param [String] locator the locator to
|
682
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
683
|
+
# identify the element or Selenium::WebDriver::Element
|
517
684
|
# @return [String] the text content of the given element
|
518
685
|
def text(locator)
|
519
686
|
find_element(locator).text
|
520
687
|
end
|
521
688
|
|
522
689
|
# Trigger the given event on the given element, identfied by locator
|
523
|
-
# @param [String] locator the locator to
|
690
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
691
|
+
# identify the element or Selenium::WebDriver::Element
|
524
692
|
# @param [String] event the event name
|
525
693
|
def trigger(locator, event)
|
526
694
|
execute_script(%(
|
@@ -548,9 +716,11 @@ class Rudra
|
|
548
716
|
end
|
549
717
|
|
550
718
|
# Draw an arrow from an element to an element2
|
551
|
-
# @param [String] from_locator the locator
|
552
|
-
#
|
553
|
-
# @
|
719
|
+
# @param [String, Selenium::WebDriver::Element] from_locator the locator
|
720
|
+
# or Selenium::WebDriver::Element where the arrow starts
|
721
|
+
# @param [String, Selenium::WebDriver::Element] to_locator the locator
|
722
|
+
# or Selenium::WebDriver::Element where the arrow ends
|
723
|
+
# @return [Selenium::WebDriver::Element] the arrow element
|
554
724
|
def draw_arrow(from_locator, to_locator)
|
555
725
|
id = random_id
|
556
726
|
|
@@ -586,7 +756,7 @@ class Rudra
|
|
586
756
|
ctx.moveTo(from.x, from.y);
|
587
757
|
ctx.lineTo(to.x, to.y);
|
588
758
|
ctx.lineWidth = 3;
|
589
|
-
ctx.strokeStyle = '#
|
759
|
+
ctx.strokeStyle = '#f00';
|
590
760
|
ctx.stroke();
|
591
761
|
// arrow
|
592
762
|
ctx.beginPath();
|
@@ -605,7 +775,7 @@ class Rudra
|
|
605
775
|
to.y - headlen * Math.sin(angle - Math.PI/7)
|
606
776
|
);
|
607
777
|
ctx.lineWidth = 3;
|
608
|
-
ctx.strokeStyle = '#
|
778
|
+
ctx.strokeStyle = '#f00';
|
609
779
|
ctx.stroke();
|
610
780
|
return;
|
611
781
|
), find_element(from_locator), find_element(to_locator))
|
@@ -614,9 +784,10 @@ class Rudra
|
|
614
784
|
end
|
615
785
|
|
616
786
|
# Draw color fill on the given element, identfied by locator
|
617
|
-
# @param [String] locator the locator to
|
787
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
788
|
+
# identify the element or Selenium::WebDriver::Element
|
618
789
|
# @param [String] color CSS style of backgroundColor
|
619
|
-
# @return [WebDriver::Element] the color fill element
|
790
|
+
# @return [Selenium::WebDriver::Element] the color fill element
|
620
791
|
def draw_color_fill(locator, color = 'rgba(255,0,0,0.8)')
|
621
792
|
rectangle = rect(locator)
|
622
793
|
id = random_id
|
@@ -643,7 +814,8 @@ class Rudra
|
|
643
814
|
end
|
644
815
|
|
645
816
|
# Draw tooltip of the given element, identfied by locator
|
646
|
-
# @param [String] locator the locator to
|
817
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
818
|
+
# identify the element or Selenium::WebDriver::Element
|
647
819
|
# @param [Hash] options the options to create a tooltip
|
648
820
|
# @option options [String] :attribute (title) attribute to draw
|
649
821
|
# the flyover with
|
@@ -652,7 +824,7 @@ class Rudra
|
|
652
824
|
# @option options [Boolean] :from_last_pos (false) if to draw
|
653
825
|
# from last position
|
654
826
|
# @option options [Boolean] :draw_symbol (false) if to draw symbol
|
655
|
-
# @return [WebDriver::Element] the tooltip element
|
827
|
+
# @return [Selenium::WebDriver::Element] the tooltip element
|
656
828
|
def draw_flyover(locator, options = {})
|
657
829
|
attribute_name = options.fetch(:attribute, 'title')
|
658
830
|
offset_x = options.fetch(:offset_x, 5)
|
@@ -722,13 +894,14 @@ class Rudra
|
|
722
894
|
end
|
723
895
|
|
724
896
|
# Draw redmark around the given element, identfied by locator
|
725
|
-
# @param [String] locator the locator to
|
897
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
898
|
+
# identify the element or Selenium::WebDriver::Element
|
726
899
|
# @param [Hash] padding the padding of the given redmark
|
727
900
|
# @option padding [Integer] :top (5) top padding
|
728
901
|
# @option padding [Integer] :right (5) right padding
|
729
902
|
# @option padding [Integer] :bottom (5) bottom padding
|
730
903
|
# @option padding [Integer] :left (5) left padding
|
731
|
-
# @return [WebDriver::Element] the redmark element
|
904
|
+
# @return [Selenium::WebDriver::Element] the redmark element
|
732
905
|
def draw_redmark(locator, padding = {})
|
733
906
|
top = padding.fetch(:top, 5)
|
734
907
|
right = padding.fetch(:right, 5)
|
@@ -759,11 +932,12 @@ class Rudra
|
|
759
932
|
end
|
760
933
|
|
761
934
|
# Draw dropdown menu on the given SELECT element, identfied by locator
|
762
|
-
# @param [String] locator the locator to
|
935
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
936
|
+
# identify the element or Selenium::WebDriver::Element
|
763
937
|
# @param [Hash] options the options to create the dropdown menu
|
764
938
|
# @option options [Integer] :offset_x (0) offset on x coordinate
|
765
939
|
# @option options [Integer] :offset_y (0) offset on y coordinate
|
766
|
-
# @return [WebDriver::Element] the dropdown menu element
|
940
|
+
# @return [Selenium::WebDriver::Element] the dropdown menu element
|
767
941
|
def draw_select(locator, options = {})
|
768
942
|
offset_x = options.fetch(:offset_x, 0)
|
769
943
|
offset_y = options.fetch(:offset_y, 0)
|
@@ -815,14 +989,15 @@ class Rudra
|
|
815
989
|
end
|
816
990
|
|
817
991
|
# Draw text on top of the given element, identfied by locator
|
818
|
-
# @param [String] locator the locator to
|
992
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
993
|
+
# identify the element or Selenium::WebDriver::Element
|
819
994
|
# @param [String] text the text to draw
|
820
995
|
# @param [Hash] options the options to create the text
|
821
996
|
# @option options [String] :color ('#f00') the color of the text
|
822
997
|
# @option options [Integer] :font_size (13) the font size of the text
|
823
998
|
# @option options [Integer] :top (2) CSS style of top
|
824
999
|
# @option options [Integer] :right (20) CSS style of right
|
825
|
-
# @return [WebDriver::Element] the text element
|
1000
|
+
# @return [Selenium::WebDriver::Element] the text element
|
826
1001
|
def draw_text(locator, text, options = {})
|
827
1002
|
color = options.fetch(:color, '#f00')
|
828
1003
|
font_size = options.fetch(:font_size, 13)
|
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
|
+
version: 1.0.1
|
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-
|
11
|
+
date: 2019-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 4.0.1
|
55
|
-
description:
|
55
|
+
description: Selenium IDE alternative using selenium-webdriver
|
56
56
|
email: aaron@611b.com
|
57
57
|
executables: []
|
58
58
|
extensions: []
|