rudra 1.0.11 → 1.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rudra.rb +63 -124
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 425842a9405ec0a244bca0e722f6eb25cdb881b355346f3d61318a2fde111a25
|
4
|
+
data.tar.gz: 4ed27b935bd5a3192d421fad516fa024fc9783f1f10c2b75da85679717511a70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aa62d7dcfa60e50e74fcc61a11a264a5e1b20f77355e4776e6821d75d06a4b3ecf9ff89c1a4197d72ace5175fe25163b7b68309f05d5ff64c60aa86e33f1aaa
|
7
|
+
data.tar.gz: 8f4353692ce71ef0276786a0bad7a062c1d88095184947a1d2f682f5ddae0d515764bb958726fe9dfafcc704b9ac40b129659b1a0a277e673e38ffd3e8cf6edc
|
data/lib/rudra.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'selenium-webdriver'
|
2
2
|
require 'webdrivers/chromedriver'
|
3
3
|
require 'webdrivers/geckodriver'
|
4
|
+
require 'webdrivers/iedriver'
|
4
5
|
|
5
6
|
# Selenium::WebDriver::Chrome::Service.driver_path = './webdrivers/chromedriver'
|
6
7
|
# Selenium::WebDriver::Firefox::Service.driver_path = './webdrivers/geckodriver'
|
@@ -12,11 +13,14 @@ require 'webdrivers/geckodriver'
|
|
12
13
|
# of the chosen browser
|
13
14
|
# @attr_reader [String] install_dir The install directory of WebDrivers
|
14
15
|
# @attr_reader [String] locale The browser locale
|
16
|
+
# @attr_reader [Boolean] headless Headless mode for Google Chrome
|
17
|
+
# @attr_reader [String] screen_dir The screenshot directory of save_screenshot
|
18
|
+
# @attr_reader [String] log_prefix Prefix for logging executed methods
|
15
19
|
# @attr_reader [Integer] timeout The driver timeout
|
16
20
|
# @attr_reader [Boolean] verbose Verbose mode
|
17
21
|
class Rudra
|
18
22
|
# Supported Browsers
|
19
|
-
BROWSERS = %i[chrome firefox safari].freeze
|
23
|
+
BROWSERS = %i[chrome firefox ie safari].freeze
|
20
24
|
|
21
25
|
# Element Finder Methods
|
22
26
|
HOWS = %i[
|
@@ -24,8 +28,16 @@ class Rudra
|
|
24
28
|
name partial_link_text tag_name xpath
|
25
29
|
].freeze
|
26
30
|
|
31
|
+
# Attributes
|
32
|
+
ATTRIBUTES = %i[
|
33
|
+
browser driver install_dir locale
|
34
|
+
headless screen_dir log_prefix
|
35
|
+
timeout verbose
|
36
|
+
].freeze
|
37
|
+
|
27
38
|
attr_reader :browser, :driver, :install_dir, :locale,
|
28
|
-
:headless, :
|
39
|
+
:headless, :screen_dir, :log_prefix,
|
40
|
+
:timeout, :verbose
|
29
41
|
|
30
42
|
# Initialize an instance of Rudra
|
31
43
|
# @param [Hash] options the options to initialize Rudra
|
@@ -35,7 +47,8 @@ class Rudra
|
|
35
47
|
# directory of WebDrivers
|
36
48
|
# @option options [Symbol] :locale (:en) the browser locale
|
37
49
|
# @option options [Boolean] :headless (false) headless mode
|
38
|
-
# @option options [String] :
|
50
|
+
# @option options [String] :screen_dir ('./screens/') the location of screenshots
|
51
|
+
# @option options [String] :log_prefix (' - ') prefix for logging executed methods
|
39
52
|
# @option options [Integer] :timeout (30) implicit_wait timeout
|
40
53
|
# @option options [Boolean] :verbose (true) verbose mode
|
41
54
|
def initialize(options = {})
|
@@ -43,20 +56,14 @@ class Rudra
|
|
43
56
|
self.install_dir = options.fetch(:install_dir, './webdrivers/')
|
44
57
|
self.locale = options.fetch(:locale, :en)
|
45
58
|
self.headless = options.fetch(:headless, false)
|
59
|
+
self.screen_dir = options.fetch(:screen_dir, './screens/')
|
46
60
|
self.log_prefix = options.fetch(:log_prefix, ' - ')
|
47
61
|
self.verbose = options.fetch(:verbose, true)
|
62
|
+
self.main_label = caller_locations(2, 1).first.label
|
48
63
|
|
49
64
|
initialize_driver
|
50
65
|
|
51
66
|
self.timeout = options.fetch(:timeout, 30)
|
52
|
-
|
53
|
-
@verbose && (
|
54
|
-
puts %(
|
55
|
-
============ Rudra ============
|
56
|
-
Browser: #{@browser}, Locale: #{@locale}
|
57
|
-
============ Log ============
|
58
|
-
).lines.map(&:strip).reject(&:empty?).join("\n")
|
59
|
-
)
|
60
67
|
end
|
61
68
|
|
62
69
|
#
|
@@ -66,14 +73,12 @@ class Rudra
|
|
66
73
|
# Initialize ActionBuilder
|
67
74
|
# @return [Selenium::WebDriver::ActionBuilder] ActionBuilder
|
68
75
|
def action
|
69
|
-
log
|
70
76
|
driver.action
|
71
77
|
end
|
72
78
|
|
73
79
|
# Get the active element
|
74
80
|
# @return [Selenium::WebDriver::Element] the active element
|
75
81
|
def active_element
|
76
|
-
log
|
77
82
|
driver.switch_to.active_element
|
78
83
|
end
|
79
84
|
|
@@ -85,43 +90,36 @@ class Rudra
|
|
85
90
|
# @option opts [Boolean] :secure (false) a boolean
|
86
91
|
# @option opts [Time, DateTime, Numeric, nil] :expires (nil) expiry date
|
87
92
|
def add_cookie(opts = {})
|
88
|
-
log(opts)
|
89
93
|
driver.manage.add_cookie(opts)
|
90
94
|
end
|
91
95
|
|
92
96
|
# Accept an alert
|
93
97
|
def alert_accept
|
94
|
-
log
|
95
98
|
switch_to_alert.accept
|
96
99
|
end
|
97
100
|
|
98
101
|
# Dismiss an alert
|
99
102
|
def alert_dismiss
|
100
|
-
log
|
101
103
|
switch_to_alert.dismiss
|
102
104
|
end
|
103
105
|
|
104
106
|
# Send keys to an alert
|
105
107
|
def alert_send_keys(keys)
|
106
|
-
log(keys)
|
107
108
|
switch_to_alert.send_keys(keys)
|
108
109
|
end
|
109
110
|
|
110
111
|
# Move back a single entry in the browser's history
|
111
112
|
def back
|
112
|
-
log
|
113
113
|
driver.navigate.back
|
114
114
|
end
|
115
115
|
|
116
116
|
# Open a blank page
|
117
117
|
def blank
|
118
|
-
log
|
119
118
|
open('about:blank')
|
120
119
|
end
|
121
120
|
|
122
121
|
# Close the current window, or the browser if no windows are left
|
123
122
|
def close
|
124
|
-
log
|
125
123
|
driver.close
|
126
124
|
end
|
127
125
|
|
@@ -129,27 +127,23 @@ class Rudra
|
|
129
127
|
# @param [String] name the name of the cookie
|
130
128
|
# @return [Hash, nil] the cookie, or nil if it wasn't found
|
131
129
|
def cookie_named(name)
|
132
|
-
log(name)
|
133
130
|
driver.manage.cookie_named(name)
|
134
131
|
end
|
135
132
|
|
136
133
|
# Get the URL of the current page
|
137
134
|
# @return (String) the URL of the current page
|
138
135
|
def current_url
|
139
|
-
log
|
140
136
|
driver.current_url
|
141
137
|
end
|
142
138
|
|
143
139
|
# Delete all cookies
|
144
140
|
def delete_all_cookies
|
145
|
-
log
|
146
141
|
driver.manage.delete_all_cookies
|
147
142
|
end
|
148
143
|
|
149
144
|
# Delete the cookie with the given name
|
150
145
|
# @param [String] name the name of the cookie
|
151
146
|
def delete_cookie(name)
|
152
|
-
log(name)
|
153
147
|
driver.manage.delete_cookie(name)
|
154
148
|
end
|
155
149
|
|
@@ -161,7 +155,6 @@ class Rudra
|
|
161
155
|
# @return [Selenium::WebDriver::Element, Integer, Float, Boolean, NilClass,
|
162
156
|
# String, Array] the value returned from the script
|
163
157
|
def execute_script(script, *args)
|
164
|
-
log
|
165
158
|
driver.execute_script(script, *args)
|
166
159
|
end
|
167
160
|
|
@@ -170,8 +163,6 @@ class Rudra
|
|
170
163
|
# identify the element or Selenium::WebDriver::Element
|
171
164
|
# @return [Selenium::WebDriver::Element] the element found
|
172
165
|
def find_element(locator)
|
173
|
-
log(locator)
|
174
|
-
|
175
166
|
return locator if locator.is_a?(Selenium::WebDriver::Element)
|
176
167
|
|
177
168
|
element = nil
|
@@ -195,8 +186,6 @@ class Rudra
|
|
195
186
|
# @param [String] locator the locator to identify the elements
|
196
187
|
# @return [Array<Selenium::WebDriver::Element>] the elements found
|
197
188
|
def find_elements(locator)
|
198
|
-
log(locator)
|
199
|
-
|
200
189
|
how, what = parse_locator(locator)
|
201
190
|
driver.find_elements(how, what) ||
|
202
191
|
abort("Failed to find elements: #{locator}")
|
@@ -204,32 +193,26 @@ class Rudra
|
|
204
193
|
|
205
194
|
# Move forward a single entry in the browser's history
|
206
195
|
def forward
|
207
|
-
log
|
208
196
|
driver.navigate.forward
|
209
197
|
end
|
210
198
|
|
211
199
|
# Make the current window full screen
|
212
200
|
def full_screen
|
213
|
-
log
|
214
201
|
driver.manage.window.full_screen
|
215
202
|
end
|
216
203
|
|
217
204
|
# Quit the browser
|
218
205
|
def quit
|
219
|
-
log
|
220
206
|
driver.quit
|
221
207
|
end
|
222
208
|
|
223
209
|
# Maximize the current window
|
224
210
|
def maximize
|
225
|
-
log
|
226
211
|
driver.manage.window.maximize
|
227
212
|
end
|
228
213
|
|
229
214
|
# Maximize the current window to the size of the screen
|
230
215
|
def maximize_to_screen
|
231
|
-
log
|
232
|
-
|
233
216
|
size = execute_script(%(
|
234
217
|
return { width: window.screen.width, height: window.screen.height };
|
235
218
|
))
|
@@ -240,7 +223,6 @@ class Rudra
|
|
240
223
|
|
241
224
|
# Minimize the current window
|
242
225
|
def minimize
|
243
|
-
log
|
244
226
|
driver.manage.window.minimize
|
245
227
|
end
|
246
228
|
|
@@ -248,14 +230,12 @@ class Rudra
|
|
248
230
|
# @param [Integer] point_x the x coordinate
|
249
231
|
# @param [Integer] point_y the y coordinate
|
250
232
|
def move_window_to(point_x, point_y)
|
251
|
-
log(point_x, point_y)
|
252
233
|
driver.manage.window.move_to(point_x, point_y)
|
253
234
|
end
|
254
235
|
|
255
236
|
# Open a new tab
|
256
237
|
# @return [String] the id of the new tab obtained from #window_handles
|
257
238
|
def new_tab
|
258
|
-
log
|
259
239
|
execute_script('window.open();')
|
260
240
|
window_handles.last
|
261
241
|
end
|
@@ -263,7 +243,6 @@ class Rudra
|
|
263
243
|
# Open a new window
|
264
244
|
# @param [String] name the name of the window
|
265
245
|
def new_window(name)
|
266
|
-
log(name)
|
267
246
|
execute_script(%(
|
268
247
|
var w = Math.max(
|
269
248
|
document.documentElement.clientWidth, window.innerWidth || 0
|
@@ -278,20 +257,17 @@ class Rudra
|
|
278
257
|
# Open the specified URL in the browser
|
279
258
|
# @param [String] url the URL of the page to open
|
280
259
|
def open(url)
|
281
|
-
log(url)
|
282
260
|
driver.get(url)
|
283
261
|
end
|
284
262
|
|
285
263
|
# Get the source of the current page
|
286
264
|
# @return (String) the source of the current page
|
287
265
|
def page_source
|
288
|
-
log
|
289
266
|
driver.page_source
|
290
267
|
end
|
291
268
|
|
292
269
|
# Refresh the current pagef
|
293
270
|
def refresh
|
294
|
-
log
|
295
271
|
driver.navigate.refresh
|
296
272
|
end
|
297
273
|
|
@@ -299,55 +275,51 @@ class Rudra
|
|
299
275
|
# @param [Integer] width the width of the window
|
300
276
|
# @param [Integer] height the height of the window
|
301
277
|
def resize_window_to(width, height)
|
302
|
-
log(width, height)
|
303
278
|
driver.manage.window.resize_to(width, height)
|
304
279
|
end
|
305
280
|
|
306
|
-
# Save a PNG screenshot to
|
307
|
-
# @param [String]
|
308
|
-
def save_screenshot(
|
309
|
-
|
281
|
+
# Save a PNG screenshot to file
|
282
|
+
# @param [String] filename the filename of PNG screenshot
|
283
|
+
def save_screenshot(filename)
|
284
|
+
mkdir(@screen_dir) unless Dir.exist?(@screen_dir)
|
310
285
|
driver.save_screenshot(
|
311
|
-
|
286
|
+
File.join(
|
287
|
+
@screen_dir,
|
288
|
+
filename.end_with?('.png') ? filename : "#{filename}.png"
|
289
|
+
)
|
312
290
|
)
|
313
291
|
end
|
314
292
|
|
315
293
|
# Switch to the currently active modal dialog
|
316
294
|
def switch_to_alert
|
317
|
-
log
|
318
295
|
driver.switch_to.alert
|
319
296
|
end
|
320
297
|
|
321
298
|
# Select either the first frame on the page,
|
322
299
|
# or the main document when a page contains iframes
|
323
300
|
def switch_to_default_content
|
324
|
-
log
|
325
301
|
driver.switch_to.default_content
|
326
302
|
end
|
327
303
|
|
328
304
|
# Switch to the frame with the given id
|
329
305
|
def switch_to_frame(id)
|
330
|
-
log(id)
|
331
306
|
driver.switch_to.frame(id)
|
332
307
|
end
|
333
308
|
|
334
309
|
# Switch to the parent frame
|
335
310
|
def switch_to_parent_frame
|
336
|
-
log
|
337
311
|
driver.switch_to.parent_frame
|
338
312
|
end
|
339
313
|
|
340
314
|
# Switch to the given window handle
|
341
315
|
# @param [String] id the window handle obtained through #window_handles
|
342
316
|
def switch_to_window(id)
|
343
|
-
log(id)
|
344
317
|
driver.switch_to.window(id)
|
345
318
|
end
|
346
319
|
|
347
320
|
# Get the title of the current page
|
348
321
|
# @return [String] the title of the current page
|
349
322
|
def title
|
350
|
-
log
|
351
323
|
driver.title
|
352
324
|
end
|
353
325
|
|
@@ -355,7 +327,6 @@ class Rudra
|
|
355
327
|
# @param [Integer] seconds seconds before timed out
|
356
328
|
# @return [Object] the result of the block
|
357
329
|
def wait_for(seconds = timeout)
|
358
|
-
log(seconds)
|
359
330
|
Selenium::WebDriver::Wait.new(timeout: seconds).until { yield }
|
360
331
|
end
|
361
332
|
|
@@ -363,21 +334,18 @@ class Rudra
|
|
363
334
|
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
364
335
|
# identify the element or Selenium::WebDriver::Element
|
365
336
|
def wait_for_enabled(locator)
|
366
|
-
log(locator)
|
367
337
|
wait_for { find_element(locator).enabled? }
|
368
338
|
end
|
369
339
|
|
370
340
|
# Wait until the title of the page including the given string
|
371
341
|
# @param [String] string the string to compare
|
372
342
|
def wait_for_title(string)
|
373
|
-
log(string)
|
374
343
|
wait_for { title.downcase.include?(string.downcase) }
|
375
344
|
end
|
376
345
|
|
377
346
|
# Wait until the URL of the page including the given url
|
378
347
|
# @param [String] url the URL to compare
|
379
348
|
def wait_for_url(url)
|
380
|
-
log(url)
|
381
349
|
wait_for { current_url.include?(url) }
|
382
350
|
end
|
383
351
|
|
@@ -385,28 +353,24 @@ class Rudra
|
|
385
353
|
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
386
354
|
# identify the element or Selenium::WebDriver::Element
|
387
355
|
def wait_for_visible(locator)
|
388
|
-
log(locator)
|
389
356
|
wait_for { find_element(locator).displayed? }
|
390
357
|
end
|
391
358
|
|
392
359
|
# Get the current window handle
|
393
360
|
# @return [String] the id of the current window handle
|
394
361
|
def window_handle
|
395
|
-
log
|
396
362
|
driver.window_handle
|
397
363
|
end
|
398
364
|
|
399
365
|
# Get the window handles of open browser windows
|
400
366
|
# @return [Array<String>] the ids of window handles
|
401
367
|
def window_handles
|
402
|
-
log
|
403
368
|
driver.window_handles
|
404
369
|
end
|
405
370
|
|
406
371
|
# Zoom the current page
|
407
372
|
# @param [Float] scale the scale of zoom
|
408
373
|
def zoom(scale)
|
409
|
-
log(scale)
|
410
374
|
execute_script(%(document.body.style.zoom = arguments[0];), scale)
|
411
375
|
end
|
412
376
|
|
@@ -421,7 +385,6 @@ class Rudra
|
|
421
385
|
# @param [String] attribute the name of the attribute
|
422
386
|
# @return [String, nil] attribute value
|
423
387
|
def attribute(locator, attribute)
|
424
|
-
log(locator, attribute)
|
425
388
|
find_element(locator).property(attribute)
|
426
389
|
end
|
427
390
|
|
@@ -431,7 +394,6 @@ class Rudra
|
|
431
394
|
# @param [String] attribute the name of the attribute
|
432
395
|
# @return [Boolean] the result of the existence of the given attribute
|
433
396
|
def attribute?(locator, attribute)
|
434
|
-
log(locator, attribute)
|
435
397
|
execute_script(%(
|
436
398
|
return arguments[0].hasAttribute(arguments[1]);
|
437
399
|
), find_element(locator), attribute)
|
@@ -441,7 +403,6 @@ class Rudra
|
|
441
403
|
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
442
404
|
# identify the element or Selenium::WebDriver::Element
|
443
405
|
def blur(locator)
|
444
|
-
log(locator)
|
445
406
|
execute_script(
|
446
407
|
'var element = arguments[0]; element.blur();',
|
447
408
|
find_element(locator)
|
@@ -452,7 +413,6 @@ class Rudra
|
|
452
413
|
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
453
414
|
# identify the element or Selenium::WebDriver::Element
|
454
415
|
def clear(locator)
|
455
|
-
log(locator)
|
456
416
|
find_element(locator).clear
|
457
417
|
end
|
458
418
|
|
@@ -460,7 +420,6 @@ class Rudra
|
|
460
420
|
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
461
421
|
# identify the element or Selenium::WebDriver::Element
|
462
422
|
def click(locator)
|
463
|
-
log(locator)
|
464
423
|
find_element(locator).click
|
465
424
|
end
|
466
425
|
|
@@ -471,8 +430,6 @@ class Rudra
|
|
471
430
|
# @option offset [Integer] :x (0) offset on x coordinate
|
472
431
|
# @option offset [Integer] :y (0) offset on y coordinate
|
473
432
|
def click_at(locator, offset = {})
|
474
|
-
log(locator, offset)
|
475
|
-
|
476
433
|
x = offset.fetch(:x, 0)
|
477
434
|
y = offset.fetch(:y, 0)
|
478
435
|
|
@@ -489,7 +446,6 @@ class Rudra
|
|
489
446
|
# identify the element or Selenium::WebDriver::Element
|
490
447
|
# @param [String] property the longhand name of the property
|
491
448
|
def css_value(locator, property)
|
492
|
-
log(locator, property)
|
493
449
|
find_element(locator).css_value(property)
|
494
450
|
end
|
495
451
|
|
@@ -498,7 +454,6 @@ class Rudra
|
|
498
454
|
# identify the element or Selenium::WebDriver::Element
|
499
455
|
# @return [Boolean]
|
500
456
|
def displayed?(locator)
|
501
|
-
log(locator)
|
502
457
|
find_element(locator).displayed?
|
503
458
|
end
|
504
459
|
|
@@ -509,8 +464,6 @@ class Rudra
|
|
509
464
|
# @option offset [Integer] :x (0) offset on x coordinate
|
510
465
|
# @option offset [Integer] :y (0) offset on y coordinate
|
511
466
|
def double_click(locator, offset = {})
|
512
|
-
log(locator, offset)
|
513
|
-
|
514
467
|
x = offset.fetch(:x, 0)
|
515
468
|
y = offset.fetch(:y, 0)
|
516
469
|
|
@@ -527,7 +480,6 @@ class Rudra
|
|
527
480
|
# @param [String] to_locator the locator to to move to and release
|
528
481
|
# the mouse at
|
529
482
|
def drag_and_drop(from_locator, to_locator)
|
530
|
-
log(from_locator, to_locator)
|
531
483
|
el1 = find_element(from_locator)
|
532
484
|
el2 = find_element(to_locator)
|
533
485
|
|
@@ -540,7 +492,6 @@ class Rudra
|
|
540
492
|
# @option offset [Integer] :x (0) offset on x coordinate
|
541
493
|
# @option offset [Integer] :y (0) offset on y coordinate
|
542
494
|
def drag_and_drop_by(source, offset = {})
|
543
|
-
log(source, offset)
|
544
495
|
element = find_element(source)
|
545
496
|
x = offset.fetch(:x, 0)
|
546
497
|
y = offset.fetch(:y, 0)
|
@@ -553,7 +504,6 @@ class Rudra
|
|
553
504
|
# identify the element or Selenium::WebDriver::Element
|
554
505
|
# @return [Boolean]
|
555
506
|
def enabled?(locator)
|
556
|
-
log(locator)
|
557
507
|
find_element(locator).enabled?
|
558
508
|
end
|
559
509
|
|
@@ -561,8 +511,6 @@ class Rudra
|
|
561
511
|
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
562
512
|
# identify the element or Selenium::WebDriver::Element
|
563
513
|
def focus(locator)
|
564
|
-
log(locator)
|
565
|
-
|
566
514
|
execute_script(
|
567
515
|
'var element = arguments[0]; element.focus();',
|
568
516
|
find_element(locator)
|
@@ -573,8 +521,6 @@ class Rudra
|
|
573
521
|
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
574
522
|
# identify the element or Selenium::WebDriver::Element
|
575
523
|
def hide(locator)
|
576
|
-
log(locator)
|
577
|
-
|
578
524
|
execute_script(%(
|
579
525
|
arguments[0].style.display = 'none';
|
580
526
|
), find_element(locator))
|
@@ -584,8 +530,6 @@ class Rudra
|
|
584
530
|
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
585
531
|
# identify the element or Selenium::WebDriver::Element
|
586
532
|
def highlight(locator)
|
587
|
-
log(locator)
|
588
|
-
|
589
533
|
execute_script(%(
|
590
534
|
arguments[0].style.backgroundColor = '#ff3';
|
591
535
|
), find_element(locator))
|
@@ -594,7 +538,6 @@ class Rudra
|
|
594
538
|
# Set implicit_wait timeout
|
595
539
|
# @param [Integer] seconds timeout for implicit_wait
|
596
540
|
def implicit_wait(seconds)
|
597
|
-
log(seconds)
|
598
541
|
driver.manage.timeouts.implicit_wait = seconds
|
599
542
|
end
|
600
543
|
|
@@ -602,7 +545,6 @@ class Rudra
|
|
602
545
|
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
603
546
|
# identify the element or Selenium::WebDriver::Element
|
604
547
|
def js_click(locator)
|
605
|
-
log(locator)
|
606
548
|
execute_script('arguments[0].click();', find_element(locator))
|
607
549
|
end
|
608
550
|
|
@@ -611,7 +553,6 @@ class Rudra
|
|
611
553
|
# identify the element or Selenium::WebDriver::Element
|
612
554
|
# @return [Selenium::WebDriver::Point] the point of the given element
|
613
555
|
def location(locator)
|
614
|
-
log(locator)
|
615
556
|
find_element(locator).location
|
616
557
|
end
|
617
558
|
|
@@ -619,7 +560,6 @@ class Rudra
|
|
619
560
|
# @param [Integer] right_by horizontal offset
|
620
561
|
# @param [Integer] down_by vertical offset
|
621
562
|
def move_by(right_by = 0, down_by = 0)
|
622
|
-
log(right_by, down_by)
|
623
563
|
action.move_by(right_by, down_by).perform
|
624
564
|
end
|
625
565
|
|
@@ -630,8 +570,6 @@ class Rudra
|
|
630
570
|
# @option offset [Integer] :x (0) offset on x coordinate
|
631
571
|
# @option offset [Integer] :y (0) offset on y coordinate
|
632
572
|
def move_to(locator, offset = {})
|
633
|
-
log(locator, offset)
|
634
|
-
|
635
573
|
x = offset.fetch(:x, 0)
|
636
574
|
y = offset.fetch(:y, 0)
|
637
575
|
|
@@ -645,7 +583,6 @@ class Rudra
|
|
645
583
|
# Set page_load timeout
|
646
584
|
# @param [Integer] seconds timeout for page_load
|
647
585
|
def page_load(seconds)
|
648
|
-
log(seconds)
|
649
586
|
driver.manage.timeouts.page_load = seconds
|
650
587
|
end
|
651
588
|
|
@@ -655,7 +592,6 @@ class Rudra
|
|
655
592
|
# identify the element or Selenium::WebDriver::Element
|
656
593
|
# @return [Selenium::WebDriver::Rectangle] the retangle of the given element
|
657
594
|
def rect(locator)
|
658
|
-
log(locator)
|
659
595
|
find_element(locator).rect
|
660
596
|
end
|
661
597
|
|
@@ -665,7 +601,6 @@ class Rudra
|
|
665
601
|
# identify the element or Selenium::WebDriver::Element
|
666
602
|
# @param [String] attribute the name of the attribute
|
667
603
|
def remove_attribute(locator, attribute)
|
668
|
-
log(locator, attribute)
|
669
604
|
execute_script(%(
|
670
605
|
var element = arguments[0];
|
671
606
|
var attributeName = arguments[1];
|
@@ -682,8 +617,6 @@ class Rudra
|
|
682
617
|
# @option offset [Integer] :x (0) offset on x coordinate
|
683
618
|
# @option offset [Integer] :y (0) offset on y coordinate
|
684
619
|
def right_click(locator, offset = {})
|
685
|
-
log(locator, offset)
|
686
|
-
|
687
620
|
x = offset.fetch(:x, 0)
|
688
621
|
y = offset.fetch(:y, 0)
|
689
622
|
|
@@ -694,7 +627,6 @@ class Rudra
|
|
694
627
|
# Set script_timeout timeout
|
695
628
|
# @param [Integer] seconds timeout for script_timeout
|
696
629
|
def script_timeout(seconds)
|
697
|
-
log(seconds)
|
698
630
|
driver.manage.timeouts.script_timeout = seconds
|
699
631
|
end
|
700
632
|
|
@@ -704,8 +636,6 @@ class Rudra
|
|
704
636
|
# @param [Boolean] align_to true if aligned on top or
|
705
637
|
# false if aligned at the bottom
|
706
638
|
def scroll_into_view(locator, align_to = true)
|
707
|
-
log(locator, align_to)
|
708
|
-
|
709
639
|
execute_script(
|
710
640
|
'arguments[0].scrollIntoView(arguments[1]);',
|
711
641
|
find_element(locator),
|
@@ -717,7 +647,6 @@ class Rudra
|
|
717
647
|
# @param [String, Selenium::WebDriver::Element] option_locator the locator to
|
718
648
|
# identify the element or Selenium::WebDriver::Element
|
719
649
|
def select(option_locator)
|
720
|
-
log(option_locator)
|
721
650
|
find_element(option_locator).click
|
722
651
|
end
|
723
652
|
|
@@ -726,7 +655,6 @@ class Rudra
|
|
726
655
|
# identify the element or Selenium::WebDriver::Element
|
727
656
|
# @return [Boolean]
|
728
657
|
def selected?(locator)
|
729
|
-
log(locator)
|
730
658
|
find_element(locator).selected?
|
731
659
|
end
|
732
660
|
|
@@ -735,7 +663,6 @@ class Rudra
|
|
735
663
|
# identify the element or Selenium::WebDriver::Element
|
736
664
|
# @param [String, Symbol, Array] args keystrokes to send
|
737
665
|
def send_keys(locator, *args)
|
738
|
-
log(locator, *args)
|
739
666
|
find_element(locator).send_keys(*args)
|
740
667
|
end
|
741
668
|
|
@@ -745,7 +672,6 @@ class Rudra
|
|
745
672
|
# @param [String] attribute the name of the attribute
|
746
673
|
# @param [String] value the value of the attribute
|
747
674
|
def set_attribute(locator, attribute, value)
|
748
|
-
log(locator, attribute, value)
|
749
675
|
execute_script(%(
|
750
676
|
var element = arguments[0];
|
751
677
|
var attribute = arguments[1];
|
@@ -758,7 +684,6 @@ class Rudra
|
|
758
684
|
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
759
685
|
# identify the element or Selenium::WebDriver::Element
|
760
686
|
def show(locator)
|
761
|
-
log(locator)
|
762
687
|
execute_script(%(
|
763
688
|
arguments[0].style.display = '';
|
764
689
|
), find_element(locator))
|
@@ -769,7 +694,6 @@ class Rudra
|
|
769
694
|
# identify the element or Selenium::WebDriver::Element
|
770
695
|
# @return [Selenium::WebDriver::Dimension]
|
771
696
|
def size(locator)
|
772
|
-
log(locator)
|
773
697
|
find_element(locator).size
|
774
698
|
end
|
775
699
|
|
@@ -777,7 +701,6 @@ class Rudra
|
|
777
701
|
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
778
702
|
# identify the element or Selenium::WebDriver::Element
|
779
703
|
def submit(locator)
|
780
|
-
log("- submit(#{locator})")
|
781
704
|
find_element(locator).submit
|
782
705
|
end
|
783
706
|
|
@@ -786,7 +709,6 @@ class Rudra
|
|
786
709
|
# identify the element or Selenium::WebDriver::Element
|
787
710
|
# @return [String] the tag name of the given element
|
788
711
|
def tag_name(locator)
|
789
|
-
log(locator)
|
790
712
|
find_element(locator).tag_name
|
791
713
|
end
|
792
714
|
|
@@ -795,7 +717,6 @@ class Rudra
|
|
795
717
|
# identify the element or Selenium::WebDriver::Element
|
796
718
|
# @return [String] the text content of the given element
|
797
719
|
def text(locator)
|
798
|
-
log(locator)
|
799
720
|
find_element(locator).text
|
800
721
|
end
|
801
722
|
|
@@ -804,7 +725,6 @@ class Rudra
|
|
804
725
|
# identify the element or Selenium::WebDriver::Element
|
805
726
|
# @param [String] event the event name
|
806
727
|
def trigger(locator, event)
|
807
|
-
log(locator, event)
|
808
728
|
execute_script(%(
|
809
729
|
var element = arguments[0];
|
810
730
|
var eventName = arguments[1];
|
@@ -819,7 +739,6 @@ class Rudra
|
|
819
739
|
|
820
740
|
# Clear all drawing
|
821
741
|
def clear_drawings
|
822
|
-
log
|
823
742
|
execute_script(%(
|
824
743
|
var elements = window.document.body.querySelectorAll('[id*="rudra_"]');
|
825
744
|
for (var i = 0; i < elements.length; i++) {
|
@@ -837,8 +756,6 @@ class Rudra
|
|
837
756
|
# or Selenium::WebDriver::Element where the arrow ends
|
838
757
|
# @return [Selenium::WebDriver::Element] the arrow element
|
839
758
|
def draw_arrow(from_locator, to_locator)
|
840
|
-
log(from_locator, to_locator)
|
841
|
-
|
842
759
|
id = random_id
|
843
760
|
|
844
761
|
execute_script(%(
|
@@ -906,8 +823,6 @@ class Rudra
|
|
906
823
|
# @param [String] color CSS style of backgroundColor
|
907
824
|
# @return [Selenium::WebDriver::Element] the color fill element
|
908
825
|
def draw_color_fill(locator, color = 'rgba(255,0,0,0.8)')
|
909
|
-
log(locator, color)
|
910
|
-
|
911
826
|
rectangle = rect(locator)
|
912
827
|
id = random_id
|
913
828
|
|
@@ -945,8 +860,6 @@ class Rudra
|
|
945
860
|
# @option options [Boolean] :draw_symbol (false) if to draw symbol
|
946
861
|
# @return [Selenium::WebDriver::Element] the tooltip element
|
947
862
|
def draw_flyover(locator, options = {})
|
948
|
-
log(locator, options)
|
949
|
-
|
950
863
|
attribute_name = options.fetch(:attribute, 'title')
|
951
864
|
offset_x = options.fetch(:offset_x, 5)
|
952
865
|
offset_y = options.fetch(:offset_y, 15)
|
@@ -1024,8 +937,6 @@ class Rudra
|
|
1024
937
|
# @option padding [Integer] :left (5) left padding
|
1025
938
|
# @return [Selenium::WebDriver::Element] the redmark element
|
1026
939
|
def draw_redmark(locator, padding = {})
|
1027
|
-
log(locator, padding)
|
1028
|
-
|
1029
940
|
top = padding.fetch(:top, 5)
|
1030
941
|
right = padding.fetch(:right, 5)
|
1031
942
|
bottom = padding.fetch(:bottom, 5)
|
@@ -1062,8 +973,6 @@ class Rudra
|
|
1062
973
|
# @option options [Integer] :offset_y (0) offset on y coordinate
|
1063
974
|
# @return [Selenium::WebDriver::Element] the dropdown menu element
|
1064
975
|
def draw_select(locator, options = {})
|
1065
|
-
log(locator, options)
|
1066
|
-
|
1067
976
|
offset_x = options.fetch(:offset_x, 0)
|
1068
977
|
offset_y = options.fetch(:offset_y, 0)
|
1069
978
|
|
@@ -1124,8 +1033,6 @@ class Rudra
|
|
1124
1033
|
# @option options [Integer] :right (20) CSS style of right
|
1125
1034
|
# @return [Selenium::WebDriver::Element] the text element
|
1126
1035
|
def draw_text(locator, text, options = {})
|
1127
|
-
log(locator, text, options)
|
1128
|
-
|
1129
1036
|
color = options.fetch(:color, '#f00')
|
1130
1037
|
font_size = options.fetch(:font_size, 13)
|
1131
1038
|
top = options.fetch(:top, 2)
|
@@ -1159,12 +1066,24 @@ class Rudra
|
|
1159
1066
|
# Create directories, recursively, for the given dir
|
1160
1067
|
# @param [String] dir the directories to create
|
1161
1068
|
def mkdir(dir)
|
1162
|
-
log(dir)
|
1163
1069
|
FileUtils.mkdir_p(dir)
|
1164
1070
|
end
|
1165
1071
|
|
1072
|
+
(instance_methods - superclass.instance_methods).map do |method_name|
|
1073
|
+
next if private_method_defined?(method_name) || ATTRIBUTES.include?(method_name)
|
1074
|
+
|
1075
|
+
original_method = instance_method(method_name)
|
1076
|
+
|
1077
|
+
define_method(method_name) do |*args, &block|
|
1078
|
+
log(method_name, *args)
|
1079
|
+
original_method.bind(self).call(*args, &block)
|
1080
|
+
end
|
1081
|
+
end
|
1082
|
+
|
1166
1083
|
private
|
1167
1084
|
|
1085
|
+
attr_writer :main_label
|
1086
|
+
|
1168
1087
|
def browser=(brw)
|
1169
1088
|
unless BROWSERS.include?(brw)
|
1170
1089
|
browsers = BROWSERS.map { |b| ":#{b}" }.join(', ')
|
@@ -1190,6 +1109,10 @@ class Rudra
|
|
1190
1109
|
@headless = true?(mode)
|
1191
1110
|
end
|
1192
1111
|
|
1112
|
+
def screen_dir=(path)
|
1113
|
+
@screen_dir = File.join(path, @locale.to_s)
|
1114
|
+
end
|
1115
|
+
|
1193
1116
|
def log_prefix=(prefix)
|
1194
1117
|
@log_prefix = prefix.chomp
|
1195
1118
|
end
|
@@ -1214,6 +1137,8 @@ class Rudra
|
|
1214
1137
|
Selenium::WebDriver.for(:chrome, options: chrome_options)
|
1215
1138
|
elsif browser == :firefox
|
1216
1139
|
Selenium::WebDriver.for(:firefox, options: firefox_options)
|
1140
|
+
elsif browser == :ie
|
1141
|
+
Selenium::WebDriver.for(:ie, options: ie_options)
|
1217
1142
|
else
|
1218
1143
|
Selenium::WebDriver.for(:safari)
|
1219
1144
|
end
|
@@ -1223,6 +1148,10 @@ class Rudra
|
|
1223
1148
|
options = Selenium::WebDriver::Chrome::Options.new
|
1224
1149
|
options.add_argument('--disable-notifications')
|
1225
1150
|
options.add_argument('--headless') if headless
|
1151
|
+
options.add_option(
|
1152
|
+
'excludeSwitches',
|
1153
|
+
%w[enable-automation enable-logging]
|
1154
|
+
)
|
1226
1155
|
options.add_preference('intl.accept_languages', locale)
|
1227
1156
|
options
|
1228
1157
|
end
|
@@ -1234,6 +1163,16 @@ class Rudra
|
|
1234
1163
|
options
|
1235
1164
|
end
|
1236
1165
|
|
1166
|
+
def ie_options
|
1167
|
+
options = Selenium::WebDriver::IE::Options.new
|
1168
|
+
options.ensure_clean_session = true
|
1169
|
+
options.full_page_screenshot = true
|
1170
|
+
options.ignore_protected_mode_settings = true
|
1171
|
+
options.ignore_zoom_level = true
|
1172
|
+
options.native_events = false
|
1173
|
+
options
|
1174
|
+
end
|
1175
|
+
|
1237
1176
|
def parse_locator(locator)
|
1238
1177
|
unmatched, how, what = locator.split(/^([A-Za-z]+)=(.+)/)
|
1239
1178
|
|
@@ -1254,13 +1193,13 @@ class Rudra
|
|
1254
1193
|
[how, what]
|
1255
1194
|
end
|
1256
1195
|
|
1257
|
-
def log(*args)
|
1258
|
-
return unless @verbose && caller_locations(2, 1).first.label ==
|
1196
|
+
def log(method_name, *args)
|
1197
|
+
return unless @verbose && caller_locations(2, 1).first.label == @main_label
|
1259
1198
|
|
1260
|
-
function = caller_locations(1, 1).first.label
|
1261
1199
|
arguments = args.map(&:to_s).join(', ')
|
1200
|
+
|
1262
1201
|
puts @log_prefix + (
|
1263
|
-
arguments.empty? ?
|
1202
|
+
arguments.empty? ? method_name.to_s : "#{method_name}(#{arguments})"
|
1264
1203
|
)
|
1265
1204
|
end
|
1266
1205
|
|
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.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.9.
|
19
|
+
version: 0.9.25
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.9.
|
26
|
+
version: 0.9.25
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: selenium-webdriver
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,24 +48,24 @@ dependencies:
|
|
48
48
|
name: webdrivers
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 4.2.0
|
54
51
|
- - "~>"
|
55
52
|
- !ruby/object:Gem::Version
|
56
|
-
version: '4.
|
53
|
+
version: '4.4'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 4.4.1
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- - ">="
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: 4.2.0
|
64
61
|
- - "~>"
|
65
62
|
- !ruby/object:Gem::Version
|
66
|
-
version: '4.
|
63
|
+
version: '4.4'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 4.4.1
|
67
67
|
description: Selenium IDE alternative using selenium-webdriver
|
68
|
-
email: aaron@
|
68
|
+
email: aaron@611b.com
|
69
69
|
executables: []
|
70
70
|
extensions: []
|
71
71
|
extra_rdoc_files: []
|