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