rudra 1.1.2 → 1.1.3
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 +90 -5
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1094036482a36f5196cd490c2594b66aabf2eebb1aa6c5adfb2b49c426d03e3
|
4
|
+
data.tar.gz: 4fd39aae44a3cf44d263014147cba3eb50a3c0622445fb0452dfda3f438120a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c1fca4fe84b87a53c2681df286f0862fa88fec448af16a4a2752c34dca6c9c0e3686b4a4f4db05fd222d539a08586e6750a524801033d127fda974345f79025
|
7
|
+
data.tar.gz: 813860ba0fa303826bcc1ea916592b73b0b42130c2ecb92082562b576be71a26a445cc3128964cc6b2342d1837d37b0b3855867bf66259b5c772cbe8d1702099
|
data/lib/rudra.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'selenium-webdriver'
|
2
2
|
require 'webdrivers'
|
3
|
+
require 'zip'
|
4
|
+
require 'base64'
|
5
|
+
require 'json'
|
6
|
+
require 'stringio'
|
3
7
|
|
4
8
|
# Selenium IDE-like WebDriver based upon Ruby binding
|
5
9
|
# @author Aaron Chen
|
@@ -15,6 +19,8 @@ require 'webdrivers'
|
|
15
19
|
# @attr_reader [Integer] timeout The driver timeout
|
16
20
|
# @attr_reader [Boolean] verbose Turn on/off Verbose mode
|
17
21
|
# @attr_reader [Boolean] silent Turn off Turn on/off descriptions
|
22
|
+
# @attr_reader [String] chrome_auth_username Chrome Basic Auth Extension - username
|
23
|
+
# @attr_reader [String] chrome_auth_password Chrome Basic Auth Extension - password
|
18
24
|
class Rudra
|
19
25
|
# Supported Browsers
|
20
26
|
BROWSERS = %i[chrome firefox ie safari].freeze
|
@@ -30,11 +36,13 @@ class Rudra
|
|
30
36
|
browser driver install_dir locale
|
31
37
|
headless window_size screen_dir
|
32
38
|
log_prefix timeout verbose silent
|
39
|
+
chrome_auth_username chrome_auth_password
|
33
40
|
].freeze
|
34
41
|
|
35
42
|
attr_reader :browser, :driver, :install_dir, :locale,
|
36
43
|
:headless, :window_size, :screen_dir,
|
37
|
-
:log_prefix, :timeout, :verbose, :silent
|
44
|
+
:log_prefix, :timeout, :verbose, :silent,
|
45
|
+
:chrome_auth_username, :chrome_auth_password
|
38
46
|
|
39
47
|
# Initialize an instance of Rudra
|
40
48
|
# @param [Hash] options the options to initialize Rudra
|
@@ -50,6 +58,8 @@ class Rudra
|
|
50
58
|
# @option options [Integer] :timeout (30) implicit_wait timeout
|
51
59
|
# @option options [Boolean] :verbose (false) Turn on/off verbose mode
|
52
60
|
# @option options [Boolean] :silent (false) Turn on/off descriptions
|
61
|
+
# @option options [String] :chrome_auth_username ('') username for Chrome Basic Auth extension
|
62
|
+
# @option options [String] :chrome_auth_password ('') password for Chrome Basic Auth extension
|
53
63
|
def initialize(options = {})
|
54
64
|
self.browser = options.fetch(:browser, :chrome)
|
55
65
|
self.install_dir = options.fetch(:install_dir, './webdrivers/')
|
@@ -60,6 +70,8 @@ class Rudra
|
|
60
70
|
self.log_prefix = options.fetch(:log_prefix, ' - ')
|
61
71
|
self.verbose = options.fetch(:verbose, false)
|
62
72
|
self.silent = options.fetch(:silent, false)
|
73
|
+
self.chrome_auth_username = options.fetch(:chrome_auth_username, '')
|
74
|
+
self.chrome_auth_password = options.fetch(:chrome_auth_password, '')
|
63
75
|
self.main_label = caller_locations(2, 1).first.label
|
64
76
|
|
65
77
|
initialize_driver
|
@@ -149,6 +161,26 @@ class Rudra
|
|
149
161
|
driver.manage.delete_cookie(name)
|
150
162
|
end
|
151
163
|
|
164
|
+
# Check if an element is found
|
165
|
+
# @param [String, Selenium::WebDriver::Element] locator the locator to
|
166
|
+
# identify the element or Selenium::WebDriver::Element
|
167
|
+
# @param [Integer] seconds seconds before timed out
|
168
|
+
def element_found?(locator, seconds = 1)
|
169
|
+
how, what = parse_locator(locator)
|
170
|
+
|
171
|
+
implicit_wait(seconds)
|
172
|
+
|
173
|
+
begin
|
174
|
+
wait_for(seconds) { driver.find_element(how, what).displayed? }
|
175
|
+
rescue Selenium::WebDriver::Error::TimeoutError
|
176
|
+
false
|
177
|
+
rescue Net::ReadTimeout
|
178
|
+
false
|
179
|
+
ensure
|
180
|
+
implicit_wait(timeout)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
152
184
|
# Execute the given JavaScript
|
153
185
|
# @param [String] script JavaScript source to execute
|
154
186
|
# @param [Selenium::WebDriver::Element, Integer, Float, Boolean, NilClass,
|
@@ -380,8 +412,12 @@ class Rudra
|
|
380
412
|
|
381
413
|
begin
|
382
414
|
wait_for(seconds) do
|
383
|
-
|
384
|
-
|
415
|
+
begin
|
416
|
+
elements = driver.find_elements(how, what)
|
417
|
+
elements.empty? || elements.map(&:displayed?).none?
|
418
|
+
rescue Selenium::WebDriver::Error::StaleElementReferenceError
|
419
|
+
false
|
420
|
+
end
|
385
421
|
end
|
386
422
|
rescue Selenium::WebDriver::Error::TimeoutError
|
387
423
|
true
|
@@ -477,7 +513,8 @@ class Rudra
|
|
477
513
|
def click(locator)
|
478
514
|
wait_for do
|
479
515
|
begin
|
480
|
-
find_element(locator)
|
516
|
+
element = find_element(locator)
|
517
|
+
element.enabled? && element.click.nil?
|
481
518
|
rescue Selenium::WebDriver::Error::ElementClickInterceptedError
|
482
519
|
false
|
483
520
|
end
|
@@ -1176,7 +1213,7 @@ class Rudra
|
|
1176
1213
|
private
|
1177
1214
|
|
1178
1215
|
attr_accessor :main_label
|
1179
|
-
attr_writer :silent, :window_size
|
1216
|
+
attr_writer :silent, :window_size, :chrome_auth_username, :chrome_auth_password
|
1180
1217
|
|
1181
1218
|
def browser=(brw)
|
1182
1219
|
unless BROWSERS.include?(brw)
|
@@ -1247,6 +1284,10 @@ class Rudra
|
|
1247
1284
|
options.add_argument('--headless')
|
1248
1285
|
options.add_argument("--window-size=#{window_size}")
|
1249
1286
|
end
|
1287
|
+
if chrome_auth_username && chrome_auth_password
|
1288
|
+
encoded = chrome_basic_auth_extension(chrome_auth_username, chrome_auth_password)
|
1289
|
+
options.add_encoded_extension(encoded)
|
1290
|
+
end
|
1250
1291
|
options.add_option(
|
1251
1292
|
'excludeSwitches',
|
1252
1293
|
%w[enable-automation enable-logging]
|
@@ -1319,4 +1360,48 @@ class Rudra
|
|
1319
1360
|
id = Array.new(length) { charset.sample }.join
|
1320
1361
|
"rudra_#{id}"
|
1321
1362
|
end
|
1363
|
+
|
1364
|
+
def chrome_basic_auth_extension(username, password)
|
1365
|
+
manifest = {
|
1366
|
+
"manifest_version": 2,
|
1367
|
+
"name": 'Rudra Basic Auth Extension',
|
1368
|
+
"version": '1.0.0',
|
1369
|
+
"permissions": ['*://*/*', 'webRequest', 'webRequestBlocking'],
|
1370
|
+
"background": {
|
1371
|
+
"scripts": ['background.js']
|
1372
|
+
}
|
1373
|
+
}
|
1374
|
+
|
1375
|
+
background = <<~JSCRIPT
|
1376
|
+
var username = '#{username}';
|
1377
|
+
var password = '#{password}';
|
1378
|
+
|
1379
|
+
chrome.webRequest.onAuthRequired.addListener(
|
1380
|
+
function handler(details) {
|
1381
|
+
if (username == null) {
|
1382
|
+
return { cancel: true };
|
1383
|
+
}
|
1384
|
+
|
1385
|
+
var authCredentials = { username: username, password: username };
|
1386
|
+
username = password = null;
|
1387
|
+
|
1388
|
+
return { authCredentials: authCredentials };
|
1389
|
+
},
|
1390
|
+
{ urls: ['<all_urls>'] },
|
1391
|
+
['blocking']
|
1392
|
+
);
|
1393
|
+
JSCRIPT
|
1394
|
+
|
1395
|
+
stringio = Zip::OutputStream.write_buffer do |zos|
|
1396
|
+
zos.put_next_entry('manifest.json')
|
1397
|
+
zos.write manifest.to_json
|
1398
|
+
zos.put_next_entry('background.js')
|
1399
|
+
zos.write background
|
1400
|
+
end
|
1401
|
+
# File.open('basic_auth.crx', 'wb') do |f|
|
1402
|
+
# f << stringio.string
|
1403
|
+
# end
|
1404
|
+
|
1405
|
+
Base64.strict_encode64(stringio.string)
|
1406
|
+
end
|
1322
1407
|
end
|
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.1.
|
4
|
+
version: 1.1.3
|
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-06-
|
11
|
+
date: 2020-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -44,6 +44,26 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '3.9'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rubyzip
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.3.0
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.3'
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 2.3.0
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '2.3'
|
47
67
|
- !ruby/object:Gem::Dependency
|
48
68
|
name: selenium-webdriver
|
49
69
|
requirement: !ruby/object:Gem::Requirement
|