aranha 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aranha/selenium/driver_factory.rb +29 -26
- data/lib/aranha/selenium/driver_factory/base.rb +38 -0
- data/lib/aranha/selenium/driver_factory/chrome.rb +28 -0
- data/lib/aranha/selenium/driver_factory/firefox.rb +54 -0
- data/lib/aranha/selenium/{auto_download_mime_types → driver_factory/firefox_auto_download_mime_types} +0 -0
- data/lib/aranha/selenium/session.rb +6 -2
- data/lib/aranha/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fae3e1f9e295a208be700db6357172330192e9e4c0586ef0fff9a78db59001a3
|
4
|
+
data.tar.gz: fb90fe66bdca6283dd61b4effd5d9265c7d8c99d5efbb21b22e8519a75aa4cb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a9cef98927abcc0ffbca46aed279e757aadbf4959604a0855094e19585364de1eca69ad209c27acbe959614a33856d322e9046005b4aeeb5404d064159c20d3
|
7
|
+
data.tar.gz: 680fcb07943ee059df08c17c51dcc8ebec377be0e153be7118118c5c566ae195c860712e79248e940ca652f21f3bfeff91b37a5375a381bbc62c6c7ea3e72052
|
@@ -1,42 +1,45 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
4
|
+
require 'aranha/selenium/driver_factory/chrome'
|
5
|
+
require 'aranha/selenium/driver_factory/firefox'
|
4
6
|
|
5
7
|
module Aranha
|
6
8
|
module Selenium
|
7
9
|
class DriverFactory
|
8
10
|
class << self
|
9
|
-
DEFAULT_DOWNLOAD_DIR = '/tmp/aranha_download_dir'
|
10
|
-
|
11
11
|
def create_driver(options = {})
|
12
|
-
options
|
13
|
-
options[:download_dir] ||= DEFAULT_DOWNLOAD_DIR
|
14
|
-
create_firefox_driver(options)
|
12
|
+
new(options).create_driver
|
15
13
|
end
|
14
|
+
end
|
16
15
|
|
17
|
-
|
16
|
+
attr_reader :options
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
options: ::Selenium::WebDriver::Firefox::Options.new(
|
23
|
-
profile: create_firefox_profile(options)
|
24
|
-
)
|
25
|
-
)
|
26
|
-
end
|
18
|
+
def initialize(options)
|
19
|
+
@options = options.with_indifferent_access.freeze
|
20
|
+
end
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
profile['browser.download.folderList'] = 2
|
32
|
-
profile['browser.helperApps.neverAsk.saveToDisk'] = auto_download_mime_types.join(';')
|
33
|
-
profile['pdfjs.disabled'] = true
|
34
|
-
profile
|
35
|
-
end
|
22
|
+
def create_driver
|
23
|
+
driver_class.new(driver_options).build
|
24
|
+
end
|
36
25
|
|
37
|
-
|
38
|
-
|
39
|
-
|
26
|
+
def driver_name
|
27
|
+
(options[:driver] || default_driver_name).to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def driver_class
|
31
|
+
Aranha::Selenium::DriverFactory.const_get(driver_name.classify)
|
32
|
+
rescue NameError
|
33
|
+
raise "Unknown Aranha Selenium driver: \"#{driver_name}\"" \
|
34
|
+
" (Class \"Aranha::Selenium::DriverFactory::#{driver_name.classify}\" not found)"
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_driver_name
|
38
|
+
:firefox
|
39
|
+
end
|
40
|
+
|
41
|
+
def driver_options
|
42
|
+
options.except(:driver)
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
4
|
+
require 'tmpdir'
|
5
|
+
|
6
|
+
module Aranha
|
7
|
+
module Selenium
|
8
|
+
class DriverFactory
|
9
|
+
class Base
|
10
|
+
DEFAULT_DOWNLOADS_DIR = ::File.join(::Dir.tmpdir, 'aranha_downloads_dir')
|
11
|
+
DEFAULT_ACCEPT_INSECURE_CERTS = false
|
12
|
+
DEFAULT_HEADLESS = false
|
13
|
+
|
14
|
+
attr_reader :options
|
15
|
+
|
16
|
+
def initialize(options)
|
17
|
+
@options = options.with_indifferent_access.freeze
|
18
|
+
end
|
19
|
+
|
20
|
+
def build
|
21
|
+
raise 'Must be overrided'
|
22
|
+
end
|
23
|
+
|
24
|
+
def downloads_dir
|
25
|
+
options[:downloads_dir] || DEFAULT_DOWNLOADS_DIR
|
26
|
+
end
|
27
|
+
|
28
|
+
def accept_insecure_certs?
|
29
|
+
options[:accept_insecure_certs] || DEFAULT_ACCEPT_INSECURE_CERTS
|
30
|
+
end
|
31
|
+
|
32
|
+
def headless?
|
33
|
+
options[:headless] || DEFAULT_HEADLESS
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'selenium-webdriver'
|
4
|
+
require 'aranha/selenium/driver_factory/base'
|
5
|
+
|
6
|
+
module Aranha
|
7
|
+
module Selenium
|
8
|
+
class DriverFactory
|
9
|
+
class Chrome < ::Aranha::Selenium::DriverFactory::Base
|
10
|
+
def build
|
11
|
+
::Selenium::WebDriver.for :chrome, options: chrome_options
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def chrome_options
|
17
|
+
r = ::Selenium::WebDriver::Chrome::Options.new
|
18
|
+
r.add_argument('--ignore-certificate-errors') if accept_insecure_certs?
|
19
|
+
r.add_argument('--headless') if headless?
|
20
|
+
r.add_argument('--disable-popup-blocking')
|
21
|
+
r.add_argument('--disable-translate')
|
22
|
+
r.add_preference(:download, prompt_for_download: false, default_directory: downloads_dir)
|
23
|
+
r
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'selenium-webdriver'
|
4
|
+
require 'aranha/selenium/driver_factory/base'
|
5
|
+
|
6
|
+
module Aranha
|
7
|
+
module Selenium
|
8
|
+
class DriverFactory
|
9
|
+
class Firefox < ::Aranha::Selenium::DriverFactory::Base
|
10
|
+
def build
|
11
|
+
::Selenium::WebDriver.for(
|
12
|
+
:firefox,
|
13
|
+
options: ::Selenium::WebDriver::Firefox::Options.new(
|
14
|
+
profile: build_profile,
|
15
|
+
args: build_args
|
16
|
+
),
|
17
|
+
desired_capabilities: build_capabilities
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def build_args
|
24
|
+
r = []
|
25
|
+
r << '-headless' if headless?
|
26
|
+
r
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_capabilities
|
30
|
+
if accept_insecure_certs?
|
31
|
+
::Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
|
32
|
+
else
|
33
|
+
::Selenium::WebDriver::Remote::Capabilities.firefox
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_profile
|
38
|
+
r = ::Selenium::WebDriver::Firefox::Profile.new
|
39
|
+
r['browser.download.dir'] = downloads_dir
|
40
|
+
r['browser.download.folderList'] = 2
|
41
|
+
r['browser.helperApps.neverAsk.saveToDisk'] = auto_download_mime_types.join(';')
|
42
|
+
r['pdfjs.disabled'] = true
|
43
|
+
r
|
44
|
+
end
|
45
|
+
|
46
|
+
def auto_download_mime_types
|
47
|
+
::File.read(
|
48
|
+
::File.join(__dir__, 'firefox_auto_download_mime_types')
|
49
|
+
).each_line.map(&:strip)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
File without changes
|
@@ -7,10 +7,14 @@ module Aranha
|
|
7
7
|
class Session < ::SimpleDelegator
|
8
8
|
attr_reader :downloads, :wait
|
9
9
|
|
10
|
-
def initialize
|
10
|
+
def initialize(options = {})
|
11
11
|
@downloads = Downloads.new
|
12
12
|
@wait = ::Selenium::WebDriver::Wait.new(timeout: 15)
|
13
|
-
super(
|
13
|
+
super(
|
14
|
+
::Aranha::Selenium::DriverFactory.create_driver(
|
15
|
+
options.merge(download_dir: @downloads.dir)
|
16
|
+
)
|
17
|
+
)
|
14
18
|
end
|
15
19
|
|
16
20
|
def find_or_not_element(find_element_args)
|
data/lib/aranha/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aranha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo H. Bogoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_scaffold
|
@@ -157,8 +157,11 @@ files:
|
|
157
157
|
- lib/aranha/parsers/spec/source_target_fixtures.rb
|
158
158
|
- lib/aranha/parsers/spec/source_target_fixtures_example.rb
|
159
159
|
- lib/aranha/processor.rb
|
160
|
-
- lib/aranha/selenium/auto_download_mime_types
|
161
160
|
- lib/aranha/selenium/driver_factory.rb
|
161
|
+
- lib/aranha/selenium/driver_factory/base.rb
|
162
|
+
- lib/aranha/selenium/driver_factory/chrome.rb
|
163
|
+
- lib/aranha/selenium/driver_factory/firefox.rb
|
164
|
+
- lib/aranha/selenium/driver_factory/firefox_auto_download_mime_types
|
162
165
|
- lib/aranha/selenium/session.rb
|
163
166
|
- lib/aranha/version.rb
|
164
167
|
- lib/tasks/aranha_tasks.rake
|